Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The article is very humble, but in my view, seems to go a little too far.

"You can reuse code with inheritance. Absolutely crazy. Brilliant.

All of this blew me away."

Honestly?



Thats a very critical point that you just have to understand, to "get". Many people know and learn about object oriented design, but when tasked to actually write a program based on these principles they will often revert to code where they make distinctions based on the type of what they have been handed.

TLDR: dynamic_cast is bad design


Using static conditions rather than polymorphism seems to just be a common thing that people tend to do, regardless of skill level or quantity of experience. It's not uncommon for people just not to think of using polymorphism, if the objects in question wouldn't really model any particular kind of object as such (they're just there to provide a table of function pointers). This says nothing about the quality of their code, or the general OOness of their designs, or the number of digits in their IQ.

It's a bit of a shame, because I've found code to be reliably improved by using objects as simple tables of function pointers. The same is less often true for using objects as models of things.


That is strange to hear. That kind of polymorphism is literally the first example given in any OO tutorial. "Bark", "Meow", "Oink", etc.


The traditional animals/shapes/cars/etc. examples all use objects to represent actual things. But sometimes, one's objects don't reflect anything that you're trying to actually model. The need for them has just sort of arisen from the way the code has structured. They don't represent anything as such, they're just a way of putting in some extensible runtime dispatch. And it seems like people often prefer to use conditionals rather than objects for this situation. Not really sure why. Perhaps most people think of mere objectness as having some meaning, that makes using an object inappropriate for this kind of situation? I'm not sure.

If you keep an eye out for this, I'm pretty sure you'll start to spot it!


I guess he's gonna come back with another article when he realizes composition > inheritance.


You'll need to wait like 5 years if he was anything like me


My thought exactly. Seems like a pretty basic usage of polymorphism/inheritance.


I didn't get that from the article. What I heard was the guy was amazed that someone took the time to attempt to better his code and (in his opinion) made it much better.

I agree with that a large extent - that's something that always amazes me about open-source. You're slogging along doing your thing, and then all of a sudden someone drops a huge patch on you that makes so much sense.

With that said; I did go back and re-read it, and your reading could be correct, it's hard to say. Does have a bit of humble brag to it for sure.


I also did not got the point.

It is as if the OP did not grasp what OOP is all about.


To each his own.

For me it was epoll() that blew me away. Absolutely crazy. Brilliant. But in retrospect so damn obvious.


epoll() (or its predecessor poll()) is a kind of low-level API function, whereas polymorphism is a general and fundamental programming concept.


It's irrelevant. The point is that either was an example of dramatically different way of looking at things. "You don't know what you don't know, but now you do."


At that point I closed the article and thought "Wtf HN, why was this on the front page?". Then I remembered that anything Ruby-related gets automatic upvotes, even if the author does not know the first thing about OOP.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: