this post was submitted on 04 Apr 2024
369 points (95.8% liked)
Programmer Humor
32410 readers
962 users here now
Post funny things about programming here! (Or just rant about your favourite programming language.)
Rules:
- Posts must be relevant to programming, programmers, or computer science.
- No NSFW content.
- Jokes must be in good taste. No hate speech, bigotry, etc.
founded 5 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
you mean like return/break/etc.?
because Rust was designed to remind you of functional programming despite not being very functional, and because semicolons allow way better syntax rules in Rust and are generally pretty vital for good, readable lowish-level code. it also allows Rust programmers to use newlines/indents and stuff to pretty up their code a lot without littering it with random
\
and|>
andbegin
end
and such everywhere, which, given how dense Rust code can be and how much it uses iterators and weird trait magic, is a big plus for readabilityI don't work on any widely-used languages (I've made my own but not anything important) but I do think the designers of Zig and Rust have very good reasons for using semicolons – I read some reasons from the Rust devs themselves somewhere but I can't remember them other than it vaguely being about how Rust is expression-based and intended to be lightweight and how whitespace significance can create confusion around how to read and write certain things and bla bla bla...
but my personal opinion, what I generally I would imagine it's for other than readability, is because the code can look a lot cleaner when an expression returned from a block is just the expression, and not expression plus some token like
return
. It's especially nice in long closures or extremely short and simple blocks. I would rather consistently have to write expressions broadly likelet a = { b + c };
rather thanlet a = { return b + c }
. The semicolon has significance as a "result discarder" so expressions can be the default, so it's on the surface a lot more functional-friendly.Also this is more specific but I hate the way WS languages generally handle quotes