Follow

So weird: when you have developed so much recently that other imperative, OO-style languages feel like 's (and no, this is not a compliment😉).

And don't you dare to assign aliases to other objects in those languages! It just looks and feels...wrong! Is it mutable? Is is not? Does it get cloned? Oh my what happens here?!😲 What...a thread!?😱

· · Web · 1 · 2 · 2

@janriemer lol yeah! :blobsweats: after working with Rust for a while I now feel dirty when using other languages and leaving unnecessary references everywhere.

But on the other hand I enjoy the fact that I don't need to .unwarp().unwrap().unwrap() everything.

@sergrass > But on the other hand I enjoy the fact that I don't need to .unwarp().unwrap().unwrap() everything.

Yeah, until you look at a bigger codebase and then have to ask yourself: "oh, can this value be null? And what is this "connect()" thing doing? Can it fail? Hm...looks like a third party lib. So do I have time to look at the docs now? Na, what can go wrong!?"

is about being explicit and I've never encountered a situation, where this is a bad thing.

1/2

@sergrass When one has to call .unwrap().unwrap().unwrap() (btw one should rather handle the Error/None case instead of panic), it _shows the complexity of the problem/data structure at hand_.

In other languages this only gets hidden away - the underlying complexity is the same and one needs to deal with it somehow (or not deal with it at all and get thrown a NullPointerException in the face).

2/2

@sergrass @janriemer Yeah. Sometimes, rather than unwrapping an error value, you can apply methods to it which will preserve any error and operate on an ok value. Similarly for Option. That reduces the number of unwraps.

See: doc.rust-lang.org/rust-by-exam

@underlap @sergrass Yeah, absolutely, the std lib is very deep in that regard and provides some useful methods for almost every circumstance.
Thank you for the link! 🙂

Also, if you "want the simplicity of unwrap without the possibility of a panic", the question mark operator "?" has you covered 😉

doc.rust-lang.org/rust-by-exam

1/2

@underlap @sergrass Of course, there are always edge-cases: let's say, in case of `Option`, in 99% of cases you definitely have a value. Then always handling the `None` case can become tedious.

In this case, you might be able to use some kind of "DUMMY" value.

If the Rust compiler uses this "trick" with their "NodeId" values in their AST, you know that this might be worth looking into😉:
github.com/rust-lang/rust/blob

As I said, this is really an exception. Please use `Option`.🤓

@janriemer @sergrass I presume that exceptional example is intended to save storage and perhaps improve performance.

@janriemer @underlap thanks for the pointers! I really appreciate the links and explanations. This has been a most informative thread :blobcat:

Sign in to participate in the conversation
Mastodon for Tech Folks

This Mastodon instance is for people interested in technology. Discussions aren't limited to technology, because tech folks shouldn't be limited to technology either!