Laurent Farhi

My Favourite Things

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.

My favourite code

Hereafter are few tools and few implementations of famous algorithms of my own written in C.

Everything is on Github.

Tools

Pool of threads for parallel programming on CPU

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”:

Channels for exchanging messages between threads

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).

Dates and times without wasting time

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>.

Light C standard timers

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).

Maps, sets and lists

This is a never-seen-before implementation of a map library that can manage maps, sets, ordered and unordered lists :

Templates (maps, sets and 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.

log4t and trace

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.

h2md

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.

Algorithms

game of life

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.

Aho Corasick

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:

Make the famous Knuth’s Dancing links algorithm easy to use for C.

Can be used to solve Sudoku grids for instance.

My favourite languages

C

The spirit of C (Rationale for International Standard) brings several advantages :

That is why C is a great language.

Korn-shell

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.

My favourite resources and books

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:

OOP

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.

Functional programming

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.

Generic programming

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.

Multi-thread 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

  1. Modern C. Jens Gustedt. Manning, 2025

  2. WG14, the international working group for the programming language C

  3. ISO/IEC 9899:2024, C programming language specification and other documentation. 

  4. The C Standard charter, WG14 N3280, 2024