4 ms·
Funny, before reading the article was thinking about the eslint rule - believe it's called the "no-else-return". While reading and before finishing the article
by dieselgate 3y ago
Funny, before reading the article was thinking about the eslint rule - believe it's called the "no-else-return". While reading and before finishing the article was thinking "isn't that the reason why we use guard clauses?".
It can be confusing but I really appreciate one-liner `unless` statements in ruby for guards
edit: not a fan of unless/else though
- mvdtnz 3y ago> It can be confusing but I really appreciate one-liner `unless` statements in ruby for guards Gosh I am working on beating that out of my Ruby folks. Sure I came into the team from other languages and they're all Ruby natives, and sure this is accepted practice in the Ruby community. But it's just awful and I won't accept it.
- tremon 3y agoWhat? You've inherited a functioning team with a certain code culture, and you're establishing your dominance by making them conform to your "superior" standards? Are they still writing Ruby or will you make them switch to a different language as well?
- zogrodea 3y agoI agree. It might be hard to adjust one's practices, like when one first starts living in another community with a different culture, but it's the right thing to do in most cases.
- mvdtnz 3y ago"Functioning" is arguable. The codebase is a mess.
- zoky 3y ago…said every newly installed manager ever.
- mvdtnz 3y agoI've been there 3 years.
- matthewmacleod 3y agoSounds like the regular beatings haven’t improved morale.
- zoky 3y agoAnd your codebase is still a mess you say? Huh. Maybe try adding some `unless` statements, I've heard they really help.
- mvdtnz 3y agoIt's a 14 year old code base mate. Have you ever worked on very large codebases?
- dragonwriter 3y agoAnd you are still fighting basic Ruby language idioms from the perspective of a newcomer rather than dealing with actual problems?
- dragonwriter 3y agoIf the codebase is actually a mess, you should focus on the actual mess rather than Ruby idioms that are uncomfortable to you.
- zoky 3y agoDo you make them replace `each` iterators with `for` loops as well, just because that’s “how it’s done” in your preferred language? The “fail early” principle is a widely accepted pattern, and that’s exactly what the `unless` statement facilitates, while communicating that is exactly what it’s doing.
- runarberg 3y agono-else-return is correct https://eslint.org/docs/latest/rules/no-else-return https://eslint.org/docs/latest/rules/no-else-return This rule is actually what got me into the practice of returning early from the edge case so many years back. I think it was enabled by default in the—then very popular—AirBnB coding standard.