Skip to content

Comment on The Wake Programming Languageparent

Comments

Which begs the question, why even have the trick of the missing semicolon in that case? Why rely on one missing 5 pixel character to say that "this function defies your expectations"?

If it's not the norm, I'd rather have an explicit "nil" or something at the end.

The trick is that now the keyword return marks an early return. And as early returns are often exceptional, I find the added visibility nice. On the other hand, every function in Rust, except those that contain an infinite loop, returns something so the keyword at the end of the function body is redundant in my opinion.

Also, because function signatures are never infered in Rust, mistakenly adding or forgetting the last semicolon will always result in a type error.

Well, if you add a semi-colon where it's not supposed to be you'll get a compile error. If you omit a semi-colon, you'll also get a compile error. They're just there to separate statements (Rust is not whitespace-sensitive).

The most common pattern in my Rust code is:

`statement; statement; expression` where the expression is what I actually want to return from this function

it seems more noisy to say `statement; statement; return expression;`

It'd be `()` and make it so that every side effecting function would be at minimum two lines long, and be a visible wart. It's pretty easy to tell that if the function returns something, the last line evaluates to that expression even if there's no `return` since if it didn't, it wouldn't compile (or there'd be a dead code warning).

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.