When people tell me that they love C, I don't get it.<p>C is so tiny that if you're going to write anything non-trivial you either have to re-implement various common data-structures yourself, or find appropriate libraries. No built-in string type, no vectors, no nothing. Also, the lack of generics makes for really ugly code, filled with void pointers and casts whenever you attempt to write type agnostic data structures such as lists, queues, etc.<p>It also seems that whenever I have to write in C, I end up writing code that painfully wants to be object-oriented, or implementing features that are already part of C++.<p>So why would you willfully pick to use C when C++ is around?
Heck, even if some sick reason you don't want to use explicitly use objects, at least you can enjoy some of the other benefits of C++ (e.g. its standard library).
Zed Shaw's Learn C The Hard way has an exercise that builds a simple prototype based OO system using C[1].<p>[1]: <a href="http://c.learncodethehardway.org/book/ex19.html" rel="nofollow">http://c.learncodethehardway.org/book/ex19.html</a>
Relative noob here,
I'm learning programming in general and I picked C to start with. My university courses are pretty shitty so I have to do it by myself.
OOP is pretty repulsive to me. I don't know why. Too many abstraction that I can't see clearly.<p>Would any of you recommend me to try and get the hang of OOP using C or should I just pick up Java or C++ ?<p>(sorry if this is a inappropriate comment on this post)
I had to make an application framework something like this with ANSI C in the 90s. Make a structure (or two) full of function pointers as an "interface", pass it (them) as the first parameter to all the relevant functions as "this"/"self". (wait, that kinda looks like what "Go" does - hmmmm)<p>Of course, some in the company tried to pad their resumes with actual (gahd-awwwful) C++. Lovely jewels like this:<p><pre><code> if ( output_format == A) {
a.write_pg_header();
} else {
b.write_pg_header();
}
</code></pre>
Guess they never heard of a virtual method. Then there's the fun of all the memory leaks from copy constructors and other silly C++ pitfalls.<p>Simulated OOP in C is an interesting exercise. I suppose if I had not learned an OOP language other than C++ first, I would have thought C++ is just how (hard) it's supposed to be :-)
I ran into this a while back. Worth knowing about I think. I'd like to see a compare-and-contrast with "Writing Bug-free C Code." (<a href="http://www.duckware.com/bugfreec/index.html" rel="nofollow">http://www.duckware.com/bugfreec/index.html</a>)
For page 33:<p>"
struct Circle { const struct Point _; int rad; };
We let the derived structure start with a copy of the base structure that we are
extending. Information hiding demands that we should never reach into the base
structure directly; therefore, <i></i>we use an almost invisible underscore as its name<i></i> and
we declare it to be constto ward off careless assignments.
"<p>This looks so manual that reminds me "C with classes". It is a very pedagogic read though.
Historical interest: Amiga BOOPSI. Not saying it was perfect, but it certainly existed.<p><a href="http://en.wikipedia.org/wiki/BOOPSI" rel="nofollow">http://en.wikipedia.org/wiki/BOOPSI</a>
<a href="http://en.wikibooks.org/wiki/Aros/Developer/Docs/Libraries/Intuition/BOOPSI" rel="nofollow">http://en.wikibooks.org/wiki/Aros/Developer/Docs/Libraries/I...</a>
Big C/C++ fan here, although I'm sure writing software for PC in C is extremely painful. Personally for PC soft I'm using C++ (Qt) but I actually really had to learn some 'higher level' language for this particular job.
However, my main area of interest are microcontrollers and there is NO other option than learning C (C++ compilers costs too much for a hobby projects).
I was kind of expecting this to be a link to Zhivago's article on OOP with C<p><a href="http://www.codersger.de/mags/cscene/CS1/CS1-02.html" rel="nofollow">http://www.codersger.de/mags/cscene/CS1/CS1-02.html</a>