Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This comment sums it up best:

https://news.ycombinator.com/item?id=33142349

So basically, use EITHER idiomatic C, which means long functions / few internal interfaces, reuse with ABIs not APIs, bespoke data structures, etc.

OR use C++ and ADTs (type safety, abstraction, polymorphism). Or use Rust if you don't need compatibility.

So books like CII are of very limited use, especially not for beginners. They will be fighting with the language and not understanding what it's about.

----

To sum it up, C is better for coarse-grained reuse (deep interfaces a la Ousterhout, Unix file system) than fine-grained reuse like CII (hash table, array, set)

Related long article I wrote about API (compile time) vs. ABI (protocol, runtime) and related issues: https://www.oilshell.org/blog/2022/03/backlog-arch.html

----

I'll take your point that if you want ABI stability, then hiding layout behind a pointer and not exposing structs is a good idea!

Although that pointer's type doesn't necessarily have to be void* as it is in CII -- it could just be an application-specific type

Also agree that there are several different ways of using C and C++.



Why is "idiomatic C" equivalent to "long functions and few internal interfaces"?

The whole point of having a small surface-area for your ABI with plenty of detail hiding is that you are free to do what you like beneath it. If the code uses a struct named "hash_map" that takes a generic hash function and stores void pointers, but runs fast for my purposes, what do I care? These techniques give you a controlled way to build black boxes.

C is a very flexible language, and it is possible to build up quite a variety of patterns in it. Your job as an engineer is to look in your toolbox and select the best tool for the job. Adhering to a "correct idiom" gets in the way of this.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: