Comment Re:As s human the weakness of Rust is macros (Score 1) 24
After spending several weeks using Rust, I went back to Go.
I wish Go had some of the simple ergonomics of Rust:
- - The ability to redefine a new variable with the same name as another variable that you no longer need (shadowing it). Go does not allow this: x
:= strconv.Itoa(x), but Rust allows the equivalent. - - The ? operator for propagating errors explicitly, with just one symbol, instead of adding this after every function call: if err != nil { return err }. The ? operator would be even easier to use in Go, because Go has a universally used garbage-collected error interface, while Rust does not, and needs conversions from one error type to another.
- - The ability to add methods to any class, without modifying the class or adding a wrapper class. You just define the extra methods in a package (crate, whatever), and by importing the package, you have access to these methods.
- - The Result construct is self-documenting vs a Go function that returns (T, error), where it really returns either T or an error, not both.
More positives of Rust:
- - The type system is very well thought out, for example enum, Result, Option. It codifies the programmer's intentions in code rather than using assumptions everywhere that are either documented in comments, or not at all (If the result is nil, then the error is not nil, and vice versa).
- - Macros are tedious to write, but very powerful, once you start using them.
The advantages of Go:
- - Lots of easy to use libraries, many of them in the standard library (for example net/http).
- - built-in reflection that makes it easy to use Go objects with text formats e.g. using text/template, or html/template, encoding/json, etc. Can Rust do this? Perhaps, but only if you manage to write or find complicated macros (e.g. serde) and use them for each class you want to reflect on. Last I checked, serde yaml was unmaintained, while one can find several yaml implementations for Go, none of which requires adding a macro to each class you want to marshal/unmarshal.
Problematic things in Rust
- - In order to do async I/O like networking, you have to use async methods allover the place. This was a deal-breaker for me. I painstakingly wrote macros for a command-line interface framework, but when I wanted to do some networking, I realized my command-line mechanism would not work, because it did not call methods with async.
- - Sharing data like simple strings in data structures is often difficult.