LPTHW Ex. 23 Calling Functions

I have a question. I want to know why, in exercise 23, we have a function that is being called before it has been defined. Is that a common thing? To me, it seems like you’d want to define all your functions before you call them.

Thank you in advance,

Hannah

Welcome Hanna (@gracefullily) to the forum.

What function are you thinking of?

You can wrap the code you want to show/ask question about like this:

[code]
write the code here
[/code]

Thank you for your reply. I got my question answered elsewhere. I will be be back on the forums if I have any more questions though.

Hi I think I replied to you on email but here’s a quick response for the forum:

Old programming languages used to require you to define everything you used first not because that was better for the programmer, but because it was better for the compiler. Computers back then used tapes and had very little memory. A tape is literally a tape, like a VHS or reel-to-reel projector. So they code for the program was read from the beginning to the end in one move. Then the computer didn’t have enough memory to hold the whole thing so it would process each line of code it hit on the tape as it ran and write out the compiled program. The end result is if it wrote out the byte code (assembler) for a call to a function, then that function better exist or else it’d crash.

Now computers have WAY more memory so this convention is unnecessary. You could define things in any order you want and a good compiler should be able to resolve them easily. Programmers still think the old school ordering is better, so you might have to adapt that in some situations, but there is no real validity to it one way or another.

2 Likes