by jokoon · 7y ago · 0 comments
Maybe I have a hard time adapting myself to rust? Maybe my brain is too much "wired" to a C style syntax. It still seems that to me, C-style syntax is just better.
I would rather prefer a C++-like language that breaks down from backward compatibility with C while keeping its simplicity, has STL containers, and is simpler to read and use.
Rust is cool, but I'm just curious if it can really be adopted for large project to justify rewriting existing code.
Anyway, what is "not simple" about Rust's syntax?
; can also make a lot of difference, which is a little weird.
I don't understand why there is both str and String, seems complicated for nothing.
Option things are not really clear yet, and I don't understand what is their use, it seems like an alternative to unions, but few developers use unions anyway...
Pattern matching seems powerful but I fail to understand its usage, and I'm a little skeptical about the machine code it generates.
D is fine, but I think that even D is not simple enough.
Rust seems like it's awesome, but it requires to entirely rethink how you write code, and I've never been a fan of high level abstraction.
`String` is roughly a Java `StringBuffer`, `&str` is roughly a C++ `string_view`.
Yes, you need to rethink how you write code. Rust relies a lot on the basics of typed functional programming. Reading a Haskell tutorial up until the M word would help a lot. But surely there's a lot of good guides written for Rust specifically.
tl;dr the core concept you're looking for is sum types, aka discriminated/tagged unions. If you're going "up" from C level abstraction, imagine a C union starting with an enum that indicates which value is there. That's essentially what it is at the memory level (modulo optimizations). But conceptually, you just have a "this OR that" type. Pattern matching is how you access values of that kind of type.
https://doc.rust-lang.org/book/ch06-01-defining-an-enum.html