Found in 18 comments on Hacker News
chrism238 · 2023-08-31 · Original thread
Copied: Please check "The C Interfaces and Implementations" book by David Hanson [1]. Someone has implemented the concept using his library that you can check and use [2]. Another excellent reference is the "The Linux Programming Interface" book by Michael Kerrisk that documents most of the API available under Linux [3]. [1]https://www.amazon.com/dp/0201498413 [2]https://github.com/gon1332/gonlibs [3]https://www.amazon.com/Linux-Programming-Interface-System-Ha...
jll29 · 2022-10-08 · Original thread
Over the years, I have acquired most of what people call seminal C books, and after reading them, I recommend the following two books to people who already know programming:

Peter A. Darnell and Philip E. Margolis C - A Software Engineering Approach (3rd ed.) https://www.amazon.com/Software-Engineering-Approach-Peter-D...

David Hanson C Interfaces and Implementations: Techniques for Creating Reusable Software (!st ed.) https://www.amazon.com/Interfaces-Implementations-Techniques...

The first is clearly written and focuses on ANSI C (lexis, syntax and semantics), with a healthy dose of software engineering education along the way, which you may already have. (It does not yet cover the latest ISO changes.)

The second book is a true gem that teaches even seasoned programmers how to implement correct, clean and portable components as libraries in ISO C, with plenty of source code to show how the true masters of the language craft the finest code you can in C. Most books how fragments of linked list implementations, but only this book shows complete a whole range of important ADTs you cannot live without (e.g. List, Ring, Atom) in C portably, with strong typing, bullet-proof error handling etc. (Hanson is also the author of lcc, a portable C compiler.)

I'm actually surprised that these are both are so little known, and that the second one hasn't seen more editions.

teleforce · 2020-09-06 · Original thread
Please check "The C Interfaces and Implementations" book by David Hanson [1]. Someone has implemented the concept using his library that you can check and use [2].

Another excellent reference is the "The Linux Programming Interface" book by Michael Kerrisk that documents most of the API available under Linux [3].

[1]https://www.amazon.com/dp/0201498413

[2]https://github.com/gon1332/gonlibs

[3]https://www.amazon.com/Linux-Programming-Interface-System-Ha...

sn9 · 2017-01-17 · Original thread
Hanson's C Interfaces and Implementations [0] is one of the best books on the subject.

Strongly complemented by Sedgewick's Algorithms in C.

[0] https://www.amazon.com/Interfaces-Implementations-Techniques...

TimJYoung · 2016-08-21 · Original thread
This book (C Interfaces and Implementations: Techniques for Creating Reusable Software) has a whole section on it:

https://www.amazon.com/Interfaces-Implementations-Techniques...

eu90h · 2016-07-28 · Original thread
I'd recommend Ben Klemens' excellent book "21st Century C - Tips from the New School" [0]. This book teaches you modern C techniques and, most importantly, the tooling that modern C programmers use (git, autotools, valgrind, etc.) It also covers commonly used libraries to help you from reinventing the wheel (GLib, POSIX standard, SQLite, libxml, & cURL.)

As mentioned in another post, David Hanson's "C Interfaces and Implementations - Techniques for Creating Reusable Software" [1] is a great book, stressing the design of good APIs. This book in particular might help you in your goal to become a better engineer.

On the free side, there's an excellent PDF by Jens Gustedt, "Modern C" [2]. I've not read the whole thing but it seems like an in-depth look at C11.

John Regehr's blog "Embedded in Academia" [3] is a good resource for C programming. You'll learn a lot about weird edge cases and undefined behavior. He also has a recent post about teaching C, with suggestions for resources [4].

[0] https://www.amazon.com/21st-Century-Tips-New-School/dp/14919...

[1] https://www.amazon.com/Interfaces-Implementations-Techniques...

[2] http://icube-icps.unistra.fr/img_auth.php/d/db/ModernC.pdf

[3] http://blog.regehr.org/

[4] http://blog.regehr.org/archives/1393

sn9 · 2016-05-12 · Original thread
Much of the code in the fantastic C Interfaces and Implementations [0] is inspired by Modula-3. It's a fantastic book to work through after finishing K&R for anyone wanting to learn how to write safe and reusable C code.

(Regular HN readers will recognize the author of the top review on Amazon.)

[0] http://www.amazon.com/Interfaces-Implementations-Techniques-...

tumba · 2016-04-24 · Original thread
I suggest C Interfaces and Implementations: Techniques for Creating Reusable Software by David Hanson.[1] It focuses on helpful engineering practices for reliably and efficiently implementing algorithms in C.

I also second the recommendation for Peter van der Linden's Expert C Programming for its masterful treatment of how C really functions, including the surprisingly frequent areas in which real-world constructs produce "undefined behavior" from the perspective of the C standard.

[1] http://www.amazon.com/Interfaces-Implementations-Techniques-...

greenyoda · 2015-07-18 · Original thread
"With OOP it's all about classes, abstractions, interfaces etc. and design patterns."

The ability to create abstractions is pretty much a part of any programming language, including assembler. They're a property of the structure of the code, not of specific language features. For example, in the Linux kernel, which is written in C, there's an abstraction called a file descriptor that represents a stream of bytes that your program can read/write, whether it comes from a file on a disk, a serial port, a pipe, etc.

Interfaces also exist in all languages: they're just a well-defined set of calls that one piece of code uses to communicate with another piece of code. For example, the C runtime library (or any library) has an interface (API), and callers of the library don't need to know about the internal structure of the library to be able to call its services. (There's a pretty good book called "C Interfaces and Implementations"[1] that talks about how to write reusable code in C.)

Classes are also possible to implement in C. A class is pretty much a data structure with a bunch of functions (the methods) that manipulate its data. In C, this can be represented by a structure and bunch of function pointers. The "constructor" function calls malloc() to create an instance of the class, sets its member variables from its parameters and returns a pointer to it. (Implementing inheritance is a bit tricky.)

To be able effectively split development tasks across a team, the same rules apply as in any other language: implement functionality behind well-defined APIs so that one part of the code can be used by another without having to know the details of how it works.

[1] http://www.amazon.com/dp/0201498413

joeld42 · 2015-04-07 · Original thread
K&R is more of a reference, I'd suggest this instead:

"C Interfaces and Implementations" by David R. Hanson http://www.amazon.com/Interfaces-Implementations-Techniques-...

kqr2 · 2013-07-15 · Original thread
I like to recommend C Interfaces & Implementations

http://www.amazon.com/Interfaces-Implementations-Techniques-...

It uses Donald Knuth's literate programming which takes getting used to, however, it's a great case study of how to make a good library.

There is a new book on "21st Century C" which I haven't read. It has mixed reviews, however.

http://www.amazon.com/21st-Century-Tips-New-School/dp/144932...

jnazario · 2013-03-12 · Original thread
two things come to mind.

first is the classic Hanson book "C Interfaces and Implementations", http://www.amazon.com/Interfaces-Implementations-Techniques-... while you may not be coding in C the basic paradigms do carry over.

second is use the API a couple of times and you'll see natural cleavage points.

i generally develop APIs on paper first, which also helps me ensure consistency that is absent when i develop them too quickly or organically. i keep in mind my goals, i document as much as possible, and i try and stick to a paradigm.

hope that helps. i've written APIs used in internal services and applications but never externally, publicly available. i'm no expert but that's how i start.

meta · 2012-11-01 · Original thread
Cool idea.

I am confused by the implication of this code

  var prices = new(Table, String, Int);
  put(prices, $(String, "Apple"),  $(Int, 12)); 
Stack objects are created with "$" so these are on the stack and then placed into the Table? So if this was in a function and the function returned, the Table (lets assume it was global) would now be pointing to destroyed stack variables? Is that the correct interpretation?

Is this all done with header files and the preprocessor? It looks like that is the case - if so, I am impressed at the dances you got it to do ;) Also, have you read http://www.amazon.com/Interfaces-Implementations-Techniques-... which does some "Object Orientation" in C tricks?

nvoorhies · 2012-06-14 · Original thread
C Interfaces and Implementations: Techniques for Creating Reusable Software is the best thing I've seen on the topic, personally. http://www.amazon.com/Interfaces-Implementations-Techniques-...
strlen · 2010-11-24 · Original thread
There's also a much cleaner way to have interfaces and implementations in C, without relying on macro hackery.

Why, there's even a whole book on that: http://www.amazon.com/Interfaces-Implementations-Techniques-...

Like Norvig's Paradigms of Artificial Intelligence: Case Studies in Common Lisp and Joshua Bloch's Effective Java, it's one of those books which despite having a specific programming language in the title, is really about programming in general.

EatenByGrues · 2010-11-13 · Original thread
I may be using the word 'modern' a bit liberally here, but these are all more recent than K&R at least. 'C A Reference Manual' I think is what a lot of people really want out of a C book and 'Expert C'/'C Traps and Pitfalls' both help with all of the less intuitive parts of the language that you don't really get out of K&R.

C A Reference Manual http://www.amazon.com/Reference-Manual-Samuel-P-Harbison/dp/...

Expert C http://www.amazon.com/Expert-Programming-Peter-van-Linden/dp...

C Interfaces and Implementations http://www.amazon.com/Interfaces-Implementations-Techniques-...

C Traps and Pitfalls http://www.amazon.com/C-Traps-Pitfalls-Andrew-Koenig/dp/0201...

defen · 2010-11-05 · Original thread
C Interfaces and Implementations is really good: http://www.amazon.com/Interfaces-Implementations-Techniques-...
kqr2 · 2010-09-11 · Original thread
I would recommend David R. Hanson's book C Interfaces and Implementations. It is an extremely well documented library and shows you how to design APIs properly.

http://www.amazon.com/Interfaces-Implementations-Techniques-...

Fresh book recommendations delivered straight to your inbox every Thursday.