7 ms·
I wanted to like Rust (memory safety and performance - what's not to like?) but both of my experiments with it ended in frustration. It seemed a way too complex
by bornfreddy 2y ago
I wanted to like Rust (memory safety and performance - what's not to like?) but both of my experiments with it ended in frustration. It seemed a way too complex language for what I needed.
Recently, a coworker of mine made a great observation that made everything clear to me. I was looking for a replacement for C, but Rust is actually a replacement for C++. Totally different beast - powerful but complex. I need to see if Zig is any closer to C in spirit.
- fc417fc802 2y agoSomewhat related, even when I work with C++ I use it as "C with RAII". What I actually want is a scheme (R5RS) with manual memory management and a borrow checker. I don't know how well such a monstrosity would actually work in practice, but it's what I've convinced myself that I want.
- valorzard 2y agohttps://github.com/carp-lang/Carp https://github.com/carp-lang/Carp
- throwawaymaths 2y agoposted yesterday: https://news.ycombinator.com/item?id=42923829 https://news.ycombinator.com/item?id=42923829
- pcwalton 2y ago> I was looking for a replacement for C, but Rust is actually a replacement for C++. Totally different beast - powerful but complex. I've seen this sentiment a lot, and I have to say it's always puzzled me. The difference between Rust and basically any other popular language is that the former has memory safety without GC†. The difference between C++ and C is that the former is a large multi-paradigm language, while the latter is a minimalist language. These are completely different axes. There is no corresponding popular replacement for C that's more minimalist than Rust and memory safe. † Reference counting is a form of garbage collection.
- zamalek 2y ago> † Reference counting is a form of garbage collection. I agree with Raymond Chen's take on the academic definition of GCs[1], and therefore Rust is certainly a GC'd language (because your code behaves as though memory is infinite... usually). It's probably one of the first examples of "static garbage collection" - though I'm sure someone will point out a prior example. [1]: https://devblogs.microsoft.com/oldnewthing/20100809-00/?p=13203 https://devblogs.microsoft.com/oldnewthing/20100809-00/?p=13...
- jonahx 2y agoThis feels like deliberate misdirection, because in most practical cases what people mean is "some memory management process that will slow my program down non-trivially". By this definition Rust does not have GC whereas Go, eg, does. The "simulates infinite RAM" is an interesting perspective but simply not the subject of most conversations.
- zozbot234 2y agoManual heap allocation can slow the program down non-trivially compared to using an arena which is cleaned up all at once; hence, manual heap allocation is a kind of GC. Checkmate atheists.
- caspper69 2y agoI went down a path researching the viability of region based memory management (a form of arenas). A language based on such a paradigm can be provably memory safe, and regions can have their own allocators and optionally provide locking when the regions are shared. This approach obviates the need for reference counting individual allocations (since regions are tracked as a whole), but it suffers from excess memory usage in the event of many short-lived allocations (i.e. they leak until the entire region's allocations go out of scope). But those types of memory accesses can be problematic in every systems language as they can eventually cause memory fragmentation. That problem can be minimized using per-allocation reference counting, but that can incur a heavy performance hit. Although not having to use it everywhere could minimize the impact. The plus side is you don't have to worry about borrow checking, so such a language can be more flexible than Rust, while still maintaining the memory safety aspect. The question, as always, is: is the juice worth the squeeze? Truthfully, I suspect no. The Rust train has left the station and has a decade head start. Even if it is a pain in the ass, lol.
- huijzer 2y agoI read a blog that called Rust a language that was aimed to be high-level but without GC.
- anacrolix 2y agoThis is actually accurate. While Rust is a great replacement for C, so is C++. But Rust has tons of extra features that C doesn't have, just like C++. Moving from C++ to Rust is a sideways move. Moving from C to Rust is definitely an increase in complexity and abstraction. Rust is a great replacement for C++ as it fits into the same place in the stack of tools. Go is not a C or Python replacement. Zig is a good replacement for C.
- zozbot234 2y ago> But Rust has tons of extra features that C doesn't have, just like C++. C++ has tons of extra features over C because it's a kitchen sink language. Rust has some extra features over C because in order to support static analysis for memory safety in a practically usable manner, you need those features. In practice, there are lots of C++ features that Rust doesn't bother with, especially around templates. (Rust just has a more general macro feature instead. The C++ folks are now on track to adding a clunky "metaclass" feature which is a lot like Rust macros.)
- pjmlp 2y agoEvery language becomes a kitchen sink with enough time on the market, even C, people really should learn about the standard and the myriad of compiler extensions, K&R C was almost 60 years ago. C++ already has almost Rust macros, with a mix of compile time execution, concepts and traits, without requiring another mini-language, or an external crate (syn).
- bmacho 2y ago> Every language becomes a kitchen sink with enough time on the market, Sometimes they remove stuff, and then everything written before a specific date stop working.
- anacrolix 2y agoI've used Rust quite a bit now and there are too many features. It can't claim to be tidy anymore. Sure it's a better situation than C++, but it is getting worse and unlikely to get better.
- superlopuh 2y agoMy experience with Zig is that it's also a plausible replacement for C++
- fuzztester 2y agoexplanation needed, bro. nerdy langnoob or noobie langnerd here. not sure which is which, cuz my parsing skills are nearly zilch. ;)
- infamouscow 2y agoC programmers have long suffered the cumbersome ritual of struct manipulation—resorting to C++ merely to dress up structs as classes. Zig shatters that with comptime and the 'type' type.
- chongli 2y agoZig’s comptime feature gives a lot of the power of C++ templates. This makes it easier to implement a lot of libraries which are just a pain to do in plain C. Even seemingly simple things like a generic vector are annoying to do in C, unless you abandon type safety and just start passing pointers to void. I believe Zig even has some libraries for doing more exotic things easily, such as converting between an array of structs and a struct of arrays (and back).
- fuzztester 2y ago>Zig’s comptime feature gives a lot of the power of C++ templates. This makes it easier to implement a lot of libraries which are just a pain to do in plain C. Even seemingly simple things like a generic vector are annoying to do in C, unless you abandon type safety and just start passing pointers to void. I get it, thanks. in C you have to cast everything to (void *) to do things like a generic vector. >I believe Zig even has some libraries for doing more exotic things easily, such as converting between an array of structs and a struct of arrays (and back). yes, iirc, there was a zig thread about this on hn recently.
- pjmlp 2y ago
- FpUser 2y ago>"but Rust is actually a replacement for C++. " I would disagree. C++ provides way more features than Rust and to me Rust feels way more constrained comparatively.
- tialaramex 2y agoSure, in the sense that in C++ they've got the Head Of Vecna: https://rpgmuseum.fandom.com/wiki/The_Head_of_Vecna https://rpgmuseum.fandom.com/wiki/The_Head_of_Vecna Many of my favourite Rust features aren't in C++. For example they don't have real Sum types, they don't have the correct move semantic, they are statement oriented rather than expression oriented and their language lacks decent built-in tooling. But also, some of the things C++ does have are just bad and won't get fixed/ removed because they're popular. And there's no sign of it slowing down. I think that in practice you should use Rust in most places that C++ is used today, while some of the remainder should be WUFFS, or something entirely different.
- FpUser 2y ago>"I think that in practice you should use Rust" I am doing fine. Thank you. Also I am not a language warrior. I do have my preferences but use many since I am an independent and work with many clients.
- pjmlp 2y agoThe biggest issue for me, is that Rust isn't used where I care about, mainstream language runtimes, compiler toolchains, and GPU ecosystem standards. No one from them would accept a patch in Rust instead of C or C++. Yes I know about Deno, but even them haven't rewriten V8, and wgpu or Rust CUDA aren't the same as what Khronos, NVidia, AMD, Microsoft put out in C++.
- krona 2y ago> Rust is actually a replacement for C++ Last I checked, rust touted itself as a systems programming language, which C++ kinda is but mostly isn't (many C++ features just aren't appropriate or are poorly suited for systems programming). I would never choose Rust over C++ for scientific programming, because Rust metaprogramming features are so poor. However I'd probably choose Rust over C in many areas where C is best suited. So to me the venn diagram of utility shows Rust to overlap with C far more than C++.