T
Trans
Trans said:That's the best example I have yet seen. Thanks for that Ara. Yet
there's still a problem. Your expecting a NoMethodError on nil, just
like I said. That's the thing, there's no other possible issue involved
here. Now I'll grant James' concern that it can make some bugs harder
to track down, but if that's our primary concern then I suggest we get
back to static typing.
Consider further, that ANY EXTENSION WHATSOEVER can have the same
effect. If someone's class X defines #geegee and I add #geegee to
String, one can no long expect String to raise a NoMethodError on
#geegee. So I argue that the bad form is not in using nil.empty? BUt in
expecting such an error, and not addressing it properly.
hash_of_lists = Hash.new{|h,k| h[k] = new_list}
raise AProperError unless hash_of_lists[:key]
hash_of_lists[:key] << 42 if hash_of_lists[:key].empty?
Oh, one more thing. The best way to address the issue raised by James
is to add selector namespaces to Ruby.
T.