From: Austin Ziegler Date: 2009-02-03T01:26:44+09:00 Subject: [ruby-core:21759] Re: New documentation system! On Mon, Feb 2, 2009 at 10:31 AM, Berger, Daniel wrote: > If we're going to go that route, then we should bake it directly into > the method declaration: > > def some_method(String param1) => Fixnum > ... > end > > Method "some_method" takes a single parameter, that should be a > String, and returns a Fixnum. Rdoc could handle this directly. Plus we > get metadata from the method declaration itself, instead of trying to > parse a comment system. I think there's greater potential for DBC with > this approach, too. > > No, it's not static typing or, at least, it doesn't have to be. It > could be purely advisory. If the type _does_ match, then you optimize. > If it doesn't, emit a warning, and you get no optimization. I'm sorry, but I hate it. When I call #some_method, param1 *doesn't* have to be a String or a descendant of a String, it just has to be sufficiently String-like (which may simply involve defining #to_str). If you start doing this, then you're going to have people who want overloading (see below for the reason): def some_method(String param1) => Fixnum; end def some_method(Array param1) => Fixnum; end And they're going to be sorely disappointed when, in fact, that doesn't work because Ruby doesn't do overloading, only overriding. So then you start suggesting other things: def some_method([String, Array] param1) => Fixnum; end And very quickly what seems like a good idea starts looking noisy and people start complaining that Ruby is an ugly noisy language that requires that you type way too much. Add to this that whether it's "static typing" or not, there's a lot of stupid programmers out there who will think that it is and tend to avoid great ideas like duck-typing and object extensibility. They'll see your definition of #some_method and say "oh, it needs to be a string" and do something stupid like: # Convert p1 to a string because #some_method needs it to be a string p1 = p1.to_s res = some_method(p1) There's nothing of value in this sort of declaration in the real world. -austin -- Austin Ziegler * halostatue@gmail.com * http://www.halostatue.ca/ * austin@halostatue.ca * http://www.halostatue.ca/feed/ * austin@zieglers.ca