Zrywka drewna 776

The English language contains words with multiple and often contradictory meanings. A dress, for example, is only one of many items you could put on while dressing yourself. Meanwhile, if you want to wear pants instead, you should avoid pantsing yourself, as that would be counter-productive.

These shades of meaning come into play frequently in programming. Writing a .NET application to manage school schedules requires some contortions to avoid using the reserved word class, and writing one to hold Dungeons and Dragons character sheets requires you to spell out the attribute Intelligence instead of using the far more common abbreviation int.

Dimitris, however, wasn't thinking about the many interesting tidbits to be found in the English language as he went about tracing an error message through the stack his formula engine application had unraveled. Instead, he was thinking about logging. Not the act of felling trees and preparing their corpses for use by humans, but the act of writing messages to a central location so that debugging an application would be easier.

Logging has a fascinating etymology, by the way. It originally had to do with a bit of wood that was designed to float upward when a ship sank, making it easier for someone to discover what had befallen the ship by reading its log. In the same manner, Dimitris wanted to discover what had happened to the application—but he got distracted along the way.


/**
 * override xxLog as it writes unnecessarily to database syslog
 */
function xxLog( tag, s )
{  
        if (sbDebugEnabled) {  
                text_write( prx_debug_file, str(tag) + "|" + (( is_na(s)) ? "NA" : str(s) ));
        }  
        if (sbDebugPrintEnabled) {  
                print( str(tag) + " : " + (( is_na(s)) ? "NA" : str(s) ));
        }
}

Demetris found the exact same snippet at the top of every system class, across hundreds of files. Why had the code's previous maintainer continually overridden the base log functionality like this? What use case was the base logger written for? Why hadn't the original function xxLog(), whatever it was, simply been rewritten to meet that more common need?

Curiosity piqued, he pulled up the base xxLog() function in the standard library the system files were using:


/**
 * Calculate a natural logarithm
 */
  function xxLog(float num) {
    if (num == $NA) {
      return $NA;
    }
    return first(first(sql("select log("+string(num)+")")));
  }

Logarithm, from the Greek "Logos" meaning ratio or reckoning and "Arithmos" meaning number, is a numerical operation that can be performed on a number to determine the number to which a given base (e, for a "natural logarithm") must be raised to achieve the number given as the input. It's certainly not an operation that can be performed on a string—and because the formula engine used the backing database's mathematical library to calculate the result, it would log errors in the database, probably along the lines of "Invalid input."

Which is all a roundabout way of saying: Words are hard.