Code review

Something I recently came across which I felt should be commented on (class names changed to make them anonymous). The original:

    var isXXS = function() {
      var $primaryMenu = $('div.display-mysite-page-primary-links');
      var attr = $primaryMenu.attr('data-eq-state');
      if (typeof attr === 'undefined') {
        eqjs.query(undefined, true);
      // If attr is defined AND attr is pane-xxl OR pane-xl, return true.
      return typeof attr !== 'undefined' && (attr === 'display-xxs' || attr === 'display-xs');

How I would change it:

    // This is a test for less than or equal to XS (as below), not XXS
    // Or this could also be "isXS". "isXXS" is incorrect, however.
    var isLteXS = function() {
      var $primaryMenu = $('div.display-mysite-page-primary-links');
      // jQuery handles data attributes with data better than with attr.
      var attr = $'eq-state');
      // We don't really need to make sure that it is undefined, so
      // just see if it has a value
      if (!attr) {
        eqjs.query(undefined, true);
        // signals to the programmer that there is no possible TRUE
        // condition from here on out.
        return false;
        // OR you could do:
        // attr = $'eq-state'); if eqjs updates state
      // why are we testing if attr is undefined here? There are two
      // possible acceptance criteria, and neither of those are undefined.
      // ALSO: strict equality should only ever be used in cases where an
      //       ambiguity can exist. In String comparison, that's not possible.
      return (attr == 'display-xxs' || attr == 'display-xs');

Posted in Best Practices, Review | Tagged | Leave a comment

Git for the non-programmer

Wrote this for work. Thought it would be beneficial here.


Once upon a time, long ago before the world was civilized, when dragons such as Flash roamed every webpage and MySpace reigned supreme in social media, code was untamed. It lived as an ever-changing chameleon and it was often impossible to know what was where and how it was supposed to execute. There were primitive attempts at guarding against these difficulties. Organizations would store archives of releases, or carefully label things so as to know which document was authoritative. But instead of ensuring security, this only lead to further chaos. How was someone new to a project to know what file was truly the authoritative version? All too often there would be names such as MyClass, MyClassReal, MyClassA, MyClass_123 and so on into a putrid cacophony.

Into this mist stepped the version control system (VCS). This allowed a company to keep a history of a file in a “repository.” No more would suffixes A,B,C,1,2,3 be needed. Instead there would be a canonical history of the document which all could examine and understand. These systems placed light into the heretofore pervasive darkness and there was much rejoicing.

Continue reading

Posted in Best Practices | Tagged , | Leave a comment

Startup is a buzzword

So at one point I commented on the meaningless of the word “startup”. And I think that it might be worth it to look into the issue a tad more.

Now don’t get me wrong, I have no issue whatsoever with people coming together to create a new business. Business is a good thingTM. And if “startup” simply meant, “business which is just starting” then I would be behind it completely. Unfortunately it has nothing to do with that.

I think the most common idea that people try to convey when they say that “they are a startup” is that they have an idea which they think that no one has ever used before/done as well/involved so many pigmy gipsy-moths/&c. Well, I hate to be the bearer of bad news, but there are few businesses which start which don’t believe they somehow meet that qualification. Heck, the gas station in my town is there because it believes that it is the best serving gas for its demographic (in this case, people who need gas and happen to be going somewhere that involves passing their particular corner). Being new definitely isn’t special and being best, honestly, isn’t even very special.

I think another thing that people try to imply when they say that they are a startup is that they happen to have a loose culture, a casual atmosphere, and an XBox in one of the meeting rooms. Well, that’s great, but that doesn’t really cary any particular meaning. If all that it takes to create a startup is a gaming system and casual atmosphere then I think my house should qualify and I should get an angel investor and/or some venture capital.

And I think that brings us to what is the practical definition of a startup. A startup is generally a business which has yet to reach the point of profitability and feels that its equity is justification for lower salary, longer hours, and/or worse working conditions.

Very often these companies will try to supplement bad conditions by giving people things which have little to no immediate cost. One of the more common options is equity. Well, I hate to break it to these people, but programmers can’t eat equity. And even if we could, there is little evidence to suggest that equity will pay out in the long run (and I have heard stories of venture capitalists coming in and making equity as useful as a back pocket on a shirt).

Startup, when it comes down to it, means unproven product which has insufficient assets to meet its overhead. It is almost always a company which is upside down, and chances are good that they will not survive much past the first year, let alone getting to the point where they have a reliable product on the market.

I can’t help but shake the feeling that it really is a bad idea to work for a place which asks for an investment without a tangible investment in return. Perhaps my standards are too high, and perhaps this will cost me work in the future, but I really do believe in just pay for a good day’s work. I’ve seen a lot of people burned by an over-willingness to allow companies to delay payment.

Posted in Business | Leave a comment

on the order of operations

Quick thought:

There is a lot to be said about order of actions and optimization. Obviously, there are situations where B cannot happen unless A is accomplished first: your car can’t drive unless you’ve put gas in the engine. On the other hand there are events which can happen asynchronously or in circumstances where the order is not as apparently important: you can put gas in the engine and start the car in any order you want.

But, this order actually can matter quite a bit. If you’re a tea drinker, you’ll know that adding water to tea will provide a better cup than putting the tea in first. While you’ll still get a warm cup, you’ll find a better result.

If you’re looking for a more technical example, maybe you remember the movie Apollo 13 where Gary Sinise[1] is told that he needs to be able to get the command module to run sufficiently to land it without enough power to run a coffee pot for 9 hours[2]. Hours were spent determining, “If we boot systems X, Y, and Z in order Y-X-Z, is that better or worse than Z-X-Y or X-Y-Z?” (and, apparently, they finally got the right answer).

In a recent case, there was code which went to iterate through a sequence of objects and it did this in PHP. Normally the most efficient route for such an operation is by modifying the SQL: databases are great at sort and filter, programming languages often (though admittedly not necessarily) less so.

A developer went to change this order to what is the normal form but added a comment instead:

In this particular circumstance, querying for a specific ID 
could lead to a performance hit: the queried objects are 
already stored in Memcache.
  1. [1] Really Ken Mattingly
  2. [2] Whether the actual quote is worth it is up for debate, but the actual situation happened
Posted in Code theory | Leave a comment

How to get today’s results in GA

So a bit of an annoyance was that there was an incident on a server earlier today and I needed to track down why. My first stop, the access log, showed nothing suspicious. So I went to check Google Analytics. Unfortunately, this was a bit difficult: the incident had happened several hours in the past and GA’s real time tracker only showed relatively recent history.

Since the most recent article on this topic has to be fetched through the Wayback Machine, I thought I would recreate that information here. Continue reading

Posted in Google | Tagged | Leave a comment