From: Pit Capitain Date: 2002-09-30T07:20:19+09:00 Subject: Re: thoughts on typelessness On 29 Sep 2002, at 12:09, dblack@candle.superlink.net wrote: > (lots of interesting remarks about explicit typing discussion) > > One possible factor, I think, is the #type method. As I mentioned on > IRC this evening, I sometimes wish Ruby didn't have it. It's harder > to make the argument that objects don't have types, when the objects > themselves willingly tell you their types.... :-) And I might add > #is_a? and #kind_of? to the list. Maybe they're necessary for > reflection. It's interesting to try to program without them. > > (snip) > > I've done that, for instance, in my dbdbd (database definer) program. > It uses 1-originating array notation to index columns, but can also > use field-names. So the reader method for the sort_key (for example) > is: > > def sort_key > @sort_key - 1 > rescue NameError > @sort_key > end When you announced dbdbd I quickly browsed through the code. I had the impression that I understood your well written program - besides this very example. I really tried to understand what's going on, but I just couldn't get it. > which I think looks better than: > > def sort_key > if @sort_key.respond_to?(:-) > @sort_key - 1 > else > @sort_key > end > end Ok. With this alternative code and the remarks in your mail I finally understand what you did. But for me the most intention revealing implementation would simply be: def sort_key if @sort_key.is_a? Integer @sort_key - 1 else @sort_key end end I'm sure it would be very interesting to try to program without #type, #is_a? etc and I'm sure I will try to do so in the future, but for me this wasn't a good example. If you think so, too, maybe you could find an other implementation. I'd be very interested in what you'd come up with. Regards, Pit