2 ms·
That's a good commentary. As for Nim, do we really need another unsafe language with a part-time GC? If you can tolerate a GC, there are a lot of good languag
by Animats 12y ago
That's a good commentary. As for Nim, do we really need another unsafe language with a part-time GC? If you can tolerate a GC, there are a lot of good language options.
I have some issues with Rust's verbosity, especially in the error handling area. I recently bugged the Rust crowd into changing their overly complicated replacement for C's "argc/argv" approach to command line parameters.[1] They listened. The Rust crowd is trying hard in a difficult area and succeeding.
In C and C++, lifetimes and mutability are in your face from the start. It's just that the compiler doesn't help you with them. For years, I've been saying that the three big problems with C/C++ are "How big is it? Who owns it? Who locks it?". C gives no help with any of those. C++ addresses "how big", but it's not airtight, and C++14 tries to address "Who owns it", but only for new code, and it's not airtight. Rust aggressively deals with all three problems.
I can understand the unhappiness with Rust, though. It's not a comfortable language for many modern programmers, especially ones who've never done any constrained form of engineering. For them, I'd suggest Go and Python. Go can do pretty much anything you need to do on a web server, and fast. That's why Google created it. So can Python, but more slowly. Both are memory safe (well, Go isn't in multi thread mode.)
Understanding the Rust mindset can be hard. That's a documentation problem. The "Rust for Dummies" book has not yet been written. The Rust tutorial glosses over the hard issues, and the Rust reference is written for people who are into language design, compiler design, and theory. Until recently the language design had so much churn that most of the Rust material on the web is out of date. In another year, there will probably be a decent Rust book.
With Rust, you need a plan for who's going to own what before you start. Then you just have to explain that plan to the borrow checker. For a complex, mutable data structure, such as a DOM or a GUI's collection of interconnected widgets, this may take design work and design documents. If you plow ahead without thinking through who owns what, including in the error cases, you'll get Rust compile time errors. You would have hit trouble in C or C++ too, but it would have been in the form of a memory leak, crash, or security hole. Now you have to fix it up front.
There are performance wins in this. Someone recently commented on HN that they'd discovered that typing into a dialog box produced some insane number (thousands) of allocation events per keystroke. That was partly because, at many places in the C++ code, a c_str was being copied into a fresh String object. That's a consequence of being afraid to borrow a reference to a string you don't own, for fear of creating a bug. It's safer to make a copy. In Rust, the compiler will tell you if you can do that safely. If you need to make a copy, you can, but if you just take a reference and Rust allows it, the code is good. Big step forward.
[1] https://github.com/rust-lang/rust/pull/21787#issuecomment-73161760 https://github.com/rust-lang/rust/pull/21787#issuecomment-73...
- steveklabnik 12y ago> The Rust tutorial glosses over the hard issues, I'm not disagreeing, this is more of a survey kind of question, but which issues are the hard ones, to you?
- Animats 12y agoIt doesn't go into how structures and ownership interact. It's possible to create a tree with all elements single-ownership. The relationship between structs, enums with data, recursive enums with data, and ownership isn't discussed. Yet this is fundamental to doing any complex data structure.
- steveklabnik 12y agoAwesome, thanks. I should be addressing that in the future.