Thursday, April 23, 2009

Delicious Tech Tweets

Due to popular demand I have started to publish my Twitter tech tweets to my delicious profile.

The original intent of the tech tweets was to share current technology news with those that might be interested.

delicious I have had feedback from several individuals (@shanselman, @calvinb, @mallize) that delicious would be a good repository to complement my tech tweets so that someone could easily retrieve the links in the future.

If you are new to delicious, it is a social bookmarking service that allows you to post and share links to the world. You can learn more about it on delicious’ about page. There are some really useful tools to make this more worth your while.

twitterSo, with the addition of delicious I think I will cease to post the weekly Tech Twitterings blog post since the content should be much easier to locate on delicious.

Hopefully this can be a useful option for those that are interested in the tech tweets, but don’t want to follow me on Twitter because of the quantity of my tweets :)

I have started a program to post a delicious link as soon as my tweets get posted, but in the meantime there will be a slight delay between my tweets and when it gets posted to delicious.

What do you think about this change? Do you find the tech tweets useful? Do you have a delicious account?

Monday, April 20, 2009

Presenting jQuery Plugin Session at devLink Conference

Last month I submitting 6 sessions to this year's devLink Conference.

I recently found that they accepted the advanced session on 'How to create your own jQuery Plugin' that I had proposed.

Here is the session abstract for those of you who are interested...

How to create your own jQuery Plugin

There comes a time when the jQuery plugins currently available just don't meet your immediate needs. This session will show you how to go about creating your own plugin and will address key points you need to consider while making a plugin.
I've been to devLink for the past two years and it's definitely worth the time and money. It is a great chance to learn new concepts and to meet and share ideas with fellow geeks!

Here is some more information about the conference...
When
August 13 - 15, 2009
Reg. Opens
April 1, 2009
Reg. Closes
July 30, 2009 or until sold out (800 available)
Cost
Standard Ticket - $100
Where
Lipscomb University

Friday, April 17, 2009

JavaScript Unit Testing Part 2: JSSpec

In this post we will examine the 2nd of 4 JavaScript Unit Testing frameworks... JSSpec.

Previous parts of this series...

In subsequent posts we will cover QUnit, and YUI Test.

I like this Unit Testing framework a lot more than JsUnit for the following reasons...

  • As you can see from the screenshot below, it has a nice interactive Test Runner
  • The testing API has an easy to read Fluent Interface (a.k.a. It reads like English)
  • The project appears to still be active... the latest version was available on Sep 23, 2008
  • The test files don't need to be hosted in a web server in order to run (unlike JsUnit).

Ok, ok, enough talk. Lets get down to using this framework...

I added functionality to the nasty Pig Latin JavaScript to not only translate words, but also sentences.*

*Note: Yet again, this code is not optimal and it will be refactored in a future post.

function EnglishToPigLatin() {
    this.CONSONANTS = 'bcdfghjklmnpqrstvwxyz';
    this.VOWELS = 'aeiou';
    this.Translate = function(english, splitType) {
        var translated = '';    
        
        console.log('English: ', english);
        var words = english.split(/\s+/);
        console.log('Split Words: ', words);
        for (var i = 0; i < words.length; ++i) {
            console.log('Word ', i, ': ', words[i]);
            translated += this.TranslateWord(words[i]);
            if (i+1 < words.length) translated += ' ';
        }
        console.log('Translated: ', translated);
        console.log('----------');
        
        return translated;
    }
    this.TranslateWord = function(english) {
       /*const*/ var SYLLABLE = 'ay';

       var pigLatin = '';
          
       if (english != null && english.length > 0 && 
          (this.VOWELS.indexOf(english[0].toLowerCase()) > -1 || this.CONSONANTS.indexOf(english[0].toLowerCase()) > -1 )) {
          if (this.VOWELS.indexOf(english[0].toLowerCase()) > -1) {
             pigLatin = english + SYLLABLE;
          } else {      
             var preConsonants = '';
             for (var i = 0; i < english.length; ++i) {
                if (this.CONSONANTS.indexOf(english[i].toLowerCase()) > -1) {
                   preConsonants += english[i];
                   if (preConsonants.toLowerCase() == 'q' && i+1 < english.length && english[i+1].toLowerCase() == 'u') {
                      preConsonants += 'u';
                      i += 2;
                      break;
                   }
                } else {
                   break;
                }
             }
             pigLatin = english.substring(i) + preConsonants + SYLLABLE;
          }
       }
       
       return pigLatin;    
    }
} 

Like I said before, JSSpec provides a nicer Fluent Interface that makes the tests read more like English. The follow are several sets of Unit Tests to exercise the existing functionality, plus the new feature I added since the last post.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ko">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<title>JSSpec results</title>
<link rel="stylesheet" type="text/css" href="JSSpec.css" />
<script type="text/javascript" src="diff_match_patch.js"></script>
<script type="text/javascript" src="JSSpec.js"></script>
<script type="text/javascript" src="PigLatinBad.js"></script>
<script type="text/javascript">// <![CDATA[
describe('Invalid Arguments', {
    before_each : function() { englishToPigLatin = new EnglishToPigLatin(); },
    'Passing Null Should Return Blank': function() {
        value_of(englishToPigLatin.TranslateWord(null)).should_be('');
    },
    'Passing Blank Should Return Blank': function() {
        value_of(englishToPigLatin.TranslateWord('')).should_be('');
    },    
    'Passing 1234567890 Should Return Blank': function() {
        value_of(englishToPigLatin.TranslateWord('1234567890')).should_be('');
    },
    'Passing ~!@#$%^&*()_+ Should Return Blank': function() {
        value_of(englishToPigLatin.TranslateWord('~!@#$%^&*()_+')).should_be('');
    }    
})

describe('Consonant Words', {
    before_each : function() { englishToPigLatin = new EnglishToPigLatin(); },
    'Passing Beast Should Return Eastbay': function() {
        value_of(englishToPigLatin.TranslateWord('beast')).should_be('eastbay');
    },
    'Passing Dough Should Return Oughday': function() {
        value_of(englishToPigLatin.TranslateWord('dough')).should_be('oughday');
    },
    'Passing happy Should Return appyhay': function() {
        value_of(englishToPigLatin.TranslateWord('happy')).should_be('appyhay');
    },
    'Passing question Should Return estionquay': function() {
        value_of(englishToPigLatin.TranslateWord('question')).should_be('estionquay');
    },
    'Passing star Should Return arstay': function() {
        value_of(englishToPigLatin.TranslateWord('star')).should_be('arstay');
    },
    'Passing three Should Return eethray': function() {
        value_of(englishToPigLatin.TranslateWord('three')).should_be('eethray');
    }
})

describe('Vowel Words', {
    before_each : function() { englishToPigLatin = new EnglishToPigLatin(); },
    'apple Should Return appleay': function() {
        value_of(englishToPigLatin.TranslateWord('apple')).should_be('appleay');
    },
    'elijah Should Return elijahay': function() {
        value_of(englishToPigLatin.TranslateWord('elijah')).should_be('elijahay');
    },
    'igloo Should Return iglooay': function() {
        value_of(englishToPigLatin.TranslateWord('igloo')).should_be('iglooay');
    },
    'octopus Should Return octopusay': function() {
        value_of(englishToPigLatin.TranslateWord('octopus')).should_be('octopusay');
    },    
    'umbrella Should Return umbrellaay': function() {
        value_of(englishToPigLatin.TranslateWord('umbrella')).should_be('umbrellaay');
    }    
})

describe('Sentences', {
    before_each : function() { englishToPigLatin = new EnglishToPigLatin(); },
    "Passing 'hello' Should Return 'elloh'": function() {
        value_of(englishToPigLatin.Translate('hello')).should_be('ellohay');
    },
    "Passing 'hello world' Should Return 'elloh orldw'": function() {
        value_of(englishToPigLatin.Translate('hello world')).should_be('ellohay orldway');
    },
    "Passing 'hello world!' Should Return 'ellow orld!w'": function() {
        value_of(englishToPigLatin.Translate('hello world!')).should_be('ellohay orld!way');
    },
    "Passing 'Hello World' Should Return 'elloH orldW'": function() {
        value_of(englishToPigLatin.Translate('Hello World')).should_be('elloHay orldWay');
    },    
    "Passing 'Hello World!' Should Return 'elloH orld!W'": function() {
        value_of(englishToPigLatin.Translate('Hello World!')).should_be('elloHay orld!Way');
    }
})
// ]]></script>
</head>
<body><div style="display:none;"><p>A</p><p>B</p></div></body>
</html>

There are other asserts that can be made that I didn't make use of in the above same. Here are some examples... (taken from the JSSpec Manual)

  • value_of('Hello'.toLowerCase()).should_be('hello');
  • value_of([1,2,3]).should_be([1,2,3]);
  • value_of(new Date(1979,03,27)).should_be(new Date(1979,03,27));
  • value_of([]).should_be_empty();
  • value_of(1 == 1).should_be_true();
  • value_of(1 != 1).should_be_false();
  • value_of("Hello").should_have(5, "characters");
  • value_of([1,2,3]).should_have(3, "items")
  • value_of({name:'Alan Kang', email:'jania902@gmail.com', accounts:['A', 'B']}).should_have(2, "accounts");
  • value_of([1,2,3]).should_have_exactly(3, "items");
  • value_of([1,2,3]).should_have_at_least(2, "items");
  • value_of([1,2,3]).should_have_at_most(4, "items");
  • value_of([1,2,3]).should_include(2);
  • value_of([1,2,3]).should_not_includ
  • value_of({a: 1, b: 2}).should_include("a");
  • value_of({a: 1, b: 2}).should_not_include("c");

As you can see, this is a very powerful easy to read and execute testing framework. Of those frameworks I have tested thus far, I recommend it above the others (at this point I've only covered JsUnit).

Wednesday, April 15, 2009

My First Podcast Interview

A good friend of mine, Tanton Gibbs (@tgibbs), from Microsoft has started a new Podcast series called New Tech Cast.

In these podcasts, I'm going to be interviewing up and comers in the software development world. These industrious developers will have their fingers on the pulse of today's tech and should provide great insight into the things to come.

I was flattered to be chosen for his first Podcast interview. In the podcast we discussed my history, various technologies that I use (ASP.NET MVC, jQuery, etc...), and a variety of other things.

You can download and listen to the podcast on his new website.

Tuesday, April 07, 2009

JavaScript Unit Testing Part 1: JsUnit

In this post we will examine the 1st of 4 JavaScript Unit Testing frameworks... JsUnit.

In subsequent posts we will cover JSSpec, QUnit, and YUI Test.

First of all, lets define some JavaScript code that we want to Unit Test. I wrote the following Pig Latin JavaScript utility for the sole purpose of this Unit Testing series…

*Note: I am aware the code needs to be refactored. We will address that in a future blog post :) 

/*const*/ var CONSONANTS = 'bcdfghjklmnpqrstvwxyz';
/*const*/ var VOWELS = 'aeiou';

function EnglishToPigLatin(english) {
   /*const*/ var SYLLABLE = 'ay';

   var pigLatin = '';
      
   if (english != null && english.length > 0 && 
      (VOWELS.indexOf(english[0]) > -1 || CONSONANTS.indexOf(english[0]) > -1 )) {
      if (VOWELS.indexOf(english[0]) > -1) {
         pigLatin = english + SYLLABLE;
      } else {      
         var preConsonants = '';
         for (var i = 0; i < english.length; ++i) {
            if (CONSONANTS.indexOf(english[i]) > -1) {
               preConsonants += english[i];
               if (preConsonants == 'q' && i+1 < english.length && english[i+1] == 'u') {
                  preConsonants += 'u';
                  i += 2;
                  break;
               }
            } else {
               break;
            }
         }
         pigLatin = english.substring(i) + preConsonants + SYLLABLE;
      }
   }
   
   return pigLatin;
}

Next we need to define a set of Unit Tests using JsUnit. I am using JsUnit 2.2 Alpha 11 for this example.

In order to create the Unit Tests we need to know the business rules for the Pig Latin method…

  1. In words that begin with consonant sounds, the initial consonant or consonant cluster or diagraph is moved to the end of the word, and "ay" is added…
  2. In words that begin with vowel sounds or silent consonants, the syllable "ay" is added to the end of the word. In some dialects, to aid in pronunciation, an extra consonant is added to the beginning of the suffix.

Now that we know the rules, lets start making some Unit Tests…

<html>
 <head>
   <title>Test Page for EnglishToPigLatin(english)</title>
   <link rel="stylesheet" type="text/css" href="../css/jsUnitStyle.css">
   <script language="JavaScript" type="text/javascript" src="../app/jsUnitCore.js"></script>
   <script language="JavaScript" type="text/javascript" src="./PigLatin.js"></script>
 </head>
 <body>
  <script language="javascript">
   function testPassingNullShouldReturnBlank() {
      assertEquals('null returns a blank', '', EnglishToPigLatin(null));
   }
    
   function testPassingBlankShouldReturnBlank() {
      assertEquals('blank returns a blank', '', EnglishToPigLatin(''));
   }
  
   function testConsonantBeastShouldReturnEastbay() {
      assertEquals('beast returns eastbay', 'eastbay', EnglishToPigLatin('beast'));
   }   
  
   function testConsonantDoughShouldreturnOughday() {
      assertEquals("dough returns oughday", 'oughday', EnglishToPigLatin('dough'));
   }
  
   function testConsonantHappyShouldReturnAppyhay() {
      assertEquals("happy returns appyhay", 'appyhay', EnglishToPigLatin('happy'));
   }        

   function testConsonantsQuestionShouldReturnEstionquay() {
      assertEquals("question returns estionquay", 'estionquay', EnglishToPigLatin('question'));
   }
    
   function testConsonantsStarShouldReturnArstay() {
      assertEquals("star returns arstay", 'arstay', EnglishToPigLatin('star'));
   } 
    
   function testConsonantsThreeShouldReturnEethray() {
      assertEquals("three returns eethray", 'eethray', EnglishToPigLatin('three'));
   }

   function testVowelAppleShouldReturnAppleay() {
      assertEquals("apple returns appleay", 'appleay', EnglishToPigLatin('apple'));
   }
    
   function testVowelElijahShouldReturnElijahay() {
      assertEquals("elijah returns elijahay", 'elijahay', EnglishToPigLatin('elijah'));
   }
    
   function testVowelIglooShouldReturnIglooay() {
      assertEquals("igloo returns iglooay", 'iglooay', EnglishToPigLatin('igloo'));
   }
    
   function testVowelOctopusShouldReturnOctopusay() {
      assertEquals("octopus returns octopusay", 'octopusay', EnglishToPigLatin('octopus'));
   }
    
   function testVowelUmbrellaShouldReturnUmbrellaay() {
      assertEquals("umbrella returns umbrellaay", 'umbrellaay', EnglishToPigLatin('umbrella'));
   }
    
   function testPassingNumberShouldReturnBlank() {
      assertEquals("1234567890 returns blank", '', EnglishToPigLatin('1234567890'));
   }

   function testPassingSymbolsShouldReturnBlank() {
      assertEquals("~!@#$%^&*()_+ returns blank", '', EnglishToPigLatin('~!@#$%^&*()_+'));
   }
    </script>
 </body>
</html>

There are several different types of asserts that JsUnit supports...

  1. assert([comment], booleanValue)
  2. assertTrue([comment], booleanValue)
  3. assertFalse([comment], booleanValue)
  4. assertEquals([comment], value1, value2)
  5. assertNotEquals([comment], value1, value2)
  6. assertNull([comment], value)
  7. assertNotNull([comment], value)
  8. assertUndefined([comment], value)
  9. assertNotUndefined([comment], value)
  10. assertNaN([comment], value)
  11. assertNotNaN([comment], value)
  12. fail(comment)

JsUnit has a testRunner to execute all of your Unit Tests. If all is well, your status bar will be green. If any asserts failed, they will be displayed in a list control where any assert comment can be retrieved

testRunner

Overall, JsUnit is a decent Unit Testing framework for JavaScript. You can also bundle tests into suites and run multiple suites. As most testing frameworks, you can also use setUp() and tearDown() methods to prepare the environment for each test method.

Thursday, April 02, 2009

3 Biggest Software Lies

I ran across the following quote today and thought it was pretty funny…

3 Biggest Software Lies:

  1. The program’s fully tested and bug-free
  2. We’re working on the documentation
  3. Of course we can modify it!

Do you have any other items to add to the above list? If so, please share them in the comments :)