Confessions of a Python fanboy
rt8396 at gmail.com
Thu Jul 30 19:45:49 CEST 2009
On Jul 30, 12:37 pm, Jean-Michel Pichavant <jeanmic... at sequans.com>
> r wrote:
> > On Jul 30, 11:31 am, Falcolas <garri... at gmail.com> wrote:
> >> On Jul 29, 9:06 pm, r <rt8... 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.
> >> I personally would not prefer this, and would likely continue to use
> >> (), precisely for code clarity - let me explain:
> >> foo.nextval
> >> foo.val
> >> foo.previousval
> >> Which of the calls above referenced instance variables, and which ones
> >> called functions which changed the internal state of foo? I would have
> >> trouble saying, just based on the calls above. I would have to go back
> >> to the definition or documentation of foo to identify which is doing
> >> what. On the other hand, the following gives a better clue as to what
> >> is happening (granted not perfect, but better):
> >> foo.nextval()
> >> foo.val
> >> foo.previousval()
> >> ~G
> > I held your exact same view before i learned the Ruby language. And
> > your veiw makes some good points, however, naming conventions with
> > eliminate this problem all together. All "method names" should use the
> > underscore to separate words, "variable names" should use camelCase,
> > "constants" in all caps, and "class defs" in titlecase.
> > def go_and_do_this_for_me_now(self, *args)
> > self.variableNameHere
> > MyClassNameHere
> > THISISACONSTANT -or- THIS_IS_A_CONSTANT
> > in your example i would have used the following
> > foo.next_value
> > foo.value
> > foo.prev_value
> > good naming conventions will make your life (and everybody else's)
> > much easier when debugging code.
> How do I know if foo.value is an attribute or if it is a method that
> returns the foo value ? It seems you can make the difference only when
> tokens are composed of more than one word, not very handy don't you think ?
> Just feeding the troll.
You can still use empty parenthesis in Ruby if that floats your boat.
obj.method() <-- note the empty parenthesis
I am just saying don't make them mandatory, thats all. In any case
where ambiguity abounds, by all means use the damn parenthisis.
Now Ruby will even let you call a method *that has arguments* with no
parenthisis -- however, i do not think this is a good idea. Consider
Geom::Transformation.rotation pt, vec, ang
bad coder!, bad!
...and leads to worn out eyeball parsers in a hurry
Geom::Transformation.rotation(pt, vec, ang)
yes, good boy!
More information about the Python-list