Why does the start() function be called at the end instead of the beginning of the program
If you compare to a car.
The parts has to be created.
They have to be assembled
The wiring has to be connected from the battery to all electronic devices.
Then you can put in your key and start the engine. = ”start()”
Merry Christmas and Happy New year
and to all other at this forum.
A program many times is a collection of parts that all get assembled at some key point. Imagine I have a fake program that has functions A, B, C, and then a start() that uses them all. I then have two basic ways to write this:
start -- calls A, B, C A B C
A B C start -- calls A, B, C
If I do it the first way then you have the problem that start is talking about A, B, C yet you haven’t even seen those yet so you have no idea what they do. You’d have to read start,then go read A, B, C, then come back and read start again so you understood it.
In the second way (that most programmers use), you can study A, B, C and learn what they are and what they do, and then when you get to start you know what they do and it’s easier to understand them.
HOWEVER, the strange thing is most programmers browser through A, B, C, then jump to start, read start to get an overview, then go back and study A, B, C, then read start again. So it would seem that the first way is actually the better way since that’s how people read the code anyway. The other reason that code is usually done this way is because of a historic accident:
Early languages had to be written this way because computer had very little memory to store information. If you write the code A,B,C,start then a compiler can read A, process it, B, process it, C, process it, and then start can use those without having to look anything up. Modern languages don’t have to do this since they can store all of A, B, C, in memory, but the history of older languages is still around so we still write code this way.