How to call an object instance's method?

I think it would break bucketloads of old code, and make the language look a
lot more like LISP*, which isn’t necessarily a good thing…

Tim Bates

···

On Fri, 25 Apr 2003 10:38 pm, Brian Candler wrote:

The latter would make the language less C-like, and would force you to
write

(sin a) + b

instead of

sin(a) + b

What do people think of that??


tim@bates.id.au

  • “Lots of Irritating Superfluous Parentheses”

Hi –

The more I think about this, the more I think that either:

  • the 1.6.8 behaviour is better, or
  • make poetry mode compulsory: that is, disallow parentheses around
    argument lists altogether, to eliminate the ambiguity.

The latter would make the language less C-like, and would force you to write

(sin a) + b

instead of

sin(a) + b

What do people think of that??

I don’t like the latter (the disallowing of parens), partly because it
would mean starting from scratch in terms of existing code, and partly
because I think parens are useful for clarity.

I would love to see the space not be significant. Whatever they mean,
it feels right to me to have:

meth(a).b

and

meth (a).b

mean the same thing as each other.

David

···

On Fri, 25 Apr 2003, Brian Candler wrote:


David Alan Black
home: dblack@superlink.net
work: blackdav@shu.edu
Web: http://pirate.shu.edu/~blackdav

The more I think about this, the more I think that either:

  • the 1.6.8 behaviour is better, or
  • make poetry mode compulsory: that is, disallow parentheses around
    argument lists altogether, to eliminate the ambiguity.

What do people think of that??

Anything that requires poetry mode I’m against, as I’m against
poetry mode in general. Maybe I’m just old and crotchety, but it
seems that it’s caused far too many “Huh?”'s, and the 1.8 changing of
it even moreso.

···

Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo

The more I think about this, the more I think that either:

  • the 1.6.8 behaviour is better, or
  • make poetry mode compulsory: that is, disallow parentheses around
    argument lists altogether, to eliminate the ambiguity.
···

----- Original Message -----
From: “Brian Candler” B.Candler@pobox.com


Or make poetry mode illegal. (Not a great option, but I had to throw it in
for completeness.)


The latter would make the language less C-like, and would force you to write

(sin a) + b

instead of

sin(a) + b

What do people think of that??


That is really cool! But I think ruby is too old for such a change.
Anyway, what would this code do?

sin a + b . abs

It seems such things should be clear. Without adding parens everywhere
(and becoming Lisp), I don’t see how it would be easy to understand what the
above does. (Of course, I wouldn’t know what the above does in Ruby 1.6 or
1.8, either, without trying it in irb first; is it good that we have irb for
such things, or is it bad that I need it for such things?) Are you saying
that methods are greedy for arguments? Then I guess the above would be:

sin(a + (b.abs))

Actually, that seems pretty reasonable… but this is still going to throw
people off:

sin(a+b) . abs

which would really be:

sin((a+b).abs)

Perhaps people would get used to it if there wasn’t already so much ruby
code with the parens like they are now… but, like I said, I think Ruby is
too old for such a change.

Chris

I think clarity is certainly the problem here. Are parens just part of the
expression which follows the method name, or do they mark the start and end
of the argument list? It’s not a problem in C because they are compulsory
around the argument list. If they were forbidden it would be fine too. But
if they are optional then we get into this mess.

I’d be happy to go back to 1.6.8 behaviour; the 1.8.0p2 behaviour will break
old code too.

FWIW Perl takes the 1.6.8 view:

perl -e ‘print(-3-4)*2’ #>> -7
perl -e ‘print (-3-4)*2’ #>> -7

Regards,

Brian.

···

On Fri, Apr 25, 2003 at 10:17:21PM +0900, dblack@superlink.net wrote:

The latter would make the language less C-like, and would force you to write

(sin a) + b

instead of

sin(a) + b

What do people think of that??

I don’t like the latter (the disallowing of parens), partly because it
would mean starting from scratch in terms of existing code, and partly
because I think parens are useful for clarity.

You mean you would prefer

while a = gets()
a.chomp!()
puts(“hello, #{a}”)
end

?

···

On Fri, Apr 25, 2003 at 11:06:22PM +0900, Michael Campbell wrote:

What do people think of that??

Anything that requires poetry mode I’m against, as I’m against
poetry mode in general. Maybe I’m just old and crotchety, but it
seems that it’s caused far too many “Huh?”'s, and the 1.8 changing of
it even moreso.

Or make poetry mode illegal. (Not a great option, but I had to throw it in
for completeness.)

That means: all method calls must have parentheses around their arguments.

Perhaps it would be OK for method calls with no arguments to omit the ‘()’.
I’ve not thought to deeply about the consequences. It would mean that

foo - bar    would be interpreted as foo() - bar(), not foo(-bar())

which seems reasonable. But you would lose the ability to write

puts "hello"

The latter would make the language less C-like, and would force you to write

(sin a) + b

instead of

sin(a) + b

What do people think of that??


That is really cool! But I think ruby is too old for such a change.
Anyway, what would this code do?

sin a + b . abs

Everything after the ‘sin’ would be its argument, so it would be equivalent
to

sin( a + (b.abs) )

given that ‘.’ binds more tightly than ‘+’. In this case, Ruby behaves like
this already, and both ruby-1.6.8 and 1.8.0p2 are the same.

It is when you add parentheses to parts of the expression that ambiguities
arise.

1.6.8:

sin (a+b).abs   \ =>  both are treated as (sin( a+b )).abs
sin(a+b).abs    /

(i.e. the opening parenthesis is always treated as grouping the argument
list of ‘sin’)

1.8.0p2:

sin (a+b).abs     =>  sin( (a+b).abs )
sin(a+b).abs      =>  (sin( a+b )).abs

That’s a big difference for one space to make.

It seems such things should be clear. Without adding parens everywhere
(and becoming Lisp), I don’t see how it would be easy to understand what the
above does. (Of course, I wouldn’t know what the above does in Ruby 1.6 or
1.8, either, without trying it in irb first; is it good that we have irb for
such things, or is it bad that I need it for such things?)

I think the 1.6.8 rule is easy to understand:

  • if a method call is followed by an opening parenthesis, everything from
    this parenthesis to the closing one is the argument list for the method

    so: sin (a+b) + c
    ^^^ ^^^^^
    meth arg

That’s it. It will catch you out if you write

    puts (a+b).abs

instead of

    puts ((a+b).abs)

Perhaps people would get used to it if there wasn’t already so much ruby
code with the parens like they are now… but, like I said, I think Ruby is
too old for such a change.

You are probably right. But the same argument could be used against 1.8.0p2

Regards,

Brian.

···

On Fri, Apr 25, 2003 at 11:30:25PM +0900, Chris Pine wrote:

You mean you would prefer

while a = gets()
a.chomp!()
puts(“hello, #{a}”)
end

Between that and not ALLOWING ()'s for method/function calls? Absolutely.

···

Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo