3 ms·
One can only learn a language one time, so I've got a hard time recommending first books. But I definitely second the recommendation for the second book here ;)
by mhd 4y ago
One can only learn a language one time, so I've got a hard time recommending first books.
But I definitely second the recommendation for the second book here ;)
Hanson's style is a bit idiosyncratic, with his somewhat Modula-3-ish naming style and literate programming use, but there are a lot of usable data structures in there, and I especially like that the focus is on the module level, not on the algorithms themselves.
Now, having said that, if you're in a particularly weird sub-domain of C, books from there might supersede or at least color a lot of what you're doing on a day to day basis. In the days of yore, if you wanted to do Win16/Win32 programming, getting to work with your Petzold early is a good idea, and I would assume the same to be true if you do glib/gobject based Gtk programming.
Two free resources that looked good to me and that I forwarded in the past were "An Introduction to the C Programming Language and Software Design"[1] by Tim Baily and "Beej's Guide to C Programming"[2]. Those are a bit more concise than your average intro to C book, but for some paths (prior experience, quick headway to C++ etc), they might be sufficient.
[1]: https://www-personal.acfr.usyd.edu.au/tbailey/ctext/ctext.pdf https://www-personal.acfr.usyd.edu.au/tbailey/ctext/ctext.pd...
[2]: https://beej.us/guide/bgc/ https://beej.us/guide/bgc/
- tdrgabi 4y agoWould David Hanson's book be useful for non C programming? Will it help me understand how to build reusable, language agnostic, code?
- mhd 4y agoI think it's a lot less useful for that. The problem is that doing that with C is that you're already strapping some lead to your feet from the very start, so a lot of what CII does is removing those weights by adding stuff from other languages, either by merit of coding style or new libraries. This would already go to far for a lot of C purists, but it doesn't totally try to work deny the language you're working in. So it does basic error handling & modularization. You get that "for free" in a lot of other languages, or sent in totally different directions anyway (good modularization in OO and/or FP looks somewhat different) Then there's a lot of practical data structures and algorithms, with good references to other versions and sources, so both something you could use immediately but also serving as jumping off points to advanced study. So I appreciate it a lot more in combination with bare bones C than with other languages or even C environments with more standard library functions. For style & technical guidelines, I think Code Complete is still a great book, or the Pragmatic Programmer. For a trad-C book, maybe even Pike's Practice of Programming. Avoid anything avuncular. Of recent years (and not including OO stuff in general), Ousterhout's "A Philosophy of Software Design" packs a lot in a few pages.
- rramadass 4y agoYes, Absolutely. However, i am not clear what you mean by "language agnostic"? Obviously Code cannot be language independent but if you can read C then you should be able to translate the data structures/algorithms given in this book to a language of your choice; the difficulty might vary (eg. how would you represent pointers in your language to implement say recursive tree structures?) but it can be done. The data structures/algorithms given in Hanson's book are "industrial strength" with no missing parts (i.e. no exercise left to the reader). So you get complete code all written in the "Literate Programming" style which takes a little getting used to but is eminently worth it.
- jart 4y agoIt is possible to write language agnostic code. Consider SectorLISP which is written in C that's also valid JavaScript See https://justine.lol/sectorlisp2/#evaluation https://justine.lol/sectorlisp2/#evaluation and https://github.com/jart/sectorlisp/blob/c9ce1c54a024ac4774a208a84c9083c3a611825d/lisp.js https://github.com/jart/sectorlisp/blob/c9ce1c54a024ac4774a2... and also https://github.com/jart/sectorlisp/blob/main/lisp.c https://github.com/jart/sectorlisp/blob/main/lisp.c
- rramadass 4y agoPretty Neat! I had come across similar techniques in Arthur Whitney's work (past HN threads). However i interpreted the original "language agnostic" question as maybe wanting to implement the C code in terms of some pseudo-code and hence my question. The phrase also seems to have another meaning: https://en.wikipedia.org/wiki/Language-agnostic https://en.wikipedia.org/wiki/Language-agnostic
- chubot 4y agoI wouldn't recommend it for that (see sibling comment). Reuse isn't as idiomatic in C as it is in other languages, for reasons inherent in the language, e.g. see all widely used C codebases