On Oct 5, 2004, at 5:22 PM, Mark Hubbart wrote:
> imho, there are two occasions for extending a class:
> 1. When the added methods are useful for that class in general (ie,
> String#rot13, Integer#factors)
> 2. When you're just hacking :)
But this is all fairly subjective, isn't it? Among some programmers,
String#rot13 might be a really sensible thing to add, but to others
maybe it might seem like cruft. One interesting example from RubyConf
was Rich Kilmer saying that he added methods like #minutes and #days to
Fixnum, so he could say things like
15.minutes + 2.hours
It's also very easy to imagine using this for, say, feet and inches:
1.miles + 6.feet + 6.inches
... which is culturally specific, isn't it? I mean, you're not going to
use that if you use the metric system like a civilized people.
There are two competing philosophies in OO theory. On one hand, you
have the Platonists who believe that types are eternal forms that can
be found in nature, so if you did your analysis right you'd find those
forms and be able to codify them in your class definitions. On the
other hand, you have the Pragmatists who believe that types are just
shorthand, to be defined and discarded as the situation allows.
Ruby is more of a Pragmatist language, which personally I like 'cause
on some deep level it jibes with my own belief in the subjectivity of
experience. So, you know, if you want to extend a class, do it if it
makes your life easier. If it doesn't, then don't do it.
Francis Hwang
http://fhwang.net/
AIM: francisrhizome