Monthly Archives: December 2014

Take Your Test Driven Development Bowling, … Take it Bowling

In case you are wondering, the title is a take on this song, Camper Van Beethoven – Take The Skinheads Bowling. It’s a stretch, I know but I found it funny.

In a previous post I mentioned how much of a fan I was Uncle Bob Martin’s books, Clean Code and Clean Coder. In Clean Coder Martin talks about coding kata. The word kata is taken from martial arts and is a form of practicing moves in a systematic and repetitive manner, until muscle memory is developed, so that successful techniques in martial arts become instinctive.  So the idea behind code kata is the same.  Practice common patterns and best practices in a deliberate, systematic, and repetitive manner so that when writing production code the best practices and common patterns are instinctive.

One kata that I found very helpful for Test Driven Development (TDD) is the Bowling Game Kata.  The kata is actually defined in a PowerPoint presentation that is linked at the beginning of Martin’s article, so be careful not to miss it.  The reason I find this kata so helpful is because I have not been fortunate enough to work in an organization with significant discipline around writing unit tests and I especially like the idea behind TDD.  In the Bowling Game Kata Martin takes the practitioner through the steps of writing code in a TDD manner.  I also think a subtler point in this kata is that you also get an idea of how Martin refactors code continuously in order to achieve “clean code”.  And the “safety net” that ensures the continuous refactoring does not break the functional requirements of the code are the unit tests, which are created first, before the code the tests are meant to validate is even written.

Also not that the results of this kata have any real value, (In this particular case it really is the journey that matters and not the destination.), but I have the source code on my GitHib account as well if you are interested.  Bowling Game Kata

I hope you found this helpful and if you are looking for more code kata a Google search will turn up quite a few resources but here are a few.

CodeKata.org
CodeKata.com

The last one also has pictures of cats, because everyone on the interwebs likes pictures of cats.

the-internet-is-a-series-of-tubes-and-theyre-filled-with-cats

Cheers,
Tim

It’s OK to be MEAN – Full Stack JavaScript Development

I’ve been a big fan of JavaScript since I started working on richer web applications. Until recently my experience has mostly been on the front end. I had heard of Node.js and even attended a introduction to Node talk at a conference a few years ago. Recently though, I’ve started using Node.js for prototyping and early integration testing. In this post I’ll describe some of the tools and technologies I’ve found for making development with Node.js easier as well as provide a link to a demo application I’ve created as well as the source code on my GitHiub account.

The idea of a common language across the full stack of a web application is quite compelling for me. Also with NoSQL databases, now the data-interchange format JSON, can be consistent from the persistence layer to the user interface. This provides a very efficient and streamlined process for retrieving stored data and displaying it on the user interface resulting in fewer layers, no ORM, and less complexity.

Full stack JavaScript development is accomplished with the MEAN Stack. The MEAN stack is composed of the following technologies.

I won’t go into a deep explanation of each of these technologies since their web sites can do a better job than I can. But MongoDB is NoSQL database that stores data in JSON format. ExpressJS is an application framework that is used with Node.js to build web applications and RESTful services. AngularJS is a framework for building rich JavaScript user interfaces. And finally Node.js is an asynchronous event driven server that allows web server applications to be built using JavaScript.

Over the years that I have been developing software I’ve heard the promise of new languages or frameworks that will improve developer productivity. So far in my experience while working with the MEAN Stack, I’d say this is one of the few technologies that actually delivers on that promise. The only change I’d personally make to the MEAN Stack would be to replace MongoDB with Couchbase, but that’s just a personal preference.

A couple of other technologies that make developing with the MEAN Stack even more productive and enjoyable are Yeoman and Heroku.

Yeoman allows you to get started developing with the MEAN Stack as quickly as possible and with common best practices and development tools. Yeoman uses generators to build all the scaffolding needed for a new project. One of the more popular generators for the MEAN Stack is the AngularJS Full-Stack generator. With Yeoman and the generator installed, getting a scaffolding MEAN Stack application started is as simple as typing, yo angular-fullstack [app-name]. This will provide you with a working, minimal application with unit testing frameworks (Mocha – server side and Karma – client side), Grunt for build tasks, and Bower for dependency management.

Heroku is a cloud application platform for deploying web applications. Heroku allows you to deploy web application for free and as your resource needs increase, the pricing plan scales with your application needs. Heroku makes deploying a MEAN Stack application as painless and easy as possible. The AngularJS Full Stack generator for Yeoman also has automated tasks for building and deploying your application to Heroku which is very nice.

So my demo application in which I used all of these technologies is a basic weather application that provides current conditions and a 10 day forecast for San Francisco California. I have a developer’s account for the Weather Underground APIs which I used for getting the weather data. Unfortunately the free developer account only allows a limited number of requests per day. So I cached the weather data temporally and only refresh the data from Weather Underground APIs after a defined time interval. I am using TingoDB to persist the cached weather data. TingoDB is an embedded JavaScript and file based database that is upwards compatible with MongoDB at the API level. That means if I later want to add MongoDB, I only need some very minor code changes specific to the database initialization to use MongoDB instead.

The demo application can be seen in the link below. (please excuse the “waether” misspelling in the URI, oops)

Weather Application

The source code for the application is available on my GitHub account in the link below.

Weather Source Code on GitHub

Well, I hope that sharing this information will be helpful for someone who hasn’t taken the dive into the MEAN Stack yet.

Cheers,
Tim

AngularJS Roulette

I haven’t posted in a while because work has been really busy.  I have been working a lot with AngularJS lately and I had a few incarnations of this idea.  The early attempts were more jQuery then AngularJS but I think I’m getting into the Angular mindset finally.

If you have ever looked closely at the American roulette wheel you might have noticed that the numbers on the table are not in the same order as they are ordered on the wheel. See the images below.

wheel.2da2ad49

table.336cd9ab

This makes it difficult if you have a favorite number and would also like to bet on that number’s neighbors. So that’s what this app is meant to help with. If you click on a number the two nearest numbers on either side will be highlighted. The number clicked will be in a darker blue, the closest neighbors in a slightly lighter blue, and the farther neighbors in an even lighter blue.

I created this AngularJS app using Yeoman and the Angular Generator. The source code is available on my GitHub account, rouletteModelApp. A demo of app is included in this post below.