3 ms·
Rust has been such a "pain" to learn - at least compared to other, more straight-forward languages. But boy does it feel good when you know that after a few bac
by iagooar 11mo ago
Rust has been such a "pain" to learn - at least compared to other, more straight-forward languages. But boy does it feel good when you know that after a few back and forths with the compiler, the code compiles and you know, there is not much that is going to go wrong anymore.
Of course, I am exaggerating a bit - and I am not even that experienced with Rust.
But after coding with Ruby, JS/TS and Python - it feels refreshing to know that as long as your code compiles, it probably is 80-90% there.
And it is fast, too.
- imron 11mo agoThat’s my favorite feature. Rust turns runtime errors into compile time errors. All that fighting with the compiler is just fixing runtime bugs you didn’t realize were there.
- echelon 11mo agoRust is the most defect-free language I have ever used. I'd wager my production Rust code has 100x fewer errors than comparable Javascript, Python, or even Java code. The way Result<T,E>, Option<T>, match, if let, `?`, and the rest of the error handling and type system operate, it's very difficult to write incorrect code. The language's design objective was to make it hard to write bugs. I'd say it succeeded with flying colors.
- satvikpendem 11mo agoNow try an actual functional programming language. I like Rust too but those features all come from FP, and FP languages have even more features like that that Rust doesn't yet or can't have.
- ikety 11mo agoI'm interested in what scenarios you don't get this same feeling when writing TS code? I of course agree with Ruby, JS, and Python.
- regular_trash 11mo agoNot parent comment, but TS is generally safe if you have types correct at system borders, but very scary when you don't. Some of the most impactful bugs I've seen are because a type for an HTTP call did not match the structure of real data. Also, many built in functions do not have sufficient typesafey like Object.entries() for instance
- vjerancrnjak 11mo agoThe worst offender is toString which has different types between objects and is everywhere by default.
- teaearlgraycold 11mo agoThat is an issue with how TS works, but it can be significantly improved upon by using a library to verify the structure of deserialized data. zod is one example, or you could use protobufs. Fundamentally, this is an issue with any programming language. But having your base "struct"-like type be a hashmap leads to more mistakes as it will accept any keys and any values.
- regular_trash 11mo agoI disagree that this is an issue in every language - the problem is that in other languages the validation against some schema is more or less required for unmarshalling, and it's optional in TS. Seeing a deserialization error immediately clues you in that your borders are not safe. Contrast that with TypeScript, where this kind of issue can lead to an insidious downstream runtime issue that might seem completely unrelated. This second scenario is very rare in other languages.
- criemen 11mo agoI don't know Rust, and I'm genuinely curious: How does it improve over that problem? When you call a REST API (or SQL query for that matter), how does it ensure that the data coming back matches the types? TS allows you to do parse the JSON, cast it into your target type, done (hiding correctness bugs, unless using runtime verification of the object shape, see sibling comment). Does Rust enforce this?
- rascul 11mo ago> Rust has been such a "pain" to learn - at least compared to other, more straight-forward languages. But boy does it feel good when you know that after a few back and forths with the compiler, the code compiles and you know, there is not much that is going to go wrong anymore. I found that at some point, the rust way kinda took over in my head, and I stopped fighting with the compiler and started working with the compiler.
- deleted 11mo ago[deleted]
- apitman 11mo agoRust is easy to learn. I've done it 4 or 5 times.