From: Mark Hahn Date: 2001-12-11T09:11:02+09:00 Subject: [ruby-talk:28157] Re: The benefits of dynamic typing? That looks correct. If String::to_s is fast (it should be since there is nothing to do) then this is even simpler: class String alias old_plus + def +(x) old_plus x.to_s end end But my point was the arguments being made against this feature fell into the "protecting programmers from themselves" category which I have a big problem with. How does everyone else feel about "protecting programmers from themselves"? At what point does a compiler switch from being helpful to being a pain? I think this is the fundamental question behind this message thread. -----Original Message----- From: Harry Ohlsen [mailto:harryo@zip.com.au] Sent: Monday, December 10, 2001 4:02 PM To: ruby-talk ML; undisclosed-recipients: Subject: [ruby-talk:28155] Re: The benefits of dynamic typing? In article , "Mark Hahn" wrote: > The reason I lost the argument was that they claimed it would cause > hard-to-find bugs if someone meant: "1".to_int + 1. They claimed it was > ambiguous. To me it is obvious that "1"+1 means a string and 1+"1" > means an integer (because of message passing). You can make this work the way you want (although, you'd have to stick this code in a module and "require" it in all your code). Note that I'm not known for writing the simplest version of things, so someone else will probably have to clean it up for me (and I've only done the 1 + "1" case for Fixnum; it would probably have to be coded more generally to be useful) ... class String alias old_plus + def +(x) if x.type == String old_plus x else old_plus x.to_s end end end class Fixnum alias old_plus + def +(x) if x.type == String old_plus x.to_i else old_plus x end end end puts "1" + 1 # => "11" puts 1 + "1" # => 2