The output of the code generators is in two parts:
* First (at the top) there are the definitions. These include function definitions, variable declarations, and helper functions.
* After the definitions, there's the general code. These are in the order the blocks appear on screen, top to bottom (with a slight LTR or RTL angle).
Here's the code responsible for putting these two parts together:
For JavaScript the function definitions could be anywhere in the program and it will still work. That's called variable hoisting. Thus this is valid JavaScript code:
foo();
function foo(){}
But for other languages (such as Python), the calls to a function must be after the definition of that function. Thus they need to be generated like this:
function foo(){}
foo();
In the interests of consistency, Blockly places all definitions at the start of the program. You could write your own generator (just copy and modify an existing one) to output function definitions inline instead of in a definitions section. But it's not an option that the existing generators support.