2013/11/13 anatoly techtonik email@example.com:
I don't know Ruby. Where I can read more about this Ruby's fail? The Ruby Programming Language, 126.96.36.199: "spaces and method invocations": """ Ruby's grammar allows the parentheses around method invocations to be omitted in certain circumstances. This allows Ruby methods to be used as if they were statements, which is an important part of Ruby's elegance. Unfortunately, however, it opens up a pernicious whitespace dependency. Consider the following two lines, which differ only by a single space: f(3+2)+1 f (3+2)+1 The first line passes the value 5 to the function f and then adds 1 to the result. Since the second line has a space after the function name, Ruby assumes that the parentheses around the method call have been omitted. The parentheses that appear after the space are used to group a subexpression, but the entire expression (3+2)+1 is used as the method argument. If warnings are enabled (with -w), Ruby issues a warning whenever it sees ambiguous code like this. The solution to this whitespace dependency is straightforward:
print(1,2) 1 2 print (1,2) (1,2)
They should both map to print as expression, meaning print as a function, i.e. to the first one.
So you want Python to behave like this:
xxx = (1,2) print xxx.count(1) 1 print (1,2).count(1) # or (1).real, since 1.real is an error Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'count'
That's pretty incosistent and will surprise beginners.
My own feelings is that this feature is the kind of thing that can make a person leave the language, or never begin using it in the first place; Things like this are part of the reason I don't use Ruby. And all this to save keystrokes? If it was part of a bigger feature, like ML's curried functions syntax, it would have been great - things like:
perr = print sys.stderr perr "Bad command or file name"
But keystrokes just can't be the reason for introducing such inconsistencies.