4 ms·
It's the ihih guy! Thanks for being one of the few C bloggers out there.
by suprjami 2y ago
It's the ihih guy! Thanks for being one of the few C bloggers out there.
- brabel 2y agoI enjoy reading posts about C just to see how much boilerplate and footguns higher languages let you avoid. I would like to write C, but I just have no trust I would remember or even know how to do things right (use `calloc` vs `malloc`, free the table when allocation of `entries` fails etc).
- 082349872349872 2y agoThe thing about boilerplate is that you were always rewriting it, so avoiding the footguns became habit. (So ... which takes longer, writing the data structure you want, as we all did then, or searching for the perfect library, as some people do now?) EDIT: awk(1) had built-in hash tables, and dates from 1977. Note that generic hashing becomes much more useful after D-space gets larger than 16-64k! (14-16 bits of address)
- mauvehaus 2y agoCounterpoint: when you're writing C, you end up only implementing as much complexity as you actually need. I rolled a hash table for a project that only need to contain integer keys and (I think) string values. It didn't need to carry around all the complexity to handle hashing arbitrary structured data for keys, etc. Multi-threading was supported but a simple lock over the whole table was sufficient for correctness and met the required performance. The whole thing was perhaps 200 lines of straightforward code. If you don't need to carry around support for all the third-prime-numbered-Tuesday-of-the-month scenarios that general purpose libraries have to, you end up with code you can understand fully and don't have to spend time reasoning about complexity that doesn't exist.
- Horffupolde 2y agoUntil it does and you do and you don’t.
- suprjami 2y agoI find that stuff enjoyable. I almost never use malloc, I learnt to use calloc so it's my go-to allocator. Whenever I write an allocation I try to write a free after it, then fill in the code in between. Use of static analysers and sanitisers helps too. Like some people enjoy making all their hand tools from scratch in their workshop, there's a craft and discipline to follow and a satisfaction in doing things well, I enjoy the craft of and discipline C for the same reason.
- rlinge 2y agoI started to make some new toys in C too: https://github.com/webd90kb/webd/tree/master/codes/c_project_template https://github.com/webd90kb/webd/tree/master/codes/c_project... https://github.com/webd90kb/webd/tree/master/codes/scripts/embed_file_c https://github.com/webd90kb/webd/tree/master/codes/scripts/e...