Confessions of a Python fanboy
Emmanuel Surleau
emmanuel.surleau at gmail.com
Fri Jul 31 01:46:49 EDT 2009
On Friday 31 July 2009 01:06:31 Robert Kern wrote:
> On 2009-07-30 16:44, r wrote:
> > On Jul 30, 4:29 pm, Emmanuel Surleau<emmanuel.surl... at gmail.com>
> >
> > wrote:
> >>> 1.) No need to use "()" to call a function with no arguments.
> >>> Python --> "obj.m2().m3()" --ugly
> >>> Ruby --> "obj.m1.m2.m3" -- sweeet!
> >>> Man, i must admit i really like this, and your code will look so much
> >>> cleaner.
> >>
> >> It has benefits - code does look better. It has also significant cons -
> >> it is ambiguous.
> >> For instance:
> >>
> >> a = b
> >>
> >> Is b a variable or a method called without parameter?
> >
> > Hello Emanuel,
> > Again, who so ever names a method with such a non-descriptive name
> > will get whats coming to him. And if you did for some reason use such
> > a cryptic name as "b", do yourself (and everyone else) a favor and
> > follow it with "()" to denote the method call. Remember when something
> > is optional that means you have an option to use it OR not use it.
>
> I believe his point is that it is ambiguous to the compiler, not humans
> reading the code.
Actually, both. Use a variable you didn't initialize? This is what you get:
NameError: undefined local variable or method `b' for main:Object
from (irb):1
The compiler has no idea if b is a variable or a method. It also makes it very
easy to shadow an existing method by declaring a variable of the same name,
which is problematic. I suppose it is a side-effect of Ruby's Perl
philosophical inheritance - except that Perl uses sigils to prefix its
variables, negating this issue.
Cheers,
Emm
More information about the Python-list
mailing list