> That restriction tends to improve readability and reduce bugs at the cost of making it harder to have a truly transparent DSL.
I used to think this too. But, then I actually learned ruby, and it turns out to be pretty easy to discern method calls from local variables, unless you are working with horridly long methods, which is a separate issue.
Remember that an instance variable is prefixed with @ in ruby, so if you see something that looks like it could either be a method call or a reference to a local variable, it's pretty easy to quickly examine the local scope to check. It's usually so obvious that you don't need to, though.
There are definitely some potentially tricky situations (closures, etc), but in over a year of working with ruby full time, I have yet to encounter one.
fun1 x
fun1 x + y
fun1 x + y.foo
fun1 x + y.foo bar
What will happen in this perfectly valid Ruby code? Where do the parentheses belong? Do you know off the top of your head?
While any programmer who would write this deserves to be fired, I can't come up with a good reason why it should be valid to write it in the first place.
Looks contrived, because I dont know many ruby users who would write fun1 for a method. Why? Because in ruby there are methods. You dont find many people doing "fun" for a method - the intent clearly was a "function". But where are they? ;)
Anyway, here is the one that comes to my brain flow naturally. It seems python writers need () in order to feel happy, otherwise they think they get confused about things (hopefully they dont have a small brain):
fun1 x
fun1 x + y
fun1 x + y.foo
fun1 x + y.foo bar
What will happen in this perfectly valid Ruby code? Where do the parentheses belong? Do you know off the top of your head?
Btw you omitted what x and y are. My first assumption is that these must be variables that allow the + method
It does not really make a lot of sense though, give the last example:
class Cat
def initialize(name)
@name = name
end
def foo(how = :h)
case how
when :h
how = 'happily'
when :u
how = 'unhappily'
end
puts @name+' meows '+how+'.'
end
end
y = Cat.new 'Tom'
y.foo # "Tom meows happily."
bar = :u
y.foo bar # "Tom meows unhappily."
x = '"At the end of the day "
x + y.foo bar # "At the end of the day Tom meows unhappily."
etc.. I simply have no idea what fun1 should do. Maybe it will involve Jerry mouse and return a conditional story where it is explained why Tom the cat is unhappy.
Btw this is a really contrived example because I tried to model your stipulation of the above code into this. It really makes no sense at all to use variables without any real idea why one should use that.
Why do people WANT to be complex when simplicity is so much more elegant?
I used to think this too. But, then I actually learned ruby, and it turns out to be pretty easy to discern method calls from local variables, unless you are working with horridly long methods, which is a separate issue.
Remember that an instance variable is prefixed with @ in ruby, so if you see something that looks like it could either be a method call or a reference to a local variable, it's pretty easy to quickly examine the local scope to check. It's usually so obvious that you don't need to, though.
There are definitely some potentially tricky situations (closures, etc), but in over a year of working with ruby full time, I have yet to encounter one.