Wednesday, December 29, 2010

A Brief History - 1 - The Birth of an Innovation


"A Brief History of Code", by Rudedog Hawkins

PART 1:  Object Trek: The Birth of an Innovation:

Computers began when engineers realized that they could create analog computers that approximated their formulas.  Analog computers were not flexible, because their circuits were built to solve just one type of calculation.  This gave rise to the digital computer, which allowed the programmer to modify the computer behavior by storing "code" within dedicated storage registers.  These registers saved a sequence of instructions that collectively executed a 'procedure' and produced a 'result'.  Engineers could string together many known procedures in a sequence and produce complex results.  The processor would begin with the instruction in the first register, the entry point, and continue in sequence until it reached the last instruction.

It quickly became apparent, as the digital computer technology grew rapidly, that writing code that accurately produced the desired results could be a slow and painstaking process.  Engineers wanted to be able to re-use and combine some of their 'procedures' into larger and more complex programs.  Thus far, engineers had to re-enter the same instructions any time they wanted to re-use proven and tested code.  This problem gave rise to the concept of a 'subroutine'.  Re-usable code was born, that was 'procedure-driven'.  The sub-routine, a basic unit of code that accurately produced a result based upon input parameters that were supplied to it.  A sub-routine could be called from one of your main procedures.

As computer technology grew and grew, engineers set their sights on higher and more complex programs.  Once again, they were driven by the desire to re-use code and that ever present "need for speed" in development.  Whereas they had once wanted to re-use 'procedures', now they wanted to re-use entire programs or just significant portions of them.  This need eventually gave birth to the concept of an "object'.  An object, a unit of code that could execute multiple procedures and sub-routines based upon input parameters that were supplied to it.  It was like a complete little stand-alone program.

However, the procedures that an object executed were a little different.  It was decided that the procedures that defined an object should be for the exclusive use of that object, not to be shared by other objects.  These procedures were named methods.  But, how do you use these objects?  This is where the constructor comes in. 

A constructor is the entry point into the code that defines an object.   It is the first method that is executed, and initializes the object to a pre-determined state.  It is the code that can be modified to accept input parameters to define the behavior of the object over its' lifetime.  Now the concept of the object was complete.  A stand-alone unit of code that was built up from many pieces.  Pieces, that could be easily debugged and proven reliable. 

But, more importantly, the code was easily re-usable by simply calling the object's constructor.  Object Oriented Programming was born.  Objects were creating and calling object instances inside of other objects.  The best part is this.  You can as many objects as you want of the same type, give each of them different parameters in their constructor, and each of them will be slightly different. 

For example, suppose you had a class named House.  You could give it a constructor that accepted a color.  Now you could define and declare a Red House, a White House, a Blue House, etc.

Hope this helps.

Rudedog Hawkins   =8^D

No comments:

Post a Comment