TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Object oriented programming with ANSI-C (1993)

79 pointsby xkarga00over 11 years ago

10 comments

mikevmover 11 years ago
When people tell me that they love C, I don&#x27;t get it.<p>C is so tiny that if you&#x27;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&#x27;t want to use explicitly use objects, at least you can enjoy some of the other benefits of C++ (e.g. its standard library).
评论 #7012718 未加载
评论 #7012963 未加载
评论 #7012966 未加载
评论 #7013800 未加载
评论 #7013175 未加载
评论 #7013618 未加载
评论 #7013058 未加载
评论 #7013497 未加载
评论 #7012964 未加载
评论 #7012884 未加载
评论 #7014152 未加载
评论 #7013369 未加载
d4rtiover 11 years ago
Zed Shaw&#x27;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:&#x2F;&#x2F;c.learncodethehardway.org&#x2F;book&#x2F;ex19.html</a>
filkatronover 11 years ago
Relative noob here, I&#x27;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&#x27;t know why. Too many abstraction that I can&#x27;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)
评论 #7012359 未加载
评论 #7012955 未加载
评论 #7012142 未加载
评论 #7012174 未加载
评论 #7012121 未加载
评论 #7012588 未加载
评论 #7012334 未加载
评论 #7012632 未加载
评论 #7012944 未加载
Roboprogover 11 years ago
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 &quot;interface&quot;, pass it (them) as the first parameter to all the relevant functions as &quot;this&quot;&#x2F;&quot;self&quot;. (wait, that kinda looks like what &quot;Go&quot; 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&#x27;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&#x27;s supposed to be :-)
评论 #7012020 未加载
评论 #7012196 未加载
blacksqrover 11 years ago
I ran into this a while back. Worth knowing about I think. I&#x27;d like to see a compare-and-contrast with &quot;Writing Bug-free C Code.&quot; (<a href="http://www.duckware.com/bugfreec/index.html" rel="nofollow">http:&#x2F;&#x2F;www.duckware.com&#x2F;bugfreec&#x2F;index.html</a>)
评论 #7011801 未加载
pmelendezover 11 years ago
For page 33:<p>&quot; 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. &quot;<p>This looks so manual that reminds me &quot;C with classes&quot;. It is a very pedagogic read though.
davidgerardover 11 years ago
Nice book, but please change the title to note this is a 221-page PDF!
daviddlhgover 11 years ago
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:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;BOOPSI</a> <a href="http://en.wikibooks.org/wiki/Aros/Developer/Docs/Libraries/Intuition/BOOPSI" rel="nofollow">http:&#x2F;&#x2F;en.wikibooks.org&#x2F;wiki&#x2F;Aros&#x2F;Developer&#x2F;Docs&#x2F;Libraries&#x2F;I...</a>
ithinksoover 11 years ago
Big C&#x2F;C++ fan here, although I&#x27;m sure writing software for PC in C is extremely painful. Personally for PC soft I&#x27;m using C++ (Qt) but I actually really had to learn some &#x27;higher level&#x27; 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).
bluedinoover 11 years ago
I was kind of expecting this to be a link to Zhivago&#x27;s article on OOP with C<p><a href="http://www.codersger.de/mags/cscene/CS1/CS1-02.html" rel="nofollow">http:&#x2F;&#x2F;www.codersger.de&#x2F;mags&#x2F;cscene&#x2F;CS1&#x2F;CS1-02.html</a>