News for hackers. Stuff that matters.
Re:Inheritance is evil, and must be destroyed: part 1 by mdemare on Friday October 12, 2007 @11:23PM (#67175)
The last couple of years my programming style has changed a lot. I've noticed that I've been using inheritance less and less. When I was still doing Java, I only used (implementation) inheritance when the API forced me to, and now in Ruby I hardly use inheritance at all.

I even use objects a lot less - prefering to pass around hashes until they've blossomed into fairly well defined types. To me, a class is a data structure that provides a namespace for the functions that manipulate it, and little more.

In any case, I think nearly empty classes with nothing but accessors have no use in dynamic languages (in static languages they provide at least code completion support.)

I also increasingly dislike local variables and if-statements (preferring case statements). I like my methods having flow, and if-statements and local variables break that flow, like a caesura in music.

What bothers me is that I don't know if this is my progress towards becoming a zen-like programmer, or just me being bored with the old way of doing things, and discovering a new fad. It seems there is no way to tell.

Re:Inheritance is evil, and must be destroyed: part 1 by cstejerean on Friday October 12, 2007 @11:44AM (#66879)
one problem that i have with inheritance, especially several layers deep is that it hides code from the developer and it makes it hard to get an idea of what is going on. A sequence of calls needs to be traced across several class definitions. Sometimes inheritance makes sense as an abstraction mechanism but i think it's often overused, especially in Java
Re:Inheritance is evil, and must be destroyed: part 1 by testapplication on Friday October 12, 2007 @10:42PM (#67124)
Only a problem if you are browsing your project with notepad.
Re:Inheritance is evil, and must be destroyed: part 1 by iamwil on Friday October 12, 2007 @09:16AM (#66814)
The way the author uses the common implementation reminds me of Ruby mixins. One of the things that takes a bit of getting use to in Ruby is that classes aren't types, and object hierarchy is used to share implementation, rather than enforce type.
Re:Inheritance is evil, and must be destroyed: part 1 by gills on Friday October 12, 2007 @08:02PM (#67079)
Inheritance is a useful tool. The article mentions the strategy pattern which, ironically, often requires inheritance to implement. So I feel like the author may have been burned and/or confused by inheritance, and following true nerd form has cast it aside completely.

Sometimes when you are using a framework, the productivity gained from inheritance cannot be ignored. I suppose this depends on the language and framework design, to a limited extent.

That said, I try to compose rather than inherit when possible, as it provides a more opaque implementation.

Re:Inheritance is evil, and must be destroyed: part 1 by dangph on Saturday October 13, 2007 @12:44AM (#67193)
> The article mentions the strategy pattern which, ironically, often requires inheritance to implement.

Not really. It only requires interface inheritance for statically-typed languages, which is not really inheritance, and no inheritance at all for duck-typed languages.

Re:Inheritance is evil, and must be destroyed: part 1 by jsjenkins168 on Saturday October 13, 2007 @05:09AM (#67250)
Compositing should always he used over inheritance where possible, in my opinion. However, claiming inheritance should never be used is a bit unrealistic. There are times when it is a useful and logical choice.
Re:Inheritance is evil, and must be destroyed: part 1 by MuddyMo on Friday October 12, 2007 @05:15PM (#67034)
Very lucid description of one of the major pitfalls (cough) inherent with a strict OOP design structure where the problem domain and/or programming language does not facilitate its imposition.