From: Robert Klemme Date: 2012-03-30T20:04:07+09:00 Subject: Re: Why z = Complex(1,2) rather than z = Complex.new(1,2)? Jan E. wrote in post #1054047: > Eric Hodel wrote in post #1054029: >> >> I've never heard that there was a convention to avoid capitalizing >> method names, and I've been doing this a long time. > > This convention is in the Ruby book by Matz and Flanagan, saying that > uppercase method names can be confused with constants (which is a bad > thing in my opion). Well, but there are only few cases of this plus in this case Complex() and Complex actually mean the same thing. > So it's not that we made this up. ;-) Everything should be taken with a grain of salt. > In Netbeans I even get a warning: > > "Style: Method names traditionally use lowercase letters only" Do you get that at the calling site or at the definition site? > But it's not so much about conventions. These methods are simply > counterintuitive. When I want to convert objects, the first thing that > comes to my mind are the to_... methods. But I don't expect someone to > pull a magical conversion "function" out of the Kernel module. Honestly, > I think even experienced Ruby programmers are confused when they first > see something like Float(4) No, not at all. An experienced Ruby programmer will identify this immediately as a method call. And he will probably do ~$ ruby19 -e 'p method(:Float)' # And then do ri19 Kernel#Float But you do not have to use that method. > Another problem is that constants and methods have different lookup > algorithms, which doesn't allow you to put the conversion method for a > subclass into the same containing module/class (unless you use qualified > names all the time). Can you show an example of what you cannot do? At the moment I don't see the limitation. > All in all, I think those methods really qualify as "Ruby warts" and > should be removed as soon as possible. ;-) There are far worse "warts" as you call them, for example class variables. Kind regards robert -- Posted via http://www.ruby-forum.com/.