Looking Back at the Mighty Function

One of the most basic building blocks of programming is the function. You call some piece of code, passing some parameters and you get back a returned value. If you grew up with any modern programming language you probably don’t even think about it. But, the function was a major innovation. In the guts of your computer there were no functions. There was just a program counter that went forward and you could tell it to jump somewhere else if you really want to (the dreaded goto).

I started programming BASIC at 11 years old. Note, this was not¬†Visual Basic, which is a full-fledged modern programming language. This was unstructured BASIC. For me, a program was this linear set of instructions to the computer that accepted input, did some processing and then printed or drew something on the screen (a TV back then, no monitors). Each line in the code had a line number and a common control structure was “goto “. So, the program was literally a linear set of instructions executed one after the other.

I still remember my awe when I learned about the “GOSUB” command (go subroutine), which lets you execute a block of commands and then return to the line after the call. Amazing, isn’t it? No parameters, of course, and no local variable, just go somewhere and return automatically. This was still a major improvement over the “goto” statement, because with “GOSUB” you could call the same subroutine from different places in your program and it will return to the right place. If you wanted to implement it with “goto” you had to store the return line number in a global variable and “goto” it at the end of the code block. There was also the “DEF FN” pair of keywords that confused me to no end. This is arguably the worst and most inconsistent programming language syntactic structure I ever encountered. It allows you define as expression similar to Python’s Lambda functions. You have to concatenate your function name to the “FN”, so each function has a mandatory “FN” prefix such as:

DEF FNSQUARE(x) = x * x

Now you can call the your function


Nasty. Isn’t it?

So, whenever you are frustrated with your programming language or why stack overflow has the best answer buried in third place, remember that it has never been so good and it will only get better.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Related Posts