top | item 45921535

(no title)

iagooar | 3 months 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.

discuss

order

imron|3 months ago

That’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|3 months ago

Rust 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.

rascul|3 months 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.

apitman|3 months ago

Rust is easy to learn. I've done it 4 or 5 times.

ikety|3 months ago

I'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.

josephg|3 months ago

One big source of bugs in TS is structural sharing. Like, imagine you have some complex object that needs to be accessed from multiple places. The obvious, high performance way to share that object is to just pass around references wherever you need them. But this is dangerous. It’s easy to later forget that the object is shared, and mutate it in one place without considering the implications for other parts of your code.

I’ve made this mistake in TS more times than I’d like to admit. It gives rise to some bugs that are very tricky to track down. The obvious ways to avoid this bug are by making everything deeply immutable. Or by cloning instead of sharing. Both of these options aren’t well supported by the language. And they can both be very expensive from a performance pov. I don’t want to pay that cost when it’s not necessary.

Typescript is pretty good. But it’s very normal for a TS program to type check but still contain bugs. In my experience, far fewer bugs slip past the rust compiler.

regular_trash|3 months ago

Not 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

o11c|3 months ago

Typescript doesn't even support notions like "unsigned integer". It is not a serious attempt at type-safety; its main claim to fame is "better than raw Javascript" which is not saying much.