4 ms·
> I have been interested in pure C lately, and I really need to level up my experience. > I wanted to use a object oriented style with constructors and polymo
by kybernetyk 13y ago
> I have been interested in pure C lately, and I really need to level up my experience.
> I wanted to use a object oriented style with constructors and polymorphism. Since it isn’t supported directly, you are free to implement it as you feel like.
I've been there in the "pure C" land some time ago. I drank all the 'C++ is shit' koolaid that was spread some time ago all over the net. And I hacked away quite a few projects in C - with my own implementation of polymorphism, strings, etc.
But then I got really really tired of it. It's all extra work you don't have to do in C++. Yes, C++ can be a horrendous mess if you use all features. But it also offers awesome syntactic sugar for "structs with methods" style programming.
std::string and vector alone save you so much time. And RAII + shared_ptr will free up another huge chunk of time you otherwise would have spent thinking about memory and resource management issues.
I think everyone who's doing C++ work should go C-only for some time just to appreciate what the lovely monster called C++ actually did for programmer productivity.
* This is no flame against C. It has its place and I appreciate its existence.
- niuzeta 13y agoI actually find it more interesting that you had to postscript which says an indifferent discourse on your experience on C and C++ was not a flame against C. While I agree with your remark wholeheartedly(Yes, C++ has a lot of toolchain, but no one decreed that you have to use everything in your toolbox), I think had I written this response, I would've added that defence somewhere. I guess it's telling how far the C vs C++ discussion went and how long it raged on...
- xyzzy123 13y agoC++ advocate here. It doesn't seem to be a strongly represented opinion here, so I think it's actually worth me chiming in. All the criticisms are valid. Yes, C++ is like "making an octopus by nailing 4 extra legs onto a dog". None of us like having to remember that we need virtual destructors if we have derived classes, because otherwise deleting a class through the wrong derived pointer type would cause complicated problems. There's a bunch of crap there. But I spent years coding C and I hate going back. I miss smart pointers when I'm stuck with C. I miss containers that don't suck. I miss lame stuff like log4cpp and boost::asio. If you're willing to accept a bunch of dependencies and can handle serious (sometimes grevious) conceptual overheads, you can write native code with an expressiveness approaching Python. To me, that makes it all worth it.
- sjf 13y agoWhat are some useful libraries for C? Everyone encounters these same issues, so what is the canonical solution?
- chas 13y agoI have heard good things about the Apache Portable Runtime [1], GLib [2], and Sglib [3] if you want something a bit more stripped down. [1] http://apr.apache.org/ http://apr.apache.org/ [2] https://developer.gnome.org/glib/2.34/ https://developer.gnome.org/glib/2.34/ [3] http://sglib.sourceforge.net/ http://sglib.sourceforge.net/
- geon 13y agoI'm the guy who made this. > I drank all the 'C++ is shit' koolaid Honestly, the only real reason to use C was because I simply wanted to get some more experience writing C. I was also curious how OO would be done in C. I just got a new job, and one of the positions I was interviewed for would involve developing a Bluetooth stack for embedded devices. I ultimately wasn't offered that particular job, because I didn't have the experience in C they were looking for. Too bad, it could have been fun. I have nothing against C++ really. It's just that if I would do a hobby project in C++, I would like to focus on the modern features like smart pointers and write really clean, idiomatic C++. The old code for the renderer was neither.