I recently got one of the new MacBook Air laptops, with the M4 ARM CPU, mainly for music production.
Once I had my hands on it though, I could not resist and I started installing a bit of my usual programming environment on it; one thing led to another, and I found myself enjoying the whole setup quite a bit.
So as usual when finding the right ergonomics, passion gets channeled through the ease of use of the tools you have in your hands, and creativity flows.
I had been working on and off for some months on the tools I use to program avr chips in nim, and I was hoping to add some code to discover serial devices automatically when programming arduino boards.
Nothing I found online was quite where I wanted, as I wished for something akin to pyserial
list_ports.comports
, which just tells you - in the usual simple and to the point python fashion - what are the serial devices connected to your computer.
So I wrote my own:
proc enumerate_serial_devices(): seq[string] =
for kind, path in walkDir("/dev/"):
if kind == pc_file and path.extract_filename.startswith("tty"):
result.add(path)
# this extracts the vid/pid from /sys/class/tty/.../device/uevent
proc get_vid_pid(dev: string): tuple[vid: uint16, pid: uint16] =
let dev_name = dev.split("/")[^1]
let tty_path = fmt"/sys/class/tty/{dev_name}/device"
let evt_path = fmt"/sys/class/tty/{dev_name}/device/uevent"
if dir_exists(tty_path) and file_exists(evt_path):
for line in evt_path.lines:
if "PRODUCT=" in line:
let meta = line.split("PRODUCT=")[^1]
let ids = meta.split("/")
return (ids[0].parse_hex_int.uint16, ids[1].parse_hex_nt.uint16)
(0'u16, 0'u16)
- You can find the complete code @github.com/Abathargh/avrmn.
Everything was fine, as usual nim is very expressive and manages to embody python's simplicity.
But now to the issue: /sys
is a linux feature, and other systems (even UNIX-like ones, like MacOSX) do not provide it. Now, I thought:
How difficult could it be to do the same for Mac?
Turns out that it is not maybe hard, but much less straightforward and immediate.
I studied the issue for a bit, but the combination of this being a "side-problem" and the fact that no one was paying me to do something not fun, led me to something I had not done really seriously up until now: using one of the LLMs to completely generate the code for me.
Now I've been using these tools for a while, like most of us, and I mainly relegated them to a sort of glorified "google when it still was good, but on steroids", but now I wanted to have full code generation, and boy was I surprised.
I fed this problem into Claude (my go to one, I just find it generates better code for my taste and standards, with respect to its competitors), and I was really surprised by the fact that the code actually worked (with minor tweaks) for such a niche use case and programming language, on a specific platform.
These tools have been getting quite better even at less known languages, and I have been surprised recently, because they are just starting to get good for me.
Now, to the real issue at heart.. I love programming, I really do, it's not only a job for me, but some kind of artisanal thing I do with some of my time on this beautiful planet, so let me philosophize and maybe romanticize a bit: I am afraid that we may lose this kind of feeling that the joy of programming gives us by only feeding prompts to a lifeless program.
Not only that, but I fear that learning to program right now will have the double-edged sword that I observe on myself after this experience: I now have a working driver for enumerating serial devices on MacOSX and I cannot explain to you how it works, because I did not think it out myself. I know I can learn it, but why would I?
I have been a kid, a student, and a learner of (sometimes) boring things, so I know that people will take shortcuts for this kind of stuff, and not look back at how it actually is done. How do we solve this issue? I think the biggest problem of the coming years in this landscape will be an educational one.
I have no answer for now, but I for sure have hope.
Top comments (0)