Overview
| module url | N/A | ||||||||||
| git repository | https://bitbucket.org/arrizza-public/test-zig | ||||||||||
| git command | git clone git@bitbucket.org:arrizza-public/test-zig.git | ||||||||||
| verification report | https://arrizza.com/web-ver/test-zig-report.html | ||||||||||
| version info |
|
- repo status: Repo Information
- installation: Common Setup
Summary
This app is to test out the zig language. I never used it before this project and so used Gemini to help with the setup and coding.
Note that I used zig 0.15.2. Gemini got quite a few things wrong. I suspect that was because 0.15.2 was very new and because there was little zig data on the internet for it to train on.
setup:
Install zls. This is used for JetBrain's IntelliJ.
git clone https://github.com/zigtools/zls
cd zls
zig build -Doptimize=ReleaseSafe
The run ./do_install full to install zig and zlint.
Note that zig is installed at ~/bin/zig.
And that you have to add that directory to your PATH.
Most of the code is for a logger. See Python falcon-logger and Ruby falcon-logger
export PATH=$PATH:$HOME/bin/zig
Run it
Use doit
zig version
./doit
Typical output for the "prefix" mode. In this mode, each line has a 4 letter prefix to help highlight log line types.
==== zig says: hello, world!
DTS 2025/10/29 14:37:10.096
---> test highlight result=15
test line
OK test ok
ERR test err
WARN test warn
WARN test warning
BUG test bug
DBG test dbg
DBG test debug
CRIT test critical
OK test check true
ERR test check false
-- 1] test output1
-- 999] test output2 99
-- 1000] test output3 99
test num_output heading
-- 0] test num_output line1
-- 1] test num_output line2
-- 2] test num_output line3
test raw - no prefix
test hex
0 0x00: 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
16 0x10: 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
32 0x20: 20 21
EXCP sample excp: PermissionDenied
There is a "none" (no prefix) mode:
test line; no prefix
test err; no prefix
test bug; no prefix
test dbg; no prefix
1] test output1
2] test output2 99
And there is a no verbose mode. The same list of calls was used, but these were the only lines printed out:
ERR test verbose err
BUG test verbose bug
CRIT test verbose critical
ERR test verbose check false
is it good?
It's an oddball language. On the one hand it is higher level than C and in some scenarios it seemed lower level (closer to Assembly).
There was a heavy burden on the programmer (me) to know all the nuances. The zig website helped a little, Gemini helped a little, but there was a ton of trial-and-error.
next steps
- Add UT coverage. I could not get that to install/work on Ubuntu 24.04.
- Add an accurate 1-millisecond loop. This will expose any multithreaded issues/complications and any abstraction issues (if any). See C++ ms loop and Python ms loop for examples.The C++ ms loop is very accurate, down to a few hundred microseconds standard deviation on Ubuntu. An interesting next step is to try EKF (Extended Kalman Filter) for getting even better accuracy.
- Add release mode