Code Compression in a Modular System

From Zanecorpwiki

Jump to: navigation, search

Nascent.

From one point of view, object oriented coding is about code compression. If object A is a parent to B and C, then the code savings are on the order of:

(size(A) + size(B) + size(C))/(size(A) * 2 - ABSTRACTION_OVERHEAD + (size(B) + size(C))

(TODO: convert to math formula using MathML or Latex stuff or whatever it is; document process this time.) In other words, you save the size of A. In general, you save the size of the parental lineage for each child after the first. Notice, you get the same benefit from the use of libraries. In general, a lot of work has been done to compress code. This saves makes a code base easier to grasp conceptually by chunking concepts, and also by reducing the sheer number of lines of code.

Simple enough, though most coders now-a-days are not used to thinking of abstraction systems in terms of code compression. For that reason, I'd like to go through a small example to focus our minds on this aspect of such systems:

At the time of writing, the parent NoteWidget (a Javascript class), was a placeholder. Following is the initialization code for the child BookNoteWidget:

pre BookNoteWidget = function() { _cl_extendPrototype(NoteWidget, BookNoteWidget); this.parent = NoteWidget; this.parent(); } /pre

Our next step in the project was to create another note taking widget aimed at web article. We could copy the above and replace mentions of 'BookNoteWidget' with 'WebArticleWidget', but instead we do:

WebArticleNoteWidget = function() { NoteWidget.initialize(WebArticleNoteWidget); }

We then change BookNoteWidget to:

BookNoteWidget = function() { NoteWidget.initialize(BookNoteWidget); }

and NoteWidget defines initialize:

pre NoteWidget.initialize = function(type) { _cl_extendPrototype(NoteWidget, type); this.parent = NoteWidget; this.parent(); } /pre

If we count the above as four lines and the child constructors as one, then this change saves us two lines (eight versus the six). For more complex initializations, the more we save (as savings dominate overhead). For each new child class, we save three lines.ref group=notesIncidentally, we can also calculate the abstraction overhead at this point. Notice that with two children, we save only two lines. With three children, we save five. With one child, the abstraction would actually cost us a line. That's the abstraction overhead./ref

Modular service systems achieve a high degree of global compression through the same mechanism, but it's applied to more than the 'logic code'. Interface code, data models, deployment code as well as process are all shared in a similar fashion.

Notes

references group=notes /

Personal tools