3 ms·
Would David Hanson's book be useful for non C programming? Will it help me understand how to build reusable, language agnostic, code?
by tdrgabi 4y ago
Would 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