5 ms·
>Your C code looks very unidiomatic to me, but I guess that is relatively a matter of taste (still I don't understand why would somebody use C if they don't lik
by copx 14y ago
>Your C code looks very unidiomatic to me, but I guess that is relatively a matter of taste (still I don't understand why would somebody use C if they don't like to write code in the 'classic' C style as seen in the original Unix and Plan 9 source).
Because we learned a lot about writing more robust and maintainable software since the 1970s. Also the original Unix source code was one thing more than anything: small. Really, really small. Mostly because it did not do much compared to a modern OS.
Things like encapsulation, separation of concerns, etc. only become important once the code grows to a certain size. Unfortunately some people think you need at least C++ for that, despite the fact that for example "private" member variables are way less private than incomplete C types. C is old, but that does not mean it is incompatible with modern software development approaches. Or that you have to write code as if your compiler only parsed the first few letters of an identifier. I think C's bad reputation in some circles can be explained by people only ever seeing 1970s style code.
- 2mur 14y agoDo you have any resources / books for writing modern C like this or is it all experiential from the trenches?
- wsc981 14y agoI'd say "C programming: A modern approach" (K.N. King) should be a good candidate? Personally I like the book.
- look_lookatme 14y agoI'm interested in this too.
- copx 14y ago>Do you have any resources / books for writing modern C like this No, sorry. >is it all experiential from the trenches? It's mostly about applying general principles of software construction like separation of concerns, encapsulation, robust interfaces, etc.
- cantankerous 14y agoMaybe you could provide some of your favorite resources to those things, then?
- AncientPC 14y agoThis link gets posted on HN a lot but I've found it useful: http://c.learncodethehardway.org/book/ http://c.learncodethehardway.org/book/
- nvoorhies 14y agoC 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-Creating-Reusable/dp/0201498413 http://www.amazon.com/Interfaces-Implementations-Techniques-...
- papsosouid 14y ago>Because we learned a lot about writing more robust and maintainable software since the 1970s. Plan 9 wasn't written in the 70s. OpenBSD is another example, probably a better example given that their sshd is far more important, and running on far more machines than anything you've ever written. So it seems rather disingenuous to suggest that the authors of such software are wrong for writing simple, concise, effective code instead of your bizarre vision of C.
- copper 14y ago> for example "private" member variables are way less private than incomplete C types I'd be interested in hearing why you think this is the case: pretty much any method I'd use to get past compiler-enforced barriers protecting access a private variable in C++ is still usable in C to access data hidden away by an incomplete type. What you say is valid for code that's written freshly. When you have to work with libraries whose first lines of code were written ages ago, you pretty much have no other option than to deal with toothache-inducing styles of C code.