I'm just wondering if using parentheses in Ruby makes a program slower. I know it's common to omit them, but for me, using parentheses increases readability.
Asked
Active
Viewed 110 times
-4
-
"makes program slower" - No, that'd be silly. – Sergio Tulentsev Mar 08 '18 at 09:46
-
1Also follow [ruby style guide](https://github.com/bbatsov/ruby-style-guide) for references. There are some conventions where parentheses are not used. – Ashik Salman Mar 08 '18 at 09:52
-
1You should write code for humans, not for machines. If parentheses increase readability, use them. – Stefan Mar 08 '18 at 09:55
-
What happened when you measured it? – Jörg W Mittag Mar 08 '18 at 18:26
2 Answers
1
Most of the time spent while running a ruby program is spent executing the code after parsing has been done. Whether you include parentheses or not affects the tokenization/parsing phase, which is a minor part of the total execution time. Even if there were any difference, it should be negligible.

sawa
- 165,429
- 45
- 277
- 381
-3
There is no difference if your are using parenthesis while calling method or not.
So these lines mean exactly the same:
puts "Hello!"
puts("Hello!")
There are some standard rules which you can follow
Use parentheses for all method calls that take arguments, except for the methods puts and p (and later: require and include).
If a method does not take any arguments, then do not add empty parentheses, omit them.

Sergio Tulentsev
- 226,338
- 43
- 373
- 367

Sujay Gavhane
- 169
- 4
-
1The OP knows that your two expressions are equivalent. The OP is not asking about that. – sawa Mar 08 '18 at 11:04