C further
Let’s go straight to the point: I’m an old school IT engineer.
I’m am very fond of C. The C programming language is imperative, and only imperative (only one paradigm, no class of objects, no inheritance, no templates, no generic programming), so it is simple and easy to learn.
It is nevertheless a modern1 and evolving language2. The language is small and simple, so the programmer can focus on what is to be done rather than on how to do it (what you C is what you get).
The specifications3 are short (168 pages for the core language) and easy to understand, they stick to sounded principles4, and common compilers (clang and gcc to name a few) propose a bunch of extensions (see here or there).
And the C language comes with thousands of libraries of course.
Hereafter are few tools and few implementations of famous algorithms of my own written in C.
Everything is on Github.
This is the common pattern of asynchronous programming ported to C language for parallel programming.
This comprehensive C standard implementation of thread pool goes beyond the classical API “create, add tasks, wait, destroy”:
This is another common pattern of asynchronous programming ported to C language for synchronisation of threads.
This module implements the communicating sequential processes model first described by from Tony Hoare’s in 1978 and that can also be found in Go or Rust to name a few: several threads communicate and synchronise by exchanging messages of any type.
The interface is easy to use: open the channel between threads, send messages on one side, wait for and receive messages on the other side, close the channel.
Messages sent in the channel are strongly typed with some kind of templates (from an idea of Randy Gaul).
The C standard time handling API (time.h) is very low level and difficult to understand and to use. The object struct tm
follows unusual and subtle conventions, is counter-intuitive and needs translation to concepts as simple as days, months and years to name a few. The use of functions such as mktime
, localtime
is not straight forward.
Nevertheless, it gets everything needed to handle UTC, local time (as chosen by the user) and other time zones properly, and to alternate between those referentials (actually and fortunately, Berkerley in BSD, and later GNU in glibc, added an extra (but unfinished and useless), field tm_zone
to struct tm
that can be hijacked to handled every timezone.)
better_times allows to manage UTC, local time and time zones conveniently in C, with a correct handling of daylight saving time. It offers a complete set of functions for definition and calculation on date and time, based on the usual structure struct tm
of <time.h>
.
POSIX defines timers with timer_create
and timer_settime
.
The C standard defines timers with timerfd_create
and timerfd_settime
.
timer.h is a simpler user-interface that permits to define timers within a single process (but possibly several threads).
This is a never-seen-before implementation of a map library that can manage maps, sets, ordered and unordered lists :
Generic programming is a great paradigm that is not limited to object oriented languages.
Functional languages make use of them as well.
And Randy Gaul has shown can this can be applied to C.
I turned his ideas into template containers for C.
This is therefore another implementation of containers with is strongly typed, in C.
trace permits to log all calls to a function without changing the code.
log4t is a korn-shell script that catches the standard input, standard output and standard error of a process and log them to files, augmented with timestamp, without changing the code of the process and without recompiling. Worth to be seen.
This small script converts a C header file (from the standard input stream) into a markdown file (to the standard output stream).
For instance, README_map.md was generated from map.h. This guarantees that documentation is in line with the code.
The game of unlimited life : let cells evolve in an (almost) infinite space for an (almost) infinite time.
The code implements in C language the Hash-life algorithm proposed by R. Gosper in 1984 to explore the evolution of the Conway’s Game Of Life. With a user-friendly programming interface.
Make the famous Aho Corasick algorithm easy to use for C.
It faithfully and accurately sticks, step by step, to the pseudo-code given in the original (and exquisite) paper of 1975 from Aho and Corasick: “Efficient string matching: An aid to bibliographic search”
But this implementation comes with few enhancements:
char
) ;Make the famous Knuth’s Dancing links algorithm easy to use for C.
Can be used to solve Sudoku grids for instance.
The spirit of C (Rationale for International Standard) brings several advantages :
malloc
is not dangerous when you write free
at the same time ; when there is a leak, you know it’s you, and you know you can fix it).That is why C is a great language.
Korn-shell is similar to bash (as a predecessor) but it is much faster even though bash brings facilities for interactive shell, as well as more advanced co-processes exchanging messages.
Korn-shell is powerful and its awkward syntax is so funny !
You can read “Learning the Korn Shell” (Bill Rosenblatt, 1993) for a clear introduction.
I’ve read a few IT books. Not that much.
Considering new languages, those struggling to reach the top of the TIOBE-index, every thing is on the web rather than in books.
Therefore, I’m more into books that focus on concepts that technical aspects:
I started to learn object-oriented programming with an early version of C++ Annotations by Frank B. Brokken. It is clear and focuses on concepts rather than recipes.
Smalltalk is a purely object-oriented conceptual language. Pharo is a good implementation of a variant of Smalltalk.
SML and Haskell are purely functional languages. So they are great to learn the concepts (a.k.a “everything is recursive”) of functional programming without the burden of more general languages.
https://learnyouahaskell.com is a good resource to get started.
The book “Modern C++ Design: Generic Programming and Design Patterns Applied” by Alexandrescu, Andrei, 2001 is a very good introduction to generic programming.
Haskell also permits generic programming.
The book “Programming with POSIX Threads” by Butenhof, David R., 1997, explains clearly the concepts and patterns of asynchronous programming with threads.
Multithreading is now integrated in the C standard, as a subset of the POSIX threads.
Thanks for reading !
frr