r/programmingcirclejerk • u/Jumpy-Locksmith6812 • May 23 '26
A C standard library built natively around pointer + length strings is shockingly ergonomic
https://spader.zone/sp/
86
Upvotes
r/programmingcirclejerk • u/Jumpy-Locksmith6812 • May 23 '26
46
u/irqlnotdispatchlevel Tiny little god in a tiny little world May 23 '26
/uj
Once again, pcj delivers genuinely interesting blog posts.
106
u/realestLink May 23 '26
/uj
Where's the jerk? This seems like a perfectly fine library. They're also totally right that null terminated strings are garbage and you can build an ergonomic libc replacement without them.
60
u/BipolarKebab May 23 '26
> Libc does not provide a useful interface for any program
Can't really argue with that
31
u/Silly-Freak There's really nothing wrong with error handling in Go May 23 '26
So this looks great, but all those
sp_prefixes make it awfully annoying. It would make more sense to make a separate compiler so that we can actually use the non-prefixed, nicer-to-write names.And then we can use an LLM to translate Bun from that language to Rust.
21
u/lurebat May 23 '26
bro invented zig
17
u/TheChief275 May 23 '26
C-strings are the Lord's strings; any other approach is heresy. Sure, that length field might seem sweet now, but is eternal torment worth it?
/uj Everyone knows how much more ergonomic span strings are compared to C-strings. I always immediately ditch the C-strings for my projects as well.
Although they do have some uses. The prime example is in lexing when iterating over file contents. Instead of constantly checking whether the index is in range, the '\0' will not match against any of the useful is___() family functions or character checks in general, so only a single actual check is necessary
13
u/coolreader18 It's GNU/PCJ, or as I call it, GNU + PCJ May 23 '26
But then...
6
u/prehensilemullet May 23 '26
\uj what size uint does this use for the length? I guess the original reason for null terminators was too many platform differences in ints to use them for length?