Little things that matter in language design: make it do what it looks like it does
Little things that matter in language design: make it do what it looks like it does
Posted Dec 29, 2014 10:26 UTC (Mon) by maryjmcdermott57 (guest, #100380)In reply to: Little things that matter in language design: make it do what it looks like it does by jem
Parent article: Little things that matter in language design
- with the last expression in a block, add ; is up to me (depend on my intention)
But it's also give me more confusing. So can you explain a little bit more about this code.
if condition {
function1()
} else {
function2()
}
expression3;
With this code above, the if/else is not last expression. And if both function don't return value so we don't need add ; at the end of } of whole if/else. That makes sense (as author said that the language doesn't require that ; if whole if/else doesn't have value). With that knowledge, why we have to add ; at the end of println!("hello"). Because println!("hello") also doesn't return any value
fn main() {
println!("hello") // why we have to add ; at here
println!("world")
}
And if can, please answer me one more question. What about other blocks like match, loop, struct, function declaration? These are also expression as whole or not.
Because I saw function declarations next each other without ; between them. like this
fn foo() {
// ...
} // don't have ; at here
fn bar() {
// ...
}
If they are expression, we have separate them with ; to compile correct, right?
Please bear with me if my questions make you annoying. I'm very confusing about these and I also add question in other places but not get the good answer or some just ignore & vote close topic.