-4

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.

vich
  • 11,836
  • 13
  • 49
  • 66

2 Answers2

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
  • 1
    The OP knows that your two expressions are equivalent. The OP is not asking about that. – sawa Mar 08 '18 at 11:04