Obsolete
/
libipc-old
Archived
3
0
Fork 0
This repository has been archived on 2024-06-18. You can view files and clone it, but cannot push or open issues/pull-requests.
libipc-old/zig-impl
Philippe Pittoli 368513bca5 Crystal bindings are in good shape. 2023-01-21 05:52:18 +01:00
..
apps Naming consistency fixed (MESSAGE_TX and MESSAGE_RX). 2023-01-20 23:12:04 +01:00
crystal/some-crystal-app Crystal bindings are in good shape. 2023-01-21 05:52:18 +01:00
drop Minor fix for the drop/Makefile (two '-o' options). 2023-01-17 04:42:05 +01:00
misc Code example for iterating on directory entries. 2023-01-18 13:59:11 +01:00
other Add several example programs. 2023-01-20 04:04:12 +01:00
src Naming consistency fixed (MESSAGE_TX and MESSAGE_RX). 2023-01-20 23:12:04 +01:00
test-bindings Bindings: update API (following previous naming consistency changes). 2023-01-20 23:14:02 +01:00
.gitignore Add a few entries in .gitignore. 2023-01-18 14:02:11 +01:00
README.md
TODO.md TODO: build.zig now creates binaries. 2023-01-20 23:11:28 +01:00
build.zig Use build.zig instead of the makefile to build binaries. 2023-01-20 02:02:47 +01:00
libipc.h Naming consistency fixed (MESSAGE_TX and MESSAGE_RX). 2023-01-20 23:12:04 +01:00
makefile Use build.zig instead of the makefile to build binaries. 2023-01-20 02:02:47 +01:00
makefile.user makefile.user: simpler, build.zig handles many operations now. 2023-01-20 03:50:47 +01:00
next-video.md Next video: orelse + some possible error improvements. 2023-01-11 16:05:39 +01:00

README.md

Why rewrite in Zig

I did a library called libipc then I wanted to rewrite it in Zig.

The problems with the C-based version:

  • libipc cannot easily be ported on other plateforms
    • cannot compile under musl
    • cannot compile for any OS
    • different libc = different error codes for functions
  • cannot change the code easily without risking to break stuff
  • behavior isn't the same accross OSs
    • glibc-based and musl-based Linux have different behavior
    • Linux and OpenBSD have different behavior
  • hard to debug
    • OpenBSD has a buggy valgrind

For all these reasons, this library took a lot of time to dev (~ 2 months), and I'm still not entirely confident in its reliability. Tests are required to gain confidence. The mere compilation isn't a proof of anything. And the code size (2kloc) for something that simple can be seen as a mess, despite being rather fair.

What Zig brings to the table:

  • OS and libc-agnostic, all quirks are handled in the std lib by the Zig dev team
  • same source code for all OSs
  • can compile from and to any OS and libc
  • errors already are verified in the std lib
  • compiling foo() catch |e| switch(e) {} shows all possible errors
  • std lib provides
    • basic structures and functions, no need to add deps or write functions to have simple lists and such
    • memory allocators & checks, no need for valgrind and other memory checking tools
    • basic network structures (address & stuff)
  • structures can be printed
  • code and tests in the same file
  • (in a near future) async functions, to handle networking operations in a very elegant manner

All these features provide a massive gain of time.

And in general, just having the same standard library for all OSs is great just not to have to rely on different implementations and even locations of code and header files.

What isn't that great with Zig:

  • structures can be printed, but they also provide the format themselves, leading to an unreliable way of discovering structure's content.