Hacker Newsnew | past | comments | ask | show | jobs | submit | sd314's commentslogin

C is not designed for OOP. You will write much nicer C code without such patterns.


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.


Not a nice idea to do reference implementation in C++ instead of C!


One can use C++ in radically different ways.

I would appreciate a reference implementation in Rust. Or, if not intended for immediate linking, in something like OCaml or ATS. Clarity and correctness are important in a reference implementation, and they are harder to achieve using C.


Best practices and rules in C++ are changing on a daily basis as the language is still evolving. On the other hand, C is much more readable for many programmers and researchers even with a little programming experience. Moreover, C is more portable and helps the reference implementation be quickly adapted for production or being used by the other compatible languages.


> Best practices and rules in C++ are changing on a daily basis as the language is still evolving.

Yeah "daily", C++ standard evolves every 3 years minimum and most API are still C++11 meaning 9 years old. "Daily" right ?

This is FUD. Without even mentioning that any C++lib can expose a C API.


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

Search: