Saturday, December 29, 2012

Lemming Terminal

Often times, nested routines tack on layers of terminals that close statement blocks. These terminals, while important, retard the development process. This article suggests the "Lemming Terminal" lexicon to close a group of nested routines.

In languages like javascript where nested callbacks can become quite involved (noticeable to anyone who uses jQuery), closing nested routines becomes a real pain (PITA) and a waste of time.


JAVASCRIPT
exports.findAll = function (req, res) {
  db.collection('wines', function (err, collection) {
  collection.find().toArray(function (err, items) {
  res.send(items);
  });
  });
});

And, then we have other languages like Ruby that terminate blocks with the "end" statement.

RUBY
class ArrayMine < Array
        # Build a string from this array, formatting each entry

        # then joining them together.
        def join( sep = $,, format = "%s" )
                collect do |item|
                       sprintf( format, item )
                end.join( sep )
        end
end


The Python language attempts to solve this problem by using tab characters. However, this causes other problems: [1] different text editors will read tab characters differently; sometimes tabs are converted into spaces, or may be read as 4 to 8 spaces; and [2] scripts can't be minimized from white spaces without turning the program into a trembling mess.

PYTHON
def dosomething(callback): 
        size, reportSize = 20000, 1000 
        callback("begin processing {0} items".format(size)) 
        for i in range(size): 
                if i % reportSize==0: 
                        callback("{0} items processed".format(i))


Terminals are important because they allow us to avoid tabs and newline characters. Which, is important for serialization and compacting code. It allows an entire program to be written on one line if the programmer so chooses. Javascript, C, and Java - are great because the provide well structured programs, but terminal maintenance is a waste of a programmers time.

The alternative is to use my new lexicon called the "Lemming Terminal" (;;) which terminates all open nested blocks. Here we apply the "Lemming Terminal" to our Javascript and Ruby codes from above:

//Javascript
exports.findAll = function (req, res) {

        db.collection('wines', function (err, collection) {
                collection.find().toArray(function (err, items) {
                        res.send(items);
;;





# Ruby
class ArrayMine < Array
        # Build a string from this array, formatting each entry
        # then joining them together.
        def join( sep = $,, format = "%s" )
                collect do |item|
                       sprintf( format, item )
;; (or perhaps an 'endall' statement would be more appropriate for Ruby)
Tim Montague 12-29-2012