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) [pdf]

214 pointsby geospeckover 7 years ago

9 comments

yawaraminover 7 years ago
The first chapter, on abstraction and information hiding, is probably the most important. Every programmer should know how to do it. It&#x27;s one of C&#x27;s main strengths that it allows abstract data types so easily. ADTs in fact allow better binary compatibility since you only expose pointers as your public API, not structures of different shapes and sizes.<p>I&#x27;m continually surprised by how often people insist on putting struct definitions right in their header files, defeating the whole idea of type abstraction.
评论 #15518906 未加载
评论 #15519402 未加载
评论 #15518691 未加载
评论 #15519696 未加载
评论 #15518661 未加载
评论 #15518930 未加载
评论 #15518729 未加载
sesteelover 7 years ago
This is one of my favorite reads. About 10 years ago I was developing a toy programming language that compiled to ANSI-C and this was a great resource to me at the time.
kuwzeover 7 years ago
Reminded me of the C Object System by Laurent Deniau[0].<p>[0]: <a href="http:&#x2F;&#x2F;ldeniau.web.cern.ch&#x2F;ldeniau&#x2F;cos.html" rel="nofollow">http:&#x2F;&#x2F;ldeniau.web.cern.ch&#x2F;ldeniau&#x2F;cos.html</a>
pdfernhoutover 7 years ago
I wrote an AI Expert article on a similar theme (&quot;Simulating Intelligent Interacting Objects in C&quot;, AI Expert, January 1989) about using C for OO programming of a robot simulator -- where the first argument is a pointer to a data structure representing the object. I prefixed all the function names with the class name, like Robot_move(robot, x, y). I was inspired by IIRC Eric Schildt&#x27;s previous article elsewhere on how OO is an attitude.<p>Looks like a very comprehensive book though compared to just some short articles (even if it does not cite those as previous work). In general, this idea of opaque handles was (and is) very common in C programming, like with file operations. So, the question is what conventions we use or what convenience superstructure we build around that basic idea of handles.
wybiralover 7 years ago
One thing that was really educational for me was reading how CPython implemented their object system. <a href="https:&#x2F;&#x2F;github.com&#x2F;python&#x2F;cpython&#x2F;blob&#x2F;master&#x2F;Include&#x2F;object.h" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;python&#x2F;cpython&#x2F;blob&#x2F;master&#x2F;Include&#x2F;object...</a><p>Basically objects are structs that all share the same header which contains a pointer to the object type (ob_type) and the reference count (ob_refcnt) for memory management.<p>That way you can always cast back to a pointer of that header struct and access ob_type and ob_refcnt no matter what the actual implemented struct contains afterwards.<p>ob_type contains the name of the type and function pointers for common methods used by objects (getattr, setattr, hash, arithmetic, etc).
jacinaboxover 7 years ago
For me the notion of domain is helpful in understanding OO. The definition of a domain is that everything inside it stands in determinate relations, whereas while multiple domains can interact they don&#x27;t stand in determinate relations. Inheritance in classes, in adding more features to a class, can also have knock-on effects that interfere with the assumptions of other classes that are closely coupled to it, making classes an example of domain. Whole computers in a network are also domains; nodes can go down in which case no determinate expectations can be placed on them.<p>The existence of multiple domains is essentially postmodern as it creates, for practical purposes, multiple sources of truth. Because the expectations of one domain on another are weak, this naturally leads to a domain becoming robust against errors and inconsistencies from other domains, which leads to a stronger system. This type of robustness also helps components still be valid when they are placed into a different theory&#x2F;environment that has additional properties. In some sense FP and OO are aiming at the same thing, that is making definitions that remain valid when the &quot;arrows&quot; of their environment change their meaning.<p>For a different perspective on this see Gerald Jay Sussman, &quot;We Really Don&#x27;t Know How to Compute!&quot;
kasajianover 7 years ago
Another article related to this: <a href="https:&#x2F;&#x2F;www.codeproject.com&#x2F;Articles&#x2F;22139&#x2F;Simply-Object-Oriented-C" rel="nofollow">https:&#x2F;&#x2F;www.codeproject.com&#x2F;Articles&#x2F;22139&#x2F;Simply-Object-Ori...</a><p>I wrote it a while back just to see what I would come up with if I had to solve that problem for myself using only macros.
paklover 7 years ago
I am a fan of libco2[1] which is a minimalist object-oriented layer on top of C.<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;peterpaul&#x2F;co2&#x2F;tree&#x2F;master&#x2F;examples&#x2F;my-object-carbon&#x2F;src" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;peterpaul&#x2F;co2&#x2F;tree&#x2F;master&#x2F;examples&#x2F;my-obj...</a>
Koshkinover 7 years ago
<p><pre><code> &gt; void * find (const void * _set, const void * _element) </code></pre> Such an eye sore, and I think it goes strongly against the tradition of coding in C when someone uses the asterisk in the pointer context in such a way that makes it look like an infix operator, i.e. as if it was multiplication.<p>As to achieving a <i>reasonably looking</i> OO in C, this is why C++ was born...
评论 #15520548 未加载