By Dwayne Phillips
I had to explain the concept of a subroutine in a computer program. The humble subroutine is a type of a module in a system. Modules in systems are wonderful devices. Often, however, we forget about them and how to use them well.
Now and then, a fundamental concept comes back to me as I try to explain it to someone else. This past week, the subroutine came back to me. My youngest son is taking a beginning programming class in college. Finally, the instructor (I am pretty sure he is a grad student, not a professor, although I am not sure a professor would be a better teacher) reached the point in the semester where he “had to” give an assignment that required subroutines (“functions” in Python). I didn’t like the assignment as I felt it didn’t show the power of subroutines.
Enough lament on the state of college education in America today.
I found myself explaining the concept to my son the music major. Hmmm, if you are not familiar with music concepts, this may not make sense to you, but it made sense to him. Often, a section of music is played several times such as when a pop song has three verses and the music is the same for each verse. That section of music is like a subroutine. It does something for the song, but there is no need for the composer to write the music three times. The composer writes it once and the notation points the performer to the same section of music three times.
A subroutine is like that. The programmer writes that piece of source code one time. The programming language notation allows the programmer to point to that section of code several times without writing it each time.
The subroutine is a piece of work or a piece of data or a piece of both work and data. Once that piece is created, it can be used in many ways with many advantages.
This brings me up a level of abstration to a module in a system. A module is a thing that is smaller than the entire system, but once made can be used in many ways by the system. Looking on my desk right now I see many modules in systems.
The cartridge that fits in a ball point or other type of pen. Once the ink is spent, I replace just the cartridge instead of the entire pen. Different types of cartridges will fit in the same pen body as long as they meet the interface standard defined.
The staples inside the stapler. The staples come glued together in a defined size. Once the staples are spent, I merely replace them instead of replacing the entire stapler.
The clip that holds my ID badge to my shirt. I can remove it and replace it with a spring or a coil or any one of several different types of connectors. After removing the clip, I can use it on another ID badge or some other type of device.
The monitor I am looking at right now. There are many different sizes, shapes, and makes of monitors that I can connect to the computer on the desk. As long as a monitor fits the defined interface, it will work.
I am not sure who invented the concept of the module in a system. Several people are credited with putting that concept into the subroutine in a computer program (see reference below). I am glad the subroutine exists.
In a way, I am happy with the failings of the state of college education in America today. That allowed me to explain the subroutine to my son the music major. I still think that an instructor should be able to say more about the humble subroutine than “we have to do an assignment with one.”
Reference:
I think the Wikipedia page on subroutines is excellent. See it here. It credits Maurice Wilkes, David Wheeler, and Stanley Gill with inventing the subroutine.
0 responses so far ↓
There are no comments yet...Kick things off by filling out the form below.
Leave a Comment