3 ms·
I hope this isn't too much of a tangent given the article's subject is details and specifics. I adore Rust for it's unique combination of features: - Can write
by the__alchemist 6y ago
I hope this isn't too much of a tangent given the article's subject is details and specifics. I adore Rust for it's unique combination of features:
- Can write fast, and systems-level code; something typically dominated by C/++
- Makes standalone executables
- Modern, high-level language features
- Best-in-class tooling and docs (As the article points out)
I'm not familiar with another language that can do these together. It's easy to pidgeonhole Rust as a "safe" language, but I adore it on a holistic level. I've found Rust's consolidated, official tooling makes the experience approachable for new people.
- nicoburns 6y agoIt's the modern high-level language features that get me. Despite Rust technically being a lower-level language, they are so well implemented that I often find Rust more enjoyable to code something in than other supposedly friendlier languages. The killer is the compile times. If Rust had Go-like compile times it would be almost perfect.
- est31 6y agoYou get accustomed to the slow compile times of Rust over time. Then you do some Go stuff and get extremely surprised by how quick it is, almost as if Go's cheating. But it's just rustc being slow :).
- drran 6y agoRust is high-level language. You mean "a language which allows low level access to hardware". Right?
- the__alchemist 6y ago"high level" and "low level" have somewhat fluid meanings, and in the case of Rust, aren't ideal for describing the language on the whole. Eg: You can do "low level" things like read a MCU register using a raw pointer. You can take advantage of "high level" abstractions like Result types.
- drran 6y agoHigh level language is platform independent. Low level stuff can be done from almost any language. I used peek and poke in Basic to access hardware registers 30 years ago.
- ncmncm 6y agoThe expressions "high-level" and "low-level" are almost meaningless in this context. Rust, like C++, has a broad range. In any big system, almost all of the code will be doing high-level-ish things no different than you would do in a Python program. At unpredictable points it will need to dip into low-level-ish activities, where it might end up spending the most runtime. If you were writing Python, you might call out to a C or C++ module, then. It is this broad range that defines a modern systems language. It has organizational features that make a big system manageable, and features to get full value from hardware. People used to try to use C as a systems language, with well-known failings.
- onei 6y ago> Modern, high-level language features I think this is something the article overlooked. Sure, Rust has the ability to be a system level language, but you don't have to use it that way and the breadth of good, albeit commonly immature, libraries is testament to this. Rust enums and pattern matching are some of my favourite features in any language. Python is often my go to for writing tools, but I mistrust its typing and how it behaves when a library throws an exception - not forgetting that pylint warns if you try to catch Exception. Conversely, Rust error handling feels a bit more verbose, but I worry less about what it does in failure scenarios. I either handle the error or pass it up the stack and carry on with my day.
- deleted 6y ago[deleted]
- saghm 6y ago> Conversely, Rust error handling feels a bit more verbose, but I worry less about what it does in failure scenarios If you're just writing a tool, you can have main return a Result with Box<dyn Error> and then just use `?` everywhere. The code doesn't really end up that much more verbose other than needing to add a return type everywhere, which can be mitigated with a type alias if needed.
- onei 6y agoThat's a good approach if you don't care about the nature of error and plan on logging it or outputting it as is, but you lose any metadata for the error unless you want to use unsafe to get it back out. What I order to do is use pattern matching for control flow in error handling, e.g. was this a server error or was I given something invalid? Depending on the error, I might want to try again. With Python, you can create a rich hierarchy of errors using inheritance, but to achieve something similar in Rust the best option I've come up with is maintaining an enum that wraps the different error types. It feels clunky, so I hope there's better ways.
- saghm 6y agoIf you're interested in generating a lot of the boilerplate for an error enum, I'd highly recommend `thiserror` (https://crates.io/crates/thiserror https://crates.io/crates/thiserror). It's made by the same person who made a lot of the other prominent proc macros libraries in the Rust community (e.g. serde).