I (proudly!) nailed the task on the first try, but I'm a little confused as to the order in which these two elements were written (in contrast with how they were written in previous examples).
What I mean is, in previous examples, the "specific tasks" (the very reason we created this function) were written first (which was counterintuitive to me), and the description/definition (if that's the right way to say it) was written second.
Can a wise person explain this difference? Are the orders arbitrary?
Thank you in advance for any insights!
Why is the "function description" written first and "specific tasks for it" written second?
Under discussion
Comments (1)
- Popular
- New
- Old
You must be signed in to leave a comment
Anthony Chalk
30 December 2019, 09:25
Are you talking about the code itself i.e. the order in which you write the methods in the code?
If yes, the order in which you write your methods doesn't matter (except for readability purposes). The main method is called first, then then the methods that the main method calls, and then the methods that those methods call etc etc e.g.
in the above example the main method is called first, it then calls method1 which in turn calls method3, then the main method calls method2 - has I written method1 and method2 before writing the main method (assuming that the method bodies were still the same) the order in which they are called would not change.
In the method body, or any block i.e. any code between { and }, is executed top down, which is why in the above example method1 is called before method2, because it is written first in the main method 0