Sterling Rose Design Blog

Model Component Ordering

2 Comments
Tags: Rails community
On a whim, I asked (in IRC and via Twitter) what order – given validators, accessors, and associations – developers typically listed these components in their models. As far as I know there is no compelling reason to use one order over the other (but feel free to correct me in the comments). Even so, it can be fun to know what other developers do.

I had 19 responses, broken down as follows:

Accessors | Associations | Validators = 20%
Accessors | Validators | Associations = 5%
Associations | Accessors | Validators = 20%
Associations | Validators | Accessors = 45%
Validators | Accessors | Associations = 5%
Validators | Associations | Accessors = 0%
Comments

I tend to do the same as the majority; Associations | Validators | Accessors. Partially because thats how things fall as they are developed (for me, at least) – associations most important, validators come next as rules are put in place, then accessors for more custom stuff. Its (imo) ordered by priority and importance.

As far as compelling reasons, I dont think there are any, I guess its more personal style really.

I list them alphabetical. Which by nature ends up ordering them roughly in accessors, associations, validators


Leave a Comment











Copyright 2007-2010, Sterling Rose Design. All rights reserved.