15 ms·
I wrote a lot of rust, but after some years it still feels unproductive. I do a lot of zig now and I am like 10 times more productive with it. I can just concen
by kuon 3y ago
I wrote a lot of rust, but after some years it still feels unproductive. I do a lot of zig now and I am like 10 times more productive with it. I can just concentrate on what I want to code and I never have to wonder what tool or what library to use.
I know rust gives memory safety and how important that is, but the ergonomic is really bad. Every time I write some rust I feel limited. I always have to search libraries and how to do things. I cannot just "type the code".
Also the type system can get out of control, it can be very hard to actually know what method you can call on a struct.
I still think rust is a great tool, and that it solves tons of problem. But I do not think it is a good general purpose language.
- synergy20 3y agonim could be another option which defaults to c backend with python syntax
- goku12 3y ago> but the ergonomic is really bad. Every time I write some rust I feel limited. > But I do not think it is a good general purpose language. Remember that this is not a sentiment that's shared by everyone. I use Rust for tasks that need anything more complicated than a shell script. Even my window manager is controlled from a Rust program. I say this as someone who has been programming in Python for nearly two decades now. At this point, I'm about as fast in Rust as I am in Python.
- lumost 3y agoI tried to get into rust for many years, I'm now in a C/CPP job (after Java/Python/Ruby and other gigs). What I've come to understand is that Rust's lifetime model is very difficult to work with whenever you have a cyclic reference. In C/CPP the same holds, but you deal with it through clever coding - or ignoring the problem and cleaning up memory later. Java, and other GC'd languages just work for these structures. While the Rust devs believe such cyclic references are rare - I think this speaks mostly to the problem domain they are focused on. Relational models are everywhere in Apps, they are often common in complex systems software like databases, and they are fairly rare in firmware/drivers/system code code. There are a few patterns for dealing with cyclic references, but they all end up requiring either unsafe or a main "owner" object which you clean up occassionally (effectively arena allocation). Having now worked in C/CPP - the idea of having unsafe blocks sprinkled around the code doesn't bother me, and many C/CPP components have some form of arena allocation built-in. I just wish Rust learning resources would be more upfront about this.
- goku12 3y ago> I just wish Rust learning resources would be more upfront about this. While beginner resources don't dwell too much upon cyclic references, they don't consider unsafe blocks as unusual. All the material I've seen say that there are certain domains where Rust's compile-time safety model simply won't work. What Rust allows you to do instead, is to limit the scope of unsafe blocks. However, the beginner material often won't give you too much details on how to analyze and decide on these compromises. Anyway, compile-time safety checks (using borrow checker) and manual safety checks (using unsafe) aren't the only way to deal with safety. Cyclic references can be dealt with runtime safety checks too - like Rc and Weak.
- mtsr 3y ago> Cyclic references can be dealt with runtime safety checks too - like Rc and Weak. Indeed. Starting out with code sprinkled with Rc, Weak, RefCell, etc is perfectly fine and performance will probably not be worse than in any other safe languages. And if you do this, Rust is pretty close to those languages in ease of use for what are otherwise complex topics in Rust. A good reference for different approaches is Learn Rust With Entirely Too Many Linked Lists https://rust-unofficial.github.io/too-many-lists/ https://rust-unofficial.github.io/too-many-lists/
- lumost 3y agoYou still need a main owner in those patterns, that owner must be part of a DAG of owners - you cannot have cyclic ownership.
- pncnmnp 3y agoAlso, take a look at GhostCell (https://plv.mpi-sws.org/rustbelt/ghostcell/ https://plv.mpi-sws.org/rustbelt/ghostcell/ and https://www.youtube.com/watch?v=jIbubw86p0M https://www.youtube.com/watch?v=jIbubw86p0M). If anyone's used this in a project or production environment, I'd love to hear your firsthand experiences and insights.
- pjmlp 3y agoExcept in those other languages the compiler types .clone() for me.
- hiAndrewQuinn 3y agoI've finally set my mind to properly learning a new language after Python, Haskell, and typescript. I'm looking into Rust especially because of how I've heard it interoperates with Python (and also because it's maybe being used in the Linux kernel? Is that correct?).
- PartiallyTyped 3y agoLinux kernel has support for rust userland drivers, and rust interops with python with pyo3.
- maccam94 3y agoNot sure what you mean by "userland" drivers here, but support for kernel modules written in rust is actively being developed. It's already being used for kernel drivers like the Asahi Linux GPU driver for M1 Macs.
- PartiallyTyped 3y agoI am referring to userspace / userland drivers. https://www.kernel.org/doc/html/v4.18/driver-api/uio-howto.html#writing-a-driver-in-userspace https://www.kernel.org/doc/html/v4.18/driver-api/uio-howto.h...
- tremon 3y agoBut you can write userspace drivers in any language, as long as that language has basic file I/O and mmap() support. There's nothing special about using Rust for userspace drivers.
- TylerE 3y agoIsn't this false? Don't certain languages basically need, say, a libc that isn't nessesarily available in kernel space?
- tinco 3y ago
- PartiallyTyped 3y agoSurprisingly, I am faster in Rust than any other language. Something about my prior experiences just made it click just the right way. I don't want to program in anything else anymore. I don't want to deal with obscure C++ error messages, C footguns and lack of ergonomics, I don't want to deal with abstraction hell of Java, or the poor person's typing that python has. I have been programming in Python for the past 6 years, I know all sorts of obscure details, and with rust, I just don't need to think about all of those issues.
- goku12 3y ago> Surprisingly, I am faster in Rust than any other language. Not really surprising, given that you have C and C++ background. That's what I was trying to highlight. Rust isn't a confusing or unproductive language as many project it to be - if you have the conceptual understanding of what happens on the hardware. Especially about stack frames and RAII. If you know those, the borrow checker complaints will immediately make sense and you will know how to resolve them. Add rust-analyzer (Rust's language server) to it, you get real-time type annotations and a way to match types correctly in the first attempt. In my experience Rust also helps structure your program correctly and saves a ton of time in debugging. All in all, Rust is a fast way to write correct programs.
- mcronce 3y agoMy background is PHP, Python, and Go, and I have the same experience as GP
- PartiallyTyped 3y agoI'd add that if you have some understanding of how memory ownership should be such that you don't end up with memory leaks, you are fine. The borrow checker just verifies that your mental model is correct, and removes some of the cognitive load from you.
- ayewo 3y ago> if you have some understanding of how memory ownership What reading materials will help me level up my understanding of this?
- pizza234 3y ago> At this point, I'm about as fast in Rust as I am in Python. This is factually impossible. For anything larger than (very) small programs, Rust requires an upfront design stage, due to ownership, that it's not required when developing in GC'ed languages. This is not even considering more local complexities, like data structures with cyclical references.
- goku12 3y ago> This is factually impossible. How do you outright deny something as subjective as my personal experience? Besides, I'm not the only one in this discussion that made the same opinion. > For anything larger than (very) small programs, Rust requires an upfront design stage, due to ownership, that it's not required when developing in GC'ed languages. While GC'ed languages allow you to skip a proper initial design stage, it's a stretch to claim that it's not required at all. In my experience using Python, while the initial stages are smooth, such design oversights come back and bite at a later stage - leading to a lot of debugging and refactoring. This is one aspect where Rust saves you time. > This is not even considering more local complexities, like data structures with cyclical references. I'm not going to dwell on cyclical references, since there's another thread that addresses it. They point out a way to make it as easy in Rust as it is in GC'ed languages. Meanwhile, the upfront architecture and data structure design isn't as complicated as you project it. Rust is mostly transparent about those - even compared Python. How well do you understand how Python manages Lists, dictionaries or even objects in general? I often find myself thinking about it a lot when programming in Python. While you need to think upfront about these in Rust, there's actually less cognitive overhead as to what is happening behind the scenes.
- Ylmaz 3y agoThis is possible if you are really slow in python
- ParetoOptimal 3y agoOr maybe they mean "fast to 1.0" rather than "fast to 0.1"? They didn't specify.
- Liskni_si 3y agoWhat window manager is that, may I ask out of curiousity?
- goku12 3y agoSway. And river, sooner or later. A single Rust program is used for setting up services (using s6-rc on Gentoo), shutdown, reboot, idle inhibit, etc.
- JohnFen 3y agoIt's interesting that you bring up Python. I find Rust unpleasant to program in -- and I also find Python unpleasant to program in. Now I'm wondering about demographics. Are people who love Python more likely to love Rust as well?
- push-f 3y ago> it can be very hard to actually know what method you can call on a struct The rust-analyzer language server can autocomplete the available methods for a value.
- earthling8118 3y agoFurthermore you can use `cargo doc` to generate a documentation website that had everything you can do or you can use docs.rs for this. Whoever wrote this didn't embrace the tooling and just gave up.
- n3storm 3y agodepending on the autocompleter feels like asking to code to Chatgpt to me.
- push-f 3y agoI disagree, there's a big difference: rust-analyzer is deterministic and 100% accurate while ChatGPT is non-deterministic and hallucinates.
- underdeserver 3y agoYep. I can't remember method names for the life of me, which is why my best experiences have been with Go and Java: The IDE (always Jetbrains) knows, via the type system, what methods I can call.
- avgcorrection 3y agoThen you underestimate the power of ChatGPT by a facor of a million.
- anon-3988 3y agoI am curious what kind of code you are writing? Is it very low level or very high? >I know rust gives memory safety and how important that is, but the ergonomic is really bad. Every time I write some rust I feel limited. I always have to search libraries and how to do things. I cannot just "type the code". You don't have to search libraries and figure out how to do things in Zig?
- dharmab 3y agoIt's hard to describe, but in some languages, you spend a lot less time looking at reference docs and more time just naturally writing the solution. Lisp is a great example of that, if you get through the learning curve.
- Buttons840 3y agoI suspect Zig libraries feel easier because they're doing easier things. I bet if you try to draw a triangle with the Vulkan API in Zig, you'll find yourself looking at the reference docs a lot.
- kuon 3y agoMost of the time I can use my "general computer science baggage" to write the solution. At present, I do embedded and web business logic (wasm) where the UI is rendered by preact. For those two projects zig is working very well.
- darthrupert 3y agoYou should try diving into num for like a month and see how you like it. It's different enough that you need to go past a certain kind of ledge to start liking it. Or at least that was my experience. For me, it shares the most important benefits of Rust but with quite a lot more ergonomic coding model.
- darthrupert 3y agoWoopsie. I meant s/num/nim/ of course.
- SJMG 3y agoNim on paper is great; it has many advantages over Rust in the general purpose "niche". Tragically, it's kind of stillborn. It's older than Rust, has orders of magnitude less mindshare, and has no companies with serious technical reputations backing it.
- darthrupert 3y agoYeah, you're not wrong about the mindshare problem. But it somehow at least in my mind differs from other "stillborn" older languages in that it keeps improving. The end result is that it still feels modern in the year 2023.
- TylerE 3y agoSo any language that isn't sponsored by Google/MS/Amazon/Mozilla from day 1 should just die?
- lifthrasiir 3y agoSince you have previously said that you are using Zig to do embedded programming for medical devices, I assume that it is your main pain point. I largely agree that the current Rust embedded story is not exactly for existing embedded programmers (and I guess you are one of them). Rather it looks more like a solution for existing application programmers. I don't think it's an intrinsic limitation of Rust the programming language, rather a specific community at this point happens to prefer this way. Still it is a weakness in some sense and Zig will be a good alternative.
- kuon 3y agoYes, I think rust is very good for higher level programmers wanting to code embedded like a regular OS. There are many great projects around using rust on embedded. But me, I prefer to manipulate registers directly. Especially with "exotic" MCU where you have to execute write/read in specific number of CPU cycles. Rust makes that very hard.
- conradev 3y agoI agree with this general feeling, and it is hard to articulate Rust forces you to figure out ahead of time where each bit or byte is going to go and on which thread and using which mutation scheme. I’m happy to play the game, but it feels tedious for anything short of a parser or a microcontroller. It messes with my process because I like to get something working before I determine the best API structure for it I can get 90% of the performance with Swift and it flows much more easily, even though Rust’s type system is more powerful.
- Ar-Curunir 3y agoI’ve written plenty of Rust code in my life (easily more than 100kLOC, and I’ve really never worried about putting which bit where. You can just clone and be on your merry way; you don’t need to worry about perf-related things if you don’t want to.
- conradev 3y agoThose two sentences feel in contradiction of one another. You don’t need worry to about where the bits go, you just need to know to call a method to move the bits? Swift makes every type implicitly copyable on the stack, including object pointers (through ARC), so you don’t have to clone. You can even pass functions as variables without any hoops. I love lots of things about Rust, though, and will continue to use it for lots of things. Cross-platform things, for one!
- pjmlp 3y agoI rather use compiled managed languages like Swift, D and C# instead, they provide enough low level coding knobs for C and C++ style coding, while being high level productive. Would add Go to the list, but only when I really have to. Nim and Crystal could be alternatives, but don't seem to have big enough communities, at least for what I do. However I do agree with the conclusion, Rust is a great language for scenarios where no form of automatic memory management is allowed, kernels, specific kinds of drivers, GPGPU programming, as general purpose, there are more productive alternatives, equally safe.
- hiAndrewQuinn 3y agoC# is underrated by the HN crowd, I find. I quite like how mid sized firms (100-1000 employees) use it.
- eddtries 3y agoI've always found those sort of firms with C#, in my experience, have the best architected code. Proper domain-driven design, onion architectures, clean testable code... Some have legacy issues where they might not have the most cutting edge CI/CD pipeline or high automated test coverage, but the code itself can be very nice. I've never really experienced that level of consistency with a different language/company size.
- tkubacki 3y agoI used to be .NET dev and don't agree. Couple of reaons: 1) Modern Java is almost as good as C# with some things I can't give up in Java (static imports => succint code, Groovy Spock => succint tests) 2) Kotlin is better than C# 3) JVM has much much bigger ecosystem (almost all the apache projects are JVM oriented) and default web framework is much less code to type (SpringBoot) is much more productiv 4) JVM has wider variety of langs For those reasons IMHO if you are small-mid company (or startup) it's wiser to choose JVM.
- hiAndrewQuinn 3y ago#1 => agree #2 => don't know enough about Kotlin to comment #3 => agree but quality > quantity #4 => not terribly important to me (Clojure is cool but it's not "switch to the JVM" level cool)
- csomar 3y agoWait, I am a bit confused. Does Zig have more/better libraries than Rust? I thought it's a pretty new language. The most limiting thing for me with Rust was the lack of libraries (vs. say Python or Node/JavaScript).
- Quekid5 3y agoIt interops seamlessly with C libraries.
- csomar 3y agoDepending on what seamlessly means, Rust can also interop with C libraries. I wrapped a bunch of them.
- hailruda 3y agoSeamlessly as in @cInclude("raylib.h")
- GuestHNUser 3y agoTruly seamless because the zig compiler is also a C compiler, so the type information and calling convention works across languages at a level above any other I've encountered.
- littlestymaar 3y agoTrue, but I think that the person you're responding argued that rust/C integration is also seamless. (In the general discussion I'd say they're right as C to Rust integration isn't much of an problem and you can use C libraries relatively easily in Rust as well, but at the same time when talking about Zig I don't think it's fair to put it on the same ground).
- Capricorn2481 3y agoIt's also an unfinished language. I agree Zig is promising, but it's not confidence inspiring when the creator is still making videos debugging the compiler.
- ostenning 3y agoOpposite experience for me. Writing Rust on embedded systems greatly improved my confidence and speed. When using C a small mistake often leads to undefined behaviour and headaches. Rust theres none of that - its been a game changer for me.
- kuon 3y agoI was using rust on embedded, I moved to zig. Very happy with it as you can pass allocators around to use fixed buffer.
- 0xfedbee 3y ago[dead]
- imtringued 3y agoWhen you are developing hardware on an FPGA, a lot of hardware bugs look like they have locked up the CPU and strangely enough, a lot of undefined behavior looks exactly like a hardware lockup...
- samus 3y agoIt somehow seems that Zig has most of the qualities that people like about C: clear, crisp, no huge Stdlib, good old straightforward imperative semantics, and readonably fast. But without lots of the cruft.
- pjmlp 3y agoUnfortunely lacks support for binary libraries, and not yet a story for UAF other than the tooling we are already using in C derived languages to track them down.
- renox 3y agoGiven that Zig is memory unsafe it isn't either a good general purpose language. IMO a good GPR is memory safe (no C, C++, Zig), is easy to use(no Rust), has strong static typing (no Perl, Python, Ruby) and is "stable" (no Scala). Lots of choices remain: Java, Kotlin, Ada, D, OCaml..
- nlnn 3y agoI use Rust a lot, and have been really keen on getting into Zig. Not sure if much has changed (it was a while back), but my biggest problem was with finding and using 3rd party libraries (mostly for the boring stuff like DB connectivity, JSON/YAML parsing, logging, etc.). E.g. even now if I search for "zig mysql library", the tops hits are all about people discussing it on reddit, than any actual library.
- kuon 3y agoYou cImport the C library most of the time.
- oneshtein 3y agoBy "wrote" you are meaning just coding or coding+debugging? Because other languages are easier to code, but hard to make error free, while Rust is hard to write but much easier to make bug free.
- cztomsik 3y agoThis. I have exactly the same experience, I can't believe how much I was able to ship with Zig and the code mostly feels like "done". You can always improve it, but there's no need to. With Rust, I was never happy, even after 5 years, I was still thinking about better abstractions and implementing more traits, making it more generic, etc.
- freilanzer 3y agoWhy is there no need to improve Zig code but there is for Rust code? You'd need the same abstractions in Zig as well, no?
- cztomsik 3y agoNo, usually you don't. Rust has closures, iterators, generics, different traits for operator overloading, smart pointers, etc. Zig doesn't have any of that. It's very interesting combination of low-level, predictable code, with meta-programming, where you get some of that abstraction back. i.e. Zig does not have generics, but your function can return type, so generic list is just a function which returns a newly created struct.
- mst 3y agoCould you expand on the generics point, please? That sounds interesting but I can't quite get my head around it.
- cztomsik 3y agoFunctions in Zig can be called both in runtime and in compile-time. You can force some expression to be called during comptime using a keyword, and sometimes the comptime is implied (like when you define top-level const) If a function is called in comptime, it can also return types. So for example: // this is a function which accepts a type // if you accept type, you also have to restrict the arg to be comptime // if the arg is comptime it still does not mean that the function cannot be called in runtime, // but in this case, it returns type, so it is comptime-only function // there are also cases where this is not true, like std.mem.eql(u8, a, b) which accepts type, // but can be called in runtime because it does not return type fn Wrapper(comptime T: type) type { return struct { value: T }; } const F32Wrapper = Wrapper(f32); // @TypeOf(x.value) == f32 var x: F32Wrapper = .{ value: 1.0 }
- ernst_klim 3y agoI agree. I feel far more productive in C and C++ than in Rust at that point. Rust feels like totally missing the sweet spot for me. It's way too pedantic about low level stuff for writing higher level applications, but way too complicated for embedded or writing an OS. In the former case I would rather take a C++, Java, Haskell, OCaml or even Go, and maybe sprinkle some C, and in the latter case C in macroassembly mode is far more suitable. I still have a feeling that original vision of Graydon Hoare (i.e. OCaml/SML with linear types, GC, stack allocations, green threads and CPS) would be a much better language.
- api 3y agoThe problem with C and to C++ is that it’s 2023 and the CVE list is still loaded with basic memory errors. These come from everywhere too: small companies and open source all the way up to Apple, Microsoft, and Google. We as a profession have proven that we can’t write unsafe code at scale and avoid these problems. You might be able to in hand whittled code you write but what happens when other people work on it, it gets refactored, someone pulls in a merge without looking too closely, etc., or even maybe you come back two years later to fix something and have forgotten the details. Having the compiler detect almost all memory errors is necessary. Either that or the language has to avoid this entirely. Rust is the former class unless you use unsafe, and the fact that it’s called “unsafe” makes it trivial to search for. You can automatically flag commits with unsafe in them for extra review or even prohibit it.
- flohofwoe 3y agoI think nobody is arguing the need for static memory safety, just that the poor Rust ergonomics aren't a good tradeoff, especially for scenarios where C is useful. We need many more Rust alternatives that explore into different directions, Rust is already too big and "established" for any radical changes in direction.
- pjmlp 3y agoOn that regard, by packaging Modula-2 into a C friendly syntax, I do agree Zig is relatively interesting option, however not having a story for binary library distribution is an hindrance in many C dominated industries.
- api 3y agoHow much of your negative Rust experience is due to async? Having used Rust for a long time it’s definitely the biggest source of confusion and headaches.
- kuon 3y agoIt is not that complicated but it is very "time consuming" for reasons I cannot really explain.
- ubermon 3y agoGive Copilot a try, it completely shift coding experience in Rust. Especially this: > I always have to search libraries and how to do things. Once you pass the initial curve with crutch like Copilot, then you can be almost as productive (if not more, considering refactoring and testing) with your native first coding language