• March 9th, 2010

    JavaScript Naming Conventions For People With Beards

    When developing in a team environment, coming to an agreed-upon set of naming conventions is incredibly important. The speed at which we as developers can come to comprehend the thought-processes and intentions of our peers greatly depends on our ability to look straight to their intentions, rather than having to first read the code line by line, mentally translating it into our own dialect, before truly understanding.

    In short, Aaron Cruz, here is a quick summary of the naming conventions which I adhere to:

    var MyClass = Class.create({
      initialize: function(arg1, arg2) {
        this.publicProperty = "'Public' property";
        this._privateProperty = "'Private' property";
        var localVariable = null;
      },
    
      publicMethod: function() {
        return "'Public' method";
      },
    
      isBooleanMethod: function() {
        return true;
      },
    
      _privateMethod: function() {
        return "'Private' method";
      },
    
      __eventHandlerMethodClick: function(e) {
        return "Click-event handler method";
      }
    });
    
    MyClass.classProperty = "Class-level property";
    
    MyClass.classMethod = function() {
      return "Class-level method";
    }
    
    MyClass.MY_CLASS_CONSTANT = "CONSTANT's should never change";
    
    MyClass.ClassEnumOrSubType = {
      value0: 0,
      value1: 1,
      value2: 2,
      value3: 4,
      value4: 8
    }
    

    While the above example uses the Prototype class structure, none of the principles themselves are Prototype-specific.

    Posted in Code/Projects, JavaScript | No Comments »

  • My Very Own GIT Manual

    August 11th, 2009

    GIT confuses the hell out of me. I’m used to Subversion and Vault, and the translation isn’t always clear. Thankfully, there’s GitHub which makes it super easy to jump into using GIT.

    Unfortunately I constantly forget how to do simple tasks, not to speak of complex ones. This post is going to serve as my very own GIT manual so I can make these translations easily and not have to remember the intricacies.

    Updating your local repositories with remote changes: git pull

    To get the latest changes from your remote repository merged into your local master, run git pull. This is pretty much the same as running git fetch then git merge origin/master. Think of this as the GIT version of svn:update or Vault’s “Get Latest”.

    git pull
    

    Pushing local changes to your remote repository

    git add 'your file name'  #do this for each file or folder with changes
    git commit -a -m 'Your commit message'
    git push origin master
    

    Rejected!

    If a push to your remote repository gets rejected, it’s probably because remote files have been changed since you last used git pull. Run git pull then git push origin/master again. With any luck you should be in business.

    Push master to origin/master

    git push origin master
    > To git@github.com:<username>/<reponame>.git
    >  ! [rejected]        master -> master (non-fast forward)
    > error: failed to push some refs to 'git@github.com:<username>/<reponame>.git'
    

    Damn! Shit’s broke! Pull again then re-try your push!

    git pull
    > Merge made by recursive.
    
    git push origin master
    > Counting objects: 10, done.
    > Compressing objects: 100% (5/5), done.
    > Writing objects: 100% (6/6), 814 bytes, done.
    > Total 6 (delta 1), reused 0 (delta 0)
    > To git@github.com:<username>/<reponame>.git
    >    65a1527..79239e9  master -> master
    

    It worked!

    Updating your fork of another user’s repository

    get fetch origin
    git fetch upstream
    git merge upstream/master
    git push origin master
    

    There’s probably an easier way to do that, but I haven’t figured out as of this writing.

    Posted in Code/Projects, git | 2 Comments »

  • Hatin’ on textContent and innerText

    June 1st, 2009

    It’s surprisingly annoying to get just the text content of an html element in a cross-browser friendly way. I wrote Element#getTextContent() to take care of this simple operation for me.

    The Prototype Version:

    Element.addMethods({
      /**
       *  Element#getTextContent(@element) -> String
       *  Cross-browser means of getting Element#textContent or Element#innerText
       **/
      getTextContent: function(element) {
        if (!Object.isUndefined(element.textContent)) {
          return element.textContent;
        }
        return element.innerText;
      }
    });
    

    The Procedural Version

    /**
     * Gets the text content of the specified element.
     * @param element {HTMLElement} The html element
     * @return {String} The string content of the specified element.
     */
    function getTextContent(element) {
      if (typeof element.textContent != "undefined") {
        return element.textContent;
      }
      return element.innerText;
    }
    

    Posted in Code/Projects, JavaScript | 6 Comments »

  • On the Challenge of Developing JavaScript Within a Team

    May 31st, 2009

    I find one of the most challenging aspects of developing JavaScript in a team environment is cracking open someone else’s code and being able to work with it as if it was my own. Within the scope of a programming language we tend, often subconsciously, to define our own dialect to describe the things we build. This dialect is expressed in the names we give to the classes, functions and variables within our applications. The position of an underscore, the use of verbs, nouns and adjectives, whether something is singular or plural — all of these things (and so much more) affect our understanding of the intent of the original developer.

    There can be vast differences between the dialects of two JavaScript developers on a single project, which is only amplified with each additional developer. Put together a team of five developers each working on different portions of the same application, or ten developers all working on various projects together, and without a set of coding standards and naming conventions, code quality and developer efficiency will quickly go down, replaced with a tangle of conflicting approaches that serve to undermine overall cohesion as developers inject their own dialect into the structures written in the dialects of other developers.

    As JavaScript is a dynamic language, naming conventions become even more important as almost everything can become anything else at any time; this means that part of our job as developers within a team is to encourage the correct use of what we create through the subtleties of naming conventions and standards.

    Aside: My biggest pet peeve is finding that a developer has named something “foo” in their application. Foo, an utterly meaningless word, describes nothing, and gives others absolutely no hint as to the purpose of that thing. The only way to figure out what “foo” might refer to is to follow that name back through the code, reading every single line, incrementally gaining insight into the intent of the original developer. Everything given a name should be named to expose the intent of that thing.

    Over the next week or so I’ll be sifting through my code in an attempt to codify my dialect of JavaScript. I hope to better understand my current approach and illuminate any shortcomings and inconsistencies. I’ll post an overview of what I find, along with code samples for illustration.

    Posted in JavaScript | 4 Comments »

  • Think you’re registered to vote?

    September 15th, 2008

    I just went to the Washington State Voter Registration website to check my voter information, and my status was set to inactive, and it listed me as not voting since 2006.

    This is frustrating because I was never informed that they had deactivated my voter status or given a reason as to why my status was changed. In addition to this, I’ve voted in every election between 2006 and now and never had a problem at my polling place. I have no way of knowing if my votes have been thrown out these past years.

    If you think that you are registered you might want to make sure:

    http://wei.secstate.wa.gov/OSOS/VoterVault/Pages/MyVote.aspx

    If there are any problems with your information, you can call King County Elections at 206 296 8683 (press 0 to talk to a human) an they can fix your information over the phone.

    Posted in Politics | Comments Off

Next Page »

Un-Dumbify