Thursday, May 22, 2014

Abstractions

One of the ideas basic to Computer Science is Abstraction. In my very first Computer Science class in college, we started out learning about logic gates and how voltage changes can alter the flow of current in a circuit. The voltages applied were ~3.0V and ~0V, if I remember correctly, but right away we simplified things by simply using zeros and ones instead of the actual voltages. This abstraction made it much easier to start dealing with the logic at a higher level.


In fact, the gist of the whole class was learning how applying one abstraction after another eventually allows us to use 3rd-generation programming languages (the C language in our case), where the bulk of development work happens today. A 3rd-generation programming language has the attractive feature of portability. You can write C code once and have different compilers translate it into assembly code specific to a certain processor architecture.

To get from electric current to C, we applied the following simplifications and abstractions:
  • Treating analog current as a simple binary on/off signal.
  • Treating logic gates as simple switches that react immediately in response to the the binary signal.
  • Combining switches to form modules that do things like compute sums or fetch memory.
  • Treating these modules as self-contained black boxes that we don't need to know the implementation details of.
  • Arranging these modules in such a way that it forms a rudimentary computer.
  • Sending instructions to the CPU first by using raw hex, then by using specific op-codes, then formalizing it with an assembly language that can be used to create entire programs. 
  • Writing C code that could be compiled (i.e. translated) into assembly before running.



Keep in mind that this was a freshman class; we barely skimmed the surface of what C is, and C is considered to be the lowest-level 3rd-generation programming language. Every other programming class continued to build on these concepts and continued adding more abstractions to the mix. It's mesmerizing to think that ultimately all we're really doing with programming is controlling the flow of electrons through a circuit. Abstractions are powerful. Next time: what happens when abstractions aren't so powerful after all.