The Go Programming Language, p. 46: “A syntactic block is a sequence of statements enclosed in braces like those that surround the body of a function or loop.”
But I don’t see anyone out there using phrases like “the code in the loop’s block runs repeatedly” or “the function’s block is executed”.
Is this just because such beginning-programmer-oriented instruction hasn’t generally been needed in the Go community thus far? Or is this terminology technically inaccurate in some way?
Aside: if we’re talking about describing code, I’d like to see more people talk about evaluation, rather than execution.
Can you elaborate on the distinction? I’m used to “evaluation” implying both parsing and running code, as done in interpreted languages; I don’t think of compiled code as something that gets “evaluated”. Could be I’ve just never looked into it that closely, though.
Probably Fabio’s, but that isn’t the important part. The important part is building you own mental model how expressions are evaluated, because when you are able to do that, you can ask questions like “what is the type of evaluating this expression”?"
Generally I think it makes most sense to talk about loop or function bodies, however, blocks are still an important concept. Consider the following code:
func foo() {
// Do stuff...
{
bar := true
}
// bar is out of scope.
}
Here I’ve used a code block to define a variable that is out of scope after the block is executed. Same as what happens with if statements and for loops.