On Sat, 2020-10-03 at 00:51 +0200, timur.kris...@gmail.com wrote: > The Rust syntax is slightly annoying. They departed from C/C++ enough > to make Rust look different, but then they got lazy and for some reason > they chose to keep the most annoying parts from C/C++ like curly braces > and semicolons, so even if we switch to Rust we can still enjoy > debating important topics like where to put curly braces, how many > spaces or tabs are best, and so on.
Unlike C++ though, Rust have reason for semicolons. In Rust you can write a subexpression, whose result gets assigned to a variable, and you "return" this result from the subexpression by omitting semicolon. In C++ you have to use a lambda for that. Talking of syntax, it may not be ideal, but since you compare it to C++, Rust syntax is better. Off the top of my head: 1. No "const" modifiers, everything is immutable by default, which is how modern language should look like (because really, most of the things you work with in a function are either never modified (e.g. some arguments) or only upon creation — i.e. basically never too) 2. No braces in if-conditions. So you have one less pair of braces to eyeball while reading complex `if ((foo()+x) && (bar()) || buzz())` statements. 3. Lambda syntax is less to write and to read: less brackets/braces. 4. Way better syntax for Algebraic Data Types. E.g. in C++ you might have a `std::variant<Foo, Bar, Buzz> MyADT`, where all thee fields are ultimately anonymous, they only have type. In Rust on the other hand you have a `enum MyADT {Event1(Foo), Event2(bar), Event3(Buzz)}`, and you know what these types actually represent. I recall in modern C++ you can use `union`, but then you have to wrap it with something that tracks the field currently set; and I guess that alone shows it is more to write than in Rust. These are just something I remember offhand, I'm sure there're more examples regarding syntax. > My main concern is that memory is just one of many resources that we > need to use safely, but it's the only one that Rust concerns itself > with. Memory safety can give you a false sense of security. It's > possible to write insecure apps that are perfectly memory safe. Well, this is a correct thought, but I don't see what point are you trying to make here. I mean, you can write a bad program in any existing language, sure. Rust gets rid of one possible problem, so… one problem less is good, I guess? _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev