Desert Code Camp and Desert Code Camp Jr

In the past few years, I've been privileged to learn and network at Desert Code Camp.  When I jumped the fence to teach, it was an honor to learn from y'all as I shared the skills you'd taught me previously.  Many years ago, I began by teaching an intro to CSS and a team-taught SVN class.  Last code camp, I taught Thinking in JavaScript, Intro to jQuery, and Advanced jQuery including building plugins and animations.  I also got to learn about ASP.NET MVC, programming usb gadgets, and unit testing JavaScript -- to name a few.  It was a blast.

For anyone who's not taught the skills and talents you have, take the opportunity to do so.  It is well worth the effort and the skills you develop are invaluable.  Imagine how confident you'll be in the next job interview when you notice the same stage fright that quickly passes when teaching a room full of peers can also dissipate just as fast when you're getting grilled by a potential colleague.  And imagine the awesome resume tick and skill justification when you can document that not only do you have x years doing it, but that you taught it to a crowded room of your peers.

But I digress.  This year I'm taking a different path with Desert Code Camp.  My son often comes with me to Users' Group meetings -- mostly for the 1-on-1 time with me as we drive and the free pizza and stickers.  (At the conclusion of an evening 6 months or so ago, with his collection of treasured swag in hand, he said to me, "Dad, there's a lot of stickers in programming."  :D)  Each of the recruiters also engage him a bit each time, and I'm sure if he played his hand right, he could find an awesome job in 5 or 10 years.  Today, he does pretty well in DreamWeaver if I jump in with hard stuff and "how do you spell ...?" from time to time.  His site is robrich.org/mark.html.  He created the concept when he was 4 as a way to keep track of his favorite sites without the need to ask me where the letter H was on his keyboard every time.  For a 4-year-old, the problem's solution was brilliant!  Lately he's been asking to learn more about the guts of how it works -- hardware, software, marketing, and finance.  An eager mind like his is such a treasure.

Thus, this year, I'm not attending Desert Code Camp as a learning and teaching and networking opportunity.  This year, it will all be about my son.  Desert Code Camp Jr is a trek slated for kids "ages 4 to 18".  (In my opinion, kids over  13 or 15 or so will probably want to take -- or teach -- the other classes though.)  We'll learn about MIT's Scratch -- drag-drop programming for kids, programming Lego Mindstorms, and we'll learn about circuits.  Lunch is generously provided by GangPlank.  Mark explained to me he wants to give me some time to go to a grown-up class too, though I'll defer to him once the excitement kicks in.  The way they've structured it with a small instruction period up front and then a generous experimentation and play time afterward for each topic will be perfect for developing skill and creativity in these bright young minds.

Thus, if you were looking for the Continuous Integration class or the Unit Testing with TypeMock and Ivonna class I hyped, or an encore performance of the Advanced jQuery class, you'll have to wait until next year.  This year, I get to be Dad -- the greatest honor I could imagine.

Rob

Continuous Integration

It's my pleasure tonight to present Continuous Integration: best practices, methodologies, and tools at the SEVDNUG.  Continuous Integration is the process of rebuilding the code in its entirety periodically and automating awkward deployment processes to create a more consistent product.  Tonight we discussed these business cases, the tools and techniques available, and best practices to use when implementing a continuous integration process.

It isn't difficult to get an automated build going.  Really the most difficult part is getting a one-line command to build it.  Be it batch files, calling Visual Studio's command line, or NAnt or MSBuild tasks, once you've got a command-line build, rigging it to a Continuous Integration service like CruiseControl.NET is easy.  Once you can automate this code verification, you'll immediately see benefits in decreased time chasing what broken and who broke it.

The slides and code are available here. CruiseControl.NET is available here, NAnt is available here, and NAntContrib is available here.

** NOTE: For some strange reason, my server wants to gzip zip files when it downloads them, leading to a double-compressed file. If you're downloading the zip files in IE, it'll tell you the file is corrupt. The fault is totally mine, but the file is not corrupt. If you download the file with FireFox, it will come down just fine. If you're an IIS guru and know how to disable gzipping zipped content while enabling gzipping for non-zipped content, please let me know. **

Testing: Methodologies, Best Practices, and Tools

I had the privilege to speak at the SEVDNUG yesterday about Testing. When we typically think of "Testing", we usually use the term "Unit Testing", yet we usually mean "Integration Testing" or "Functional Testing". This was definitely not a demo on how to use NUnit, but rather a specific look at the reasons for testing, the best practices for writing tests, and a look at popular and obscure tools to facilitate the task.

During the presentation, we looked at many tools: NUnit, TestDriven.NET, Resharper's test runner, TypeMock, Selenium, Ivonna, NUnit's RowTest TestCase (I still think 'RowTest' is more descriptive than 'TestCase', and I'm still annoyed I had to update all my code when I switched to NUnit 2.5. Find/Replace is a wonderful tool though.)

One of the coolest things is that the goal of writing tests is so you spend less time debugging. Quite honestly, I'd rather write code than debug code any day. The key though is knowing what to test. Testing the .net framework or your database connection string is probably not the wisest use of your time. Testing that your business logic works the way you think it does is definitely a good way to keep bugs out of your code. To the depth that you can make the testing process seamless in your development, it can become an invaluable tool. Testing is an up-front investment that yields a long-tail benefit in improved code quality. If you can afford the investment, it's well worth it.

One of the coolest points that came out during the discussion was using your suite of tests as documentation, new developer training, etc. If your tests are run frequently and encompass the bulk of your code, that's where the best definitions of your business logic reside. What an awesome idea.

The slides and code are available here. If you're going to use the TypeMock and Ivonna content, you'll need to download trial licenses from here. All the other tools we discussed are open-source or free.

** NOTE: For some strange reason, my server wants to gzip zip files when it downloads them, leading to a double-compressed file. If you're downloading the zip files in IE, it'll tell you the file is corrupt. The fault is totally mine, but the file is not corrupt. If you download the file with FireFox, it will come down just fine. If you're an IIS guru and know how to disable gzipping zipped content while enabling gzipping for non-zipped content, please let me know. **

Desert Code Camp Sessions

Yesterday we had an awesome time at Desert Code Camp learning from each other and sharing ideas with each other. I got to present 3 sessions during the day, and here are the slides to each:
** NOTE: For some strange reason, my server wants to gzip zip files when it downloads them, leading to a double-compressed file. If you're downloading the zip files in IE, it'll tell you the file is corrupt. The fault is totally mine, but the file is not corrupt. If you download the file with FireFox, it will come down just fine. Since you'll need FireFox to use FireBug, you'll be just fine. **

Thinking in JavaScript: This is an awesome introduction to what makes JavaScript different from other C-Style languages such as C#, Java, C/C++, Perl, etc. There are a few differences you need to understand, and with those in mind, you can leverage your existing skills in this new world with ease.

Intro to jQuery: In this session, we look at the most common use of jQuery -- picking something, then doing something with each item selected. For example: $("p").css("background-color","#cccccc"); In that single line, we're able to search through the entire dom for all <p> tags, and set their background-color to gray. 1 line. That's awesome. We also briefly summarize some of the other stuff you get for your 26k now only 19k library script inclusion: AJAX, Animation, Traversing and modifying the dom, etc.

jQuery Deep Dive: Here we briefly reviewed the "pick something, then do something with each" techniques. Then we dive right in with AJAX: using GET and POST to retrieve content, sending parameters in the query string or as post parameters, techniques to call ASP.NET AJAX web services and page methods -- without a ScriptManager on the page, built-in jQuery animation, how use and build plugins, and how to interact with server-side controls and page life cycle. By the time we were done with all that, we were definitely ready for lunch.

Desert Code Camp is a great opportunity for coders of all skill levels and all technology backgrounds to share and learn.  I thank you for the opportunity to learn with you.  See you at the next Desert Code Camp.

"Command Prompt" in Windows Explorer Context Menu

There's a great power-toy for adding "Command Prompt" to the Windows Explorer context menu in XP here (or search for XP Power Toys). In Vista and Server 2008, you just hold shift when you right click to get it -- built in. But what if you're on Windows Server 2003 or another version? Well, the technique to add it is just a simple registry change:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\Command_Prompt]
@="Command Prompt"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\Command_Prompt\command]
@="cmd.exe /k pushd \"%1\""

Copy the above into a reg file (such as "Command Prompt Here.reg" -- no quotes) or similar, double-click to merge it, and you've got a Command Prompt selection in Windows Explorer's context menu. Easy as pie. If you want to "uninstall" it, open up RegEdit, navigate to that key, and delete it. Changes take effect imediately.

Note: some have reported this syntax brings up an error. If cmd.exe isn't in the PATH, this will utterly fail. In some cases I've had success with changing the command to be @="cmd.exe \"%1\"". In some cases, that utterly fails too. Your mileage may vary, batteries not included, don't use this product while sleeping on a curling iron or driving in traffic.

And to take it a step further, I modified the command name to "Command Prompt x86" and the command to "C:\Windows\SysWoW64\cmd.exe \"%1\"" and imported into a new key name, and I now have a 32-bit command prompt in the pop-up too.

(Now hopefully I won't forget it again.)

jQuery demo at SEVDNUG

It was a blast to present deeper concepts of jQuery at the SEVDNUG this evening. We enjoyed discussing ajax in jQuery, calling web services and page methods, building and using plugins, animation, and general best practices for JavaScript. The content from the demo can be found here. Note that because of a server misconfiguration, the file will come down double-zipped. Firefox seems to download the file just fine, while IE seems to choke every time.

For quick reference as well, here's the contents of the Resources page:

Tools

Learning and Reference Material

jQuery Plugins

FAQ

IoC: What is it and why do I care?

It finally sank into my melon why Dependency Injection, Inversion of Control, and IoC Containers exist. The 'a-ha' moment came, and I wanted to share it. Here's my "explain it to your mom" definition of IoC Containers, and the back-story to make it make sense. First, we start with bugs ...

Bugs: These are when a program malfunctions. They aren't good. An abundance of bugs means the program is broken, and users are grumpy.

Trying to solve bugs more proactively leads us to ...

Unit Testing: Automated testing of software leads to catching and solving bugs faster. Unit testing specifically involves testing a small piece of the program in isolation -- away from all other parts of the program. More generally, the term "testing" is used to mean testing the application, its parts, its functions, interaction between parts, access to external resources (a database, a web service, etc). Testing code frequently and automatically leads to better code because bugs are exposed by tests, not by users.

Unit Testing highlights inconsistent object initialization. When I create a new transaction, I need to set the date, set the customer, set the product, and verify all these exist. That seems to fundamentally go against the nature of Object Oriented development: Polymorphism, Inheritance, and Encapsulation. The other two aren't important to this discussion, but Encapsulation is.

Encapsulation: Encapsulation is hiding the grunt of the task behind a simpler skin. "Yes, I know to wash the car, you need to get it wet, rub soap on it, scrub, rinse, dry, wax, etc. I just want to call Car.Wash() and you figure out the details." This is encapsulation.

There are many ways to encapsulate awkward code, but for this discussion we'll discuss encapsulating object creation. Encapsulation of object initialization is solved via ...

Factory Pattern: In the Factory Pattern, object initialization is done in a central place for each type of object. When you want a Car object, you call the CarFactory, pass it parameters, and it returns a fully initialized car. Initialization is done centrally in the Factory method, so object initialization is always uniform and complete.

During testing, you have to test lots of permutations of sequential behaviors that may depend on external resources that are slow. For example, consider a test to see if a recent transaction query only grabs transactions within 7 days. To test this, you need some transactions older than 7 days ago and some newer than 7 days ago. If your TransactionFactory is coded to create all transactions as "right now", you can't exactly wait around 7 days for your unit test to finish. In a less obscure example, say you are trying to verify a calculation, but the database query used to populate the calculation is slow. What you need is the ability to alter these dependencies during a test. This leads to ...

Dependency Injection: Dependency Injection is the process of telling an object what its dependencies are. If you're creating transactions on a variety of dates, and the Factory marks every new transaction as "today", you may want to specify what "today" means to the Factory during a test. In the real program, "today" will always mean "right now". But during the test, "today" needs to match the scenario we're testing to make sure the program functions correctly.

Dependency Injection is also really handy if the unit you're testing depends on other things which are slow -- for example a database or a web service. If these things take seconds or minutes to return the requested resource, a single test takes at least as long. If we have many such tests -- or groups or suites of these tests -- the tests will be said to "take too long to run", so they won't be run often. A test that isn't run doesn't find bugs, thus doesn't serve its purpose. This dilemma leads us to ...

Mocking: Creating a mock (fake) object that behaves in a predictable way is a great way to "fake-out" an external resource with a faster "work-alike" counterpart. If the GeoLocation service takes too long to return, and we've proven (through another test) that it always returns the same answer when we ask for a specific location, we may not want to flex that resource to calculate the distance between a customer and a delivery location. Instead, we can create a mock web service that always answers correctly instantaneously. This mock object stands in for the real, expensive resource during a test. The mock object is injected into place via Dependency Injection.

When you've got mock objects in the mix, the Factory's object initialization parameters can get pretty intense. Not only do I need to specify the make & model of the car I want built, I also need to specify which database you get it from (the real one or the mock object), maybe what "today" means for initializing the waranty, and maybe I also need to specify other external resources such as the GeoLocation service strategy for how to find the car. This initialization puts a heavy burden on the other parts of the program that use this code. Mocking via Dependency Injection and hiding details of execution through Encapsulation seem to be fundamentally at odds, which leads us to ...

IoC Container: Inversion of Control (IoC) -- is a methodology of injecting dependencies through a centralized Factory for all objects in the application. The IoC container typically has a method like Resolve() or Create() or Get(). You pass it details of what you want, it makes an object in its centralized factory, and hands it back. The benefit to being centralized is not only does it know how to make your object, but it knows how to make many objects. If your object requires external dependencies, it can find and create those, and inject them in as it creates your object.  You need not worry about these details.

The IoC Container is an uber object Factory that centrally creates all objects, and recursively resolves Dependency Injection requirements of those objects while encapsulating this complexity from consumers of these objects.

If you're in the middle of a unit test, and you need to adjust what "today" means, you configure the IoC Container, and all objects that need it get it. But the code that wants the object doesn't need to know any of this. It doesn't need to know if it's in the middle of a test or not. It doesn't even need to know if the database is real or the data its working on is real.  It just says to the IoC container, "Give me an object that is ..." and poof, there it is.

IoC Container methodology is awesome, as it empowers:
  • consistent initialization through a central factory
  • dependency injection to allow mock objects to stand in for computationally expensive objects during tests
  • consuming classes need not resolve dependencies to use objects
IoC is awesome. It is hardly the magic bullet though. The nature of the IoC Container is it must know how to resolve all the initialization of all the objects in the application. To do this effectively, it must be configured to know all the dependencies it needs to inject, to know which object to return when asked for an interface, how to instantiate and initialize everything, and all this in a generic, maintainable way. This configuration is key. You're specifying, "When you're asked for a 'car' that is 'red', go create it like this, initialize its dependencies like this, etc." Beefy IoC container libraries will allow you to return the Singleton instance of an object created previously, a new object, a cached object (if it exists), etc.

Traditionally, IoC configuration comes in two ways. I haven't found any compelling reason to choose one over the other as both are not that great: create the map in code or in a configuration file.

Code is great as you get compile time support for it. If you change the name of a class, the IoC configuration breaks until you also change it. (Or the refactor tool does it for you.) But on the other hand, it takes a recompile to change your mind.

A configuration file is easily changed, but it's fragile. Generally, you have to specify the full object namespace and type name, maybe even the library name and/or path it came from. And all this without intellisense, compile-time checking, or even spell checking.

So, that's what IoC is. It isn't the magic bullet, but it can sure make unit testing much more effective. To sum it up, my 'a-ha' "to my mom" definition of IoC is:

The IoC Container is an uber object Factory that centrally creates all objects, and recursively resolves Dependency Injection requirements of those objects while encapsulating this complexity from consumers of these objects.

(no, my mom didn't get it either.)

Rob

iPhone and Google Maps

I've gotten quite a bit more feedback than I anticipated about my prior post about Google Maps and the iPhone. Who would've thought that not being able to mash up live GPS data, maps, and one or more external files of geographic data in a generic, consumer-driven way would be such a stir?

Since then, I've made some progress on this rant.
  • LocWidget: this handy iPhone app allows you to send Latitude, Longitude, and Altitude measurements as query parameters to a website of your choosing. It also takes it a step further, sending the phone's unique id. (Great for those dispatch apps we are barred from creating.) The great part: it gets the data to a website in a way that any site developer can consume. The bad part: you gotta keep launching the app to get anything done.
  • Alocola: this is another handy iPhone app that registers the url prefix "alcola://" in iPhone's Safari. The great part: now the site can request the location, the user is prompted to agree, and the GPS data is passed to the url as query string parameters. In theory, this url could be triggered by a JavaScript timer. The bad part: the user has to click ok every time, and it closed and reopened safari as it sped through the app. I'm not positive, but I'd think it would open a new browser window on each run. In short order, if called periodically from a web app, you'd max out the 6 safari tabs. And not to mention you're reloading the page on each round trip through GPS land. The author has made the source available under GPL2 license, so in theory one could cache the "yes, do this" the way other apps do, register a more natural prefix (like gps://), and other nicities.
These are both great steps forward, but don't fundamentally solve the problem at hand. What I want is:
  1. Per domain permanent acceptance to use location services like I can per app now
  2. Live GPS data and external KML can mix in a central, standard place, without changing applications
I see this could get solved easily in one of two ways. Either
  • Provide a field in the Google Maps app for "url of a KML file" (or maybe access to Google's "My Maps")
Or
  • Provide a JavaScript function in Safari to get location data
I realize the GPS Browser functionality is to come with HTML 5. Will HTML 5 become spec before or after 802.11n gets ratified?
Yeah, I know, dream on. Flash isn't coming to the iPhone in this millennia. Neither is copy & paste. Or even a system-wide "switch to landscape" keyboard for those of us with hands bigger than my kindergartner. Next I'll dream of having Mono or Silverlight on the iPhone. Or wilder still, it prompts me to allow location services on each request, but there's no firewall to block a game from uploading my high score, date & time, and possibly my phone number or phone guid to it's service on every game-over. ("I'm really thrilled I just got a high score, but I don't need to publish to all the world my phone data so you can bombard me with even more targeted ads while I play, thank you very much.")

But if you're watching, Steve, and if it isn't too much to ask, can you give me the ability to do real time GPS / KML mashups? Either in the Google Maps iPhone app or in Safari is fine. And I'll forget I even mentioned those silly terms like "Flash" or ".NET" or "copy & paste".

Rob

"Oh duh": Google Maps and iPhone

Google Maps is awesome.  It is phenomenally cool.  It is the quintessential definition to many of what is Web 2.0: a very dynamic, very interactive, very usable site that presents what I want in a way I want it right now, lets me use it intuitively, and publish it to anywhere else easily.  Some may argue Google Maps is the reason cell phones now have GPS's in them: for turn-by-turn directions based on map data downloaded to the phone on demand.

Google Maps is also the quintessential example of a mashup: take two unrelated services, push them together, and you've got something incredibly new and cool.  Take presidential election results and geolocate voter preferences.  Take restaurant reviews and show me how close I am to them.  Take driving directions to the next level by overlaying speed trap markers.  It is awesome.  And the Google Maps API makes it drop-dead simple to do this in JavaScript, static images (with really long urls), or Flash.  I'm a happy camper.

In the other corner is the iPhone.  It is an awesome piece of engineering and elegance.  It is the new standard for what a phone should do.  It's touch screen interface is the standard by which all PDAs are judged going forward.  It's simple user navigation is awesome.  It's "always within reach" browser is awsesome.  (Sometimes when I'm upstairs and want to quickly look something up, I won't bother going all the way downstairs to the computer.  I'll pop out the iPhone and get on the net.)  Stop by the App Store or Cydia and download just about any kind of app from "keep my kids busy while I just quickly finish up ..." to "are there any wireless networks open here?" to "lemmie quickly RDP / VNC into that machine over there and ..."  And all that "in your pocket", instantly available anywhere, at the push of a button is awesome.

The iPhone takes Google Maps to the next level too: you can search for a restaurant name or genre, pan around the map, and see things close to you.  You can pick a contact from your address book, and get directions from "where I am right now" (thanks GPS) to their street address.  As you're driving, you can watch the little blue blinking ball dance accross the map in unison to your driving.  It's incredibly marvelous engineering feats behind the scenes, and incredibly simple to use.  Cudos to both Google and Apple.  Awesome.

Here's the rub: iPhone Google Maps mashups.  They don't exist.  They can't.  Google Maps app for the iPhone is crafted by Apple.  It is not JavaScript, not Flash, not static images with cryptic urls.  It's an app.  Ok, granted, there is an iPhone app to show me speed traps.  An iPhone app to geolocate stuff "around me" -- restuarants, theatres, etc.  I can download 1000 iPhone apps to map various things.  They're cool.  They're also seperate applications.  If I want to both see route information and see the speed traps on 1 map, I'm screwed ... unless the app developer implimented everything and it's dog.

The speed trap app is a great example.  I think they call it trapster.  I can see my current location, I can see speed traps identified by others using this service.  I can mark ones I find when I'm sitting by the side of the road with blinky lights in my rear view mirror.  It's like driving in a video game.  It's awesome.  But the developer didn't impliment screen jestures for navigating the map.  I can't pinch to zoom out or in, I can't swipe the screen sideways to move.  I have to use the little joystick controls on the bottom control bar.  And I definately can't put in my destination address and see the route of how to get there.  Or where the closest ATM is that supports my bank's card.  Or if any of my address book contacts live nearby.

Around Me is another awesome app that shows me restaurants, theatres, etc, around me.  (Not that I have time to use any of them, but that's another mater.)  But what if I want directions to there?  Sorry, that's in the other maps app.

"Ok," so I say to myself.  "I'm a 1/2 descent web user.  I'll just use the real Google Maps website for my mashups."  That's all fine and good except ... now I'm in app #3: Safari.  That has no Flash plugin, by the way.  And (in theory) any url that contains map information is automatically grabbed by the phone and routed to the Google Maps app.  And it doesn't have my GPS info, so I have to keep track of my current location by manually panning around as I drive.

I came to the awful conclusion at the end of this mental journey that the iPhone's Google Maps app is incredibly cool.  But it fundamentally defeats the purpose: today's internet is about mashups.  Combining data in interesting ways.  And I can't do that with any map data, a target destination, and my current location from my iPhone with Google Maps.  "Oops."

jQuery - LINQ to JavaScript

I had the privilege of presenting jQuery at Desert Code Camp today.  jQuery is the do more, write less JavaScript library.  Because it runs client-side, it can be used easily with any server framework.  There's nice support for intellisense in Visual Studio 2008 as well (with a bug-fix update).

jQuery basically breaks down into two operations: picking things, and doing something with those things.  Picking things is done via a CSS / XPath strign describing the DOM nodes you want to do.  This returns an array of DOM elements (wrapped nicely in a jQuery object) that get passed into each of jQuery's 'do it' functions.  It becomes trivial to change css on all items, change the innerHTML, append DOM elements, even do AJAX and visual effects.  What's best: this whole process usually takes about 20 characters -- very small, very clean, very nice.

The slides from the content can be found here.  We generated all the code we saw on the fly inside FireBug.  Enjoy!

Rob