John Carter wrote: > Well, a more sophisticated Static Typer would do... > attr_reader :date > def date=(val) > raise ArgumentError.new("Not a Date") if val.kind_of? Date > end Ah, of course. But seeing as I never actually do this in code, I can be excused, right? :P Thanks for the suggestion. > I would also prefer it to rescue just a No Method exception than just > any Exception. You can really really really hide some horrible bugs catching > just any exception. Like empty catch blocks in Java, it is a truly > evil practice. Again, you're correct and I hadn't thought much about these pieces of code beyond the basic functionality since they were throw-away examples anyway. Although there are cases where the code might throw an ArgumentError instead of a NoMethodError and still work. The logic behind catching just any exception was that if one method doesn't work, for whatever reason, bail out and try a different one... > The worse breakage I have seen in a Object Oriented System was in a > language called Actor, where for optimization reasons they had forced > the internal representation of their graphics type into pairs of two byte > integers. This turned a very large, very useful generic 2D geometry > library into something totally useless to me. ie. Never gratiutously > break polymorphism, even if you personally can't think of another use > for this code, somebody else can. I'm sorry, I don't quite follow you; can you clarify a little? How did changing the internal representation break things? How does this relate to polymorphism or Duck Typing? > For example, suppose you got a string from a SQL server that was a > "date". But since parsing the string is difficult and expensive to do, > you just don't. You stuff it into the date= method and lo and behold, > it just so turns out that for this execution path you _never_ actually > invoke :year, :month, :day, it just travels through your system, and > gets converted to a string with .to_s and written back to SQL. This is rather risky; you're assuming less than what the documentation says, and hoping that nobody else assumes any more than you do. That's just asking for someone to come along and add something that does use one of those methods, and suddenly things come crashing down around you. On the other hand, however, if you know what you're doing then this is one of the advantages of Duck Typing, and part of the beauty of Ruby - if you *know* that those methods will never get called, the language never forces you to convert the date into that format if you don't want to. Tim. -- Tim Bates tim / bates.id.au