6 ms·
There is a Ruby idiom[0] that I find quite useful (esp. combined with a linter such as Rubocop), leveraging optional parens as a marker of intentional assignmen
by lloeki 9y ago
There is a Ruby idiom[0] that I find quite useful (esp. combined with a linter such as Rubocop), leveraging optional parens as a marker of intentional assignment:
# bad
if v = array.grep(/foo/)
do_something(v)
# some code
end
# good
if (v = array.grep(/foo/))
do_something(v)
# some code
end
Caught a number of nasty bugs that way.
[0]: https://github.com/bbatsov/ruby-style-guide#safe-assignment-in-condition https://github.com/bbatsov/ruby-style-guide#safe-assignment-...
- syrrim 9y agoYou can catch this in c using -Wall.