When possible.. do you leave parentheses in or out in Ruby?
相关问题
- How to specify memcache server to Rack::Session::M
- Why am I getting a “C compiler cannot create execu
- reference to a method?
- ruby 1.9 wrong file encoding on windows
- gem cleanup shows error: Unable to uninstall bundl
相关文章
- Ruby using wrong version of openssl
- Difference between Thread#run and Thread#wakeup?
- how to call a active record named scope with a str
- “No explicit conversion of Symbol into String” for
- Segmentation fault with ruby 2.0.0p247 leading to
- How to detect if an element exists in Watir
- uninitialized constant Mysql2::Client::SECURE_CONN
- ruby - simplify string multiply concatenation
I leave them out when I'm doing DSL-ish stuff, like t.column or has_many in rails. The rest of the time, it generally comes down to clarity, and it's probably an even split.
I tend to leave them out when doing assertions such as assert_equal. Maybe it's to make it domain specific language-like.
I use parens as comments to help the future me... who is likely to have fewer brain cells than the current me :-)
Nothing worse than looking at some code you wrote 2 years ago and misunderstanding it, so that you break something while modifying it.
If parens will save the future me a few minutes (or hours) in the future, I'll put in as many as needed to make the statement crystal clear.
-- John
I try to leave them out, if at all possible. I think it makes code easier to read (generally speaking).
If you mean in function calls, I always put parenthesis because it's always easier to read. If you mean in conditions (if, while) I only put parenthesis when they're necessary.
I guess I do both, but I definitely keep them in if it adds to readability and avoids statements that look ambiguous.