3 ms·
I'll restate my point: sometimes when replacing C people want something that's just as fast but also way more safe, and in that case will usually reach out for
by Zababa 5y ago
I'll restate my point: sometimes when replacing C people want something that's just as fast but also way more safe, and in that case will usually reach out for Rust. That's what the people doing the cryptography in Python did. Rust can also expose a C ABI, you can write code as fast as C. People will often choose Rust instead of Zig because Rust has stronger guarantees about memory safety, and these guarantees are more important for them than having a language that's small and fits in your head.
This is why I think talking about what you're trying to achieve is more fruitful than just talking about the language you want to replace. For example, if you want to replace C code and you don't need all of the performance in the world, you couold simply switch to a garbage collected language. In that case, since speed wasn't the most important requirement, a language that isn't usually thought as a C replacement can replace C code.
If you want to make the point that Zig is "closer to C" compared to other language that wants to replace C, that's a fair claim to make.
- xhealthgothx 5y agoRust is also not 'small and fits in your head', so that's yet another point it is missing in your initial set of criteria. Its main implementation and library also emits rather large binaries in the usual case. You may not find this important, but others do.
- Zababa 5y agoI addressed that point: > People will often choose Rust instead of Zig because Rust has stronger guarantees about memory safety, and these guarantees are more important for them than having a language that's small and fits in your head. For some people, having a language that's small and fits in your head is not a requirement, not a priority, and sometimes not even important.
- nicoburns 5y agoAs others have pointed out, neither is C if you take into account avoiding UB, the preprocessor, the build systems, the many stdlib functions you need to avoid, etc. You might already know how these work, but that doesn't mean there's less to learn than a language like Rust.
- tialaramex 5y ago> This is why I think talking about what you're trying to achieve is more fruitful than just talking about the language you want to replace This is definitely the right approach in my opinion. Even for your garbage collection example on the one hand, in some cases your program is dominated by tricky reclamation problems and the "correct" Rust program is basically 90% garbage collector, so that an existing GC language might produce faster programs; but on the far opposite scale maybe your program has tricky non-memory resource problems and GC doesn't help at all, so the GC language has worse performance and yet it makes your problem harder to solve than in Rust anyway. One of the nice things about Rust and about C++ RAII here is that you don't care whether the resources are memory. Database handles? Aerial drones? A tape robot? These are all just resources you can wrap in an object to manage them, in both languages. "I only have 15MB of RAM" and "I only have 4 fire-fighting robots" are the same kind of problem from this perspective. > If you want to make the point that Zig is "closer to C" compared to other language that wants to replace C, that's a fair claim to make. This is really important. Zig is very much inspired by C. Rust has the syntax of a semi-colon language like C, but its inspirations come from all over the shop. I came to Rust having already programmed not only C and Java (and a little C++) but also Python and ML (and a little Prolog) and so this was less disconcerting. But I can see if you've literally never encountered a functional language some of Rust is weird because even though it is spelled like semi-colon languages you know it behaves very differently. I like Rust, much more than I liked Go or Python when I picked those up. It feels less clunky. An elegant weapon, for a more civilised age.
- Zababa 5y agoFor the comparaison between C, Zig and Rust syntax, I'm honestly not that sure. People love to complain about Rust's syntax for reasons I don't really understand. Sure the turbofish is a bit weird the first time, but other than that I don't find it especially difficult. On the other hand, I still have a hard time understanding Zig code. Probably because I never really played with it, but it's just like Rust, you need to familiarize yourself a bit. Maybe people that did only C are able to get up to speed with Zig more quickly than Rust? But that seems a bit superficial, if these people are already spending most of their time with only one language, if they learn a second to spend that much time with a few hours to get up to speed with the syntax is nothing.
- Gibbon1 5y agoI feel that people aren't using C because it's fast as much as it's not dog slow. And that it has a stable ABI and a very small footprint.