From: hemant Date: 2007-12-19T19:18:17+09:00 Subject: [Rhetoric] Two feature requests for safer Ruby Programming You can take my take on following issues with a pinch of salt, when you disagree I perhaps know, why you disagree and generally respect your opinion no matter how badly i disagree. 1. Image a new guy joins your rails team and he writes code like this in a controller: def get_quote(ticker) # create a request string, that matches internal protocol request = format_request_str(:quote, ticker) # Market is a class that hold TCP connections to server that can give stock market quotes response = Market.get_response(request) end Above code is going to blow. Why? because request is a method defined by ActionPack. What can we do to prevent this? or this guy is simply dumb and should stop programming? Well in my opinion, the precious little that Ruby can do is to enforce having '()' for method invocation. Does that solve the problem? Heck no, what if our man goes and defines: def request(request_type,ticker) # create a request string and return it end There he is till shooting himself in foot. This brings second issue. 2. Adding methods to core classes, overriding core class methods, silent override of methods inherited from parent classes is a big problem with Ruby. Ruby absolutely gives no indication that this has happened. Today, you may claim that heck, I will stay away from such libraries ( quoting : raggi on #ruby-lang ). Today you have that luxury, because even if a library is not documented, you can see the source code of every damn library and find out, what its doing. You can stay safe that way. But this will not be the case in future. JRuby, Ruby2.0, Rubinius,IronRuby are preparing a future where compiled bytecode may be only thing that can be distributed. Again, as a free software guy You can avoid such "evil" libraries. But imagine, if you are using such a library and library is not very well documented, you are in for a fun. Another thing that I have seen with rubyists (including myself) is, they don't really follow class encapsulation properly. What I mean, you will rarely see a library that uses :private and :protected properly. Why is this? Because ease with which private methods can be called, people don't really care. It is dangerous, without source code, proper encapsulation and silent override of a method, you are in for fun. But this encapsulation issue is just scratching the surface, even unindented override of public methods is a potential hazard. Whats the solution? In my opinion, when unintended override of a method happens, Ruby should throw a warning. To silent that warning, one should explicitly say you are overriding a method. Thats about it. -- Let them talk of their oriental summer climes of everlasting conservatories; give me the privilege of making my own summer with my own coals. http://gnufied.org