Oddbean new post about | logout
 For when yall give up and realize C is the proper language to build in. 

https://www.vaughnnugent.com/resources/software/modules/noscrypt

nostr:nevent1qvzqqqqqqypzpckv7l8jqspl8u4y54dn9rcduwlrs4v2040nxce0m2h0cunvrj8tqqsf8k2tmhsdyvp7v67y8a6k426kuyqn5sf690j4ujf58r30vyx3emqaea7gy 
 i wish i could spend 5 minutes walking you through the secp256k1 library used in bitcoin core and point out to you how many ways it is both excessively verbose, and confusing to follow, and then show you how people trained in using this language made the abomination called btcec, which is 1/10th as performant, as a result of their excessive verbosity and lack of brain 
 Okay, I will admit I'm not the most satisfied with libsecp256k1. BUT don't let that reflect on classic GNU software, despite my also not following GNU/FSF development best practices XD 
 yeah... also, just to point out, we have AVX registers now... 20 years after the transmeta multiple parallel instruction design, finally it made it into a mainstream CPU 
 Why not upgrade to Zig? 
 But why?

It works and I have control over my CPU instructions if I want it :),  because it's worked for 40+ years in the same way over and over again, and is available on every machine and developer and ABI layers, the same way it's always done. You can save your breath on zig I'm very aware of it's capabilities and I'm not against it, right tool for the right job, but for the reasons stated above, I think C is the largest hammer in the tool belt and should continue to be used when necessary. 
 
 zig is also not better than Go, neither is V

i looked at both and they both go off on the stupid rust tangent 
 Eh, not really. It was designed to be easily compatible with C and not have to deal with the frustrations imposed on you by Rust. 
 C would be an okay language if not for the abomination that are 0-terminated strings and the str* and sprintf families of standard C functions, it's completely unsuitable for string processing 
 Yeah, I simply avoid them. I used macros and tiny structs to track length. In noscrypt I replicated C# spans with inline functions and small structs, the same way literally every other language does because most of them are written in C anyway lol. 

To be fair though, if people didn't keep ignoring the language requirements, ub, and ignoring compiler manuals, storing the termination with 0 at the end of a buffer is arguably the most efficient way to handle that. Strings are just a sequence of memory, and literals are stored in data segments. Most efficient way to handle that imo. 

https://git.vaughnnugent.com/cgit/vnuge/noscrypt/.git/tree/src/nc-util.h#n96 
 > I used macros and tiny structs to track length. In noscrypt I replicated C# spans with inline functions and small structs, the same way literally every other language does because most of them are written in C anyway lol. 

the way you say that, C is mostly a language for people with too much time on their hands 😀 it's great if things like that just work with the standard types provided by the compiler/standard library, believe me, after 30 years of coding it doesn't sound like fun anymore to roll it yourself

> storing the termination with 0 at the end of a buffer is arguably the most efficient way to handle that

nah, PASCAL strings (storing the length explicitly) are slightly more efficient in most cases, as there's no need to iterate over the string again and again to get the length.

But their biggest problem isn't efficiency, it's that a character (\0) is special-cased. This can often be exploited in various ways in protocol handling.

(i say this as someone that has found tons of remote exploitable bugs in C code, including libminiupnp 😱 ) 
 length prefixes is how i do all of my string and other array encoding in my binary data protocols

Wurth was right about this, and notably, pretty sure that if you asked Thompson he would say that null termination was a false economy 
 C is punk rock! 
 Fuck it all.

#Binary