the point of omitting parentheses

T

Thomas Adam

I would say that that's this year's 'point'. For me, I just think
that they are ugly.

I only use them in two places, personally:
1. When the left-hand side of a ternary starts to look scary:
x = (foo == baz.something) ? this : the_other

2. Method definitions, since I find they draw the eye better than
without. def thingy x, y, *z, &block vs. def thingy(x, y, *z, &block)

Like everyone else who has replied to this thread -- they're either
explicitly stated or alluded to the fact that it's purely a matter of
choice.

For me, it's useful to fit my mindset as to what makes things clearer
for me. For years, I have been using Java, and I *do* find the use of
parenthesis around method calls useful in Ruby to make me realise
what's going on. But it's just choice.

When you consider things like:

require 'foo'
attr_reader :myvar

Those dictate properties if you will of the class, so not adding
parenthesis around them makes sense, despite them being methods in
their own right.

-- Thomas Adam
 
H

Henrik Schmidt

Phrogz said:
See if the following helps: code in classes isn't compiled, it is
executed. Defining a function is a discrete step that runs (and returns
nil), and that you can listen for.

Got it. That's pretty cool. Thanks for the help.

Best Regards,
Henrik Schmidt
 
J

Joe Ruby MUDCRAP-CE

I feel like such a n00b -- I don't think I've ever created a DSL and
don't expect to in the near future.

Joe
 
K

Keith Gaughan

I feel like such a n00b -- I don't think I've ever created a DSL and
don't expect to in the near future.

You do, you have, and you will: a library with a well-designed API is
essentially a DSL.
 
J

Joe Van Dyk

Would you really type:

class Foo
attr_accessor( :bar )
end

f = Foo.new()
f.bar=( 12 )
puts( f.bar() )

One of the greatest reasons for omitting parentheses is that the
syntactic sugar allows you to write code that *looks* like you're
assigning values to properties and reading those properties, when in
reality you're calling methods.

f.bar = 12
puts( f.bar )

Or hell,

x = 5

If you used parenthesis around every method call, this would be
x=(5)

How does that work, actually? method_missing?
 
J

Joe Ruby MUDCRAP-CE

Keith said:
You do, you have, and you will: a library with a well-designed API is
essentially a DSL.

Phew! It's good to know I've been buzzword-compliant all these years. ;P

Joe
 
S

S.Z.

Thomas Adam пиÑал(а):
Like everyone else who has replied to this thread -- they're either
explicitly stated or alluded to the fact that it's purely a matter of
choice.
My this year point is as follows:
To use or not to use -- is a matter of taste.
To have a rule for doing either -- is a matter of clear writing.
To use an appropriate rule -- is a matter of productivity.
Constantly improve the rules -- is a metter of progress.

Best respects,
S.Z.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,278
Latest member
BuzzDefenderpro

Latest Threads

Top