ruby.social is one of the many independent Mastodon servers you can use to participate in the fediverse.
If you are interested in the Ruby programming language, come join us! Tell us about yourself when signing up. If you just want to join Mastodon, another server will be a better place for you.

Administered by:

Server stats:

1.1K
active users

Stephann V.

When organizing model validations, which style do you prefer?

I prefer 1) because I usually wonder "which attributes are required?", "which attributes are unique?", and not "which validations does permalink attribute have?".

@ste interesting! I usually go with 2) mainly because it avoids repetition and isn't confusing to look at multiple validations for one attribute. If you have a model with many attributes (containing a form for example) 1) can become a lot more complicated and you may trade readability and meaning.

@madhums I think repetition isn't bad when it brings readability/organization, which is what I think option 1 brings. I see it as "one line per validation".

And I think the 2) is worse especially when a model has many attributes with many validations, and it's fine when it's a small model with a few validations.

@ste @madhums I guess when you have a small model, it works fine. But then it would be weird to have different styles in the same code base. I find grouping by model attribute is more common and readable than grouping by validation constraint. I guess you can check how most of the community does it by going through some popular projects

@ste I also prefer 1. Which makes me occasionally prefer the “fully named” variant (validates_presence_of etc)

Might be a good reason to have more doc-generation (eg yard) that documents models along both axis, so you can view it either way, regardless which style is used.