Hacker News new | ask | show | jobs
by sd314 2162 days ago
C is not designed for OOP. You will write much nicer C code without such patterns.
2 comments

I agree. While it is occasionally can work alright (as with the examples in the article), I recommend a very light touch with this stuff. If you get to the point where you are implementing casts, RTTI, etc, stop and rethink. I say this as someone who has gone down this path and later regretted it.
In a professional context I couldn't agree more. However for a hobby project I couldn't disagree more. Implementing safe down-casting (up is trivial), dynamic dispatch, encapsulation, and other OO(ish) features is an absolutely wonderful learning experience. Like most first attempts, it will probably be a mess as you say, but there can be a joy in making a mess of things so long as you're not inflicting it on the unsuspecting.
Yes I agree that for learning purposes it can be very illuminating. :)
No, actually C was designed with this pattern in mind. That is why the C standard guarantees no padding before the first struct member.