Pre-RFC: Catching Functions

I couldn’t agree more with @chriskrycho. I especially dislike the change in the return type. It’s syntactic rat poison rather than syntactic sugar. Declaring that your function returns T whereas in reality it returns a Result<T, E> is just awkward, it looks wrong. It puts mental pressure on the reader of the code, having to JIT-translate the types in their head all the time. (I also agree that it causes syntactic non-uniformity, and although it may already be present in the language, I would still not recommend adding even more of it.)

Also, my experience is that generally those who haven’t written a lot of Rust code are the ones who oppose having to write an explicit Ok, Err, or Some. I remember saying to myself, when I was just about to start learning Rust: “Meh, do I really have to wrap every optional value in Some?” — and then after about 2 or 3 days, this feeling went away completely. Coming from other languages, we don’t initially think in the way Rust expects us to think, and it’s fine — but we should eventually try to adapt. After all, we are now programming in Rust, and not in another language. :slight_smile:

So instead of thinking about “nullables” and “exceptions”, we should just appreciate that Rust’s expressive type system gives us Option and Result, which don’t require any special casing/handling, they’re just regular enum types that can and should be treated in a regular manner. No throwing, no nulling, no bells and whistles — just construct an enum variant as you always would, and the rest is conventions.

And indeed, one of Rust’s main selling points is its simplicity. We shouldn’t add more and more syntax just for the sake of some slight convenience (which also isn’t necessarily considered to be convenient by the entire community, see this very thread). I probably said this already in the thread about translating Rust keywords to non-English languages. Just as I would not like to see non-English keywords in Rust, I would also not welcome non-Rustic concepts, such as “exceptions” sneak into it.

Rust has the unique feature that the original designers and the community managed to leave or weed out almost all bad pieces of language design which are so common in other languages. It’s basically the only systems programming language that I could honestly recommend to be used without subsetting. (No, not even C — while it is probably smaller than Rust, oh boy, does it have some horrible features that one just should avoid completely!) I would very much not like random syntactic and/or semantic additions popping into the language without a good reason — and shaving off 3 bytes (apparently) or making the language look like Java aren’t too good of a reason in my eyes.

18 Likes