Cutting the cable cord

There is a lot of talk about people cutting the cable cord and not having cable TV because of how expensive it is.  I have not had cable in 8 years.  I mostly use a combination of Netflix mail-order DVD’s and Amazon Prime streaming.  However I still wanted to be able to get my local channels.  I ended up putting an antenna on my roof.  I am going to describe the process I went through to pick an antenna and how to setup a no subscription DVR.

First to pick an antenna, there is a site called Antenna Web.  If you put in your address, it will tell you all the channels that are in your area, and the position of the broadcast antennas in relation to your house.  Additionally it will tell you if the broadcast is in UHF or VHF, and what kind of antenna to buy.  When I bought my antenna I got a UHF/VHF combination antenna, but now most broadcasters have switched to UHF.  In one room that was difficult to get cable to I ended up putting one of these in it and it works pretty well also.    Most people would benefit from hiring someone to install it just to be safe in regards to being up on the roof.  The antenna also needs to be grounded.

For a DVR, I ended up buying something called a SiliconDust HDHomeRun.  You attach the coax from the antenna to the HDHomeRun and then run an ethernet cable from the HDHomeRun  to your Router.  Then all you need to do is install the software provided on your computer and you can watch TV on your computer.  I use Microsoft’s Windows Media Center software on it.  It makes for an outstanding DVR.  My HDHomeRun came with two tuners so I can simultaneously watch one show and record another or record two shows at the same time.  This works over a wireless or wired connection.

Scala for the Impatient

I’ve been meaning to start learning Scala for some time now.  The other JVM language I’ve used is Groovy.  Groovy is a pleasure to use.  I wrote one application using Groovy and Grails.  It’s purpose was to allow Subversion repository owners to grant permissions to new committers.  Groovy has a very low learning curve and great interoperability with Java.  It also has the backing of the creators of the Spring Framework.  Groovy gave us closures, which are finally coming in Java 8, and other wonderful features.  Grails is also a great framework for creating web applications.  I used it for creating front end services that served a Single Page Application.  The complaint I’ve heard about Groovy is that with it’s dynamic nature it is much slower than Java.  They have the ability to static type checking now in newer versions of Groovy so I don’t know how much that is improved.

The other two languages that interest me at the moment are Scala and Clojure.  I actually have books from the library for both of them right now.  I am going to start with Scala.  The one knock I’ve heard about Scala is that it is overly complicated.  I am going to start with a free book I found written by Cay Horstmann called Scala for the Impatient.  It is $25 from Amazon, but I just noticed it is free at the TypeSafe website.  They also have Scala In Depth.  I am never one to turn down a free technical book.

Java Static Code Analysis

This post will cover Java static code analysis using two tools:  PMD and Find Bugs.  Both PMD and Find Bugs are automated code review tools that help pinpoint potentially troubled code. They help to find overly complicated code that you may want to refactor or to focus your unit testing efforts. Both of these tools may be used in Eclipse to examine your code and refactor it, and may also be used through the Reports section of Maven to automatically generate reports for PMD and Find Bugs. When you run the mvn site command from Maven, a report will be created for each of these tools. Both of these tools are very good at helping to fund bugs that you may not even see through a manual code review.

If you use Spring Source Tool Suite, they make it easy to get many popular plugins.  You can go to the Dashboard from the Help menu.  Then click on the Extensions tab on the bottom.  From there you can select PMD and Find Bugs.  Otherwise just use the Eclipse update site if you are not using Spring Source Tool Suite.

PMD

PMD parses project code, runs the code throught its rules, flags rule violations, and generates reports. Each rule within PMD is a Java class and is assigned to one of the given rulesets.   Some of the rulesets bundled with PMD:

  • Basic
  • J2EE
  • Java Logging
  • Naming
  • Optimization
  • String and StringBuffer
  • And more…

In addition to belonging to a ruleset, each rule is assigned one of five priorities:

  • Error high
  • Error
  • Warning high
  • Warning
  • Information

To view all of the rules:

  • Go to Window->Preferences
  • Select PMD->Rules Configuration

PMD is extensible. If you encounter or wish to enforce a rule you can write your own.

To run PMD in Eclipse, right click on the projects source directory and select PMD->Check Code with PMD.  On a big project, this may take a while so you may want to click Run in Background.  If you are not in the PMD perspective, select Window->Open Perspective->Other and select PMD.  When you run PMD on a project it will appear as follows:

pmd

 

The Violations Overview summarizes all of the Rules Violations. There are three ways that violations can be grouped (Available from the third button from the right in the Violations Overview or the context menu Presentation type):

  • Show violations to packages
  • Show violations to files
  • Show packages with files

The Violations Outline summarizes the Rule Violations in the open class. For detail on what a Rule Violation means, right click on it and select Show Details. You can remove individual violations from appearing within PMD by right clicking on the violation and selecting Remove Violation. (It will reappear if you re-run PMD without fixing the violation). Within either the Violation Overview or the Violations Outline you can filter the level of violations that are visible to you.

 

In the Violations Overview there are five buttons with colored circles in their center. The highest severity is the left-most button with decreasing severity from left to right. Toggle the display of a violation by clicking on the individual buttons.In the Violations Outline, there is a downward pointing triangle next to the red X that you can similarly toggle individual violation levels. To get rid of PMD violations, right click on the project and select PMD-> Clear Violations. PMD can also find Suspicious Cut and Paste meaning that a developer takes a snippet of code from one area of the application and copies it to another.
To use this, right click on the project and select PMD -> Find Suspect Cut and Paste. An options window will come up asking to select a Minimum Tile Size. This means the number of lines of duplicate code. The default is 25. Selecting too small a number will result in too many violations. Many of PMD’s violations are related to style and code formatting and can be automatically cleaned up by using the code cleanup feature in Eclipse.

Find Bugs

Find Bugs is similar to PMD in that it will scan code and point out potential problems. To run Find Bugs, right click the project you want to evaluate and select Find Bugs->Find Bugs. If it does not open automatically, open the Find Bugs perspective by selecting Window->Open Perspective->Other and select Find Bugs. The window will look like the following picture:

findbugs

 

On the left hand side you will see the Bug Explorer. Click on the 4th button from the right in the Bug Explorer (It looks like a pencil) to bring up the grouping. You can group the bugs in any order you like. I use Project, Priority, Pattern in that order. Using the options selected in the prior step, Bug Explorer will now show the individual projects that Find Bugs has evaluated. Under each project there may be High Priority and Normal Priority Bugs. Selecting a bug will show the details of the bug in the Bug Details tab.

Conclusion

PMD and Find Bugs should be used together as they complement each other. Each tool may find problems that the other does not. You do not need to fix each and every error or rule violation. Some things that these tools point out are not necessarily wrong. For example PMD has many rules that some people would find debatable.

I’m buying a KickPed

I’ve been looking at getting a kickped for quite some time. I live about 1 1/2 miles away from the train and every day I drive my car and park in a parking garage. I pay $30 a month to park in the garage.  I’ve been looking for an easier way to do the commute. I thought about riding my bike but I don’t really want to have to lock it up every day. All the bikes that people leave the train are usually beater bikes. In the morning I don’t have very much time and that is why scooters appeal to me.  With a scooter I can just pull right up to the train and fold it up.  It looks like a fun way to get to work.  Also when I get to the city all I have to do is exit the train station, unfold the scooter, and I can get to work a lot faster than I would walking.

One other thing I will do with the scooter is go for rides with my son.  He really likes the scooter he has and prefers to go on that more than his bike.

You can buy a Kickped at NyceWheels.

Single Page Web Application – part two

In my second post about single page web applications I want to talk about how to organize code.  The first single page web applications we used Dojo.  I was very attracted to the way they used modules.  Each component in Dojo would be created in it’s own file called a module.  The top of the module would have zero or more dojo.require statements which would indicate the current module’s dependencies.  When loading the module dojo would execute these statements and load these dependencies and all of the transitive dependencies.  You can visualize a dependency graph.  The benefit of breaking up JavaScript into modules such as this is that it may, if done correctly, lead to much more organized cohesive code.

I thought this was great when I first learned about it.  When most people think of JavaScript they recoil in horror at the thought of huge files containing poorly organized unrelated functions.  If you view the source of many applications today you may still see that.

When I started working last year on my current project, I started researching modules.  I came upon  RequireJS.  There are two main functions in RequireJS:

  1. require:  Takes 2 arguments.  The first argument is an array of dependencies where each dependency is a string name of a JavaScript file.  The second argument is a call back function. The call back functions args should match the list of dependencies.  RequireJS will pass the dependencies listed in the first parameter to the callback function in the second parameter.  A file containing a require statement would be the main file loaded by your page and would typically bootstrap your application.
  2. define:  Again takes two arguments just like require.  An array of dependencies and a callback function.  This has the same semantics as the require statement.  Usually a require statement would reference one or modules created using define.  Each JavaScript file should have one define statement.  Define statements can contain dependencies on other modules containing their define statements with their own dependencies.  Hence you end up with a web of dependencies.

To demonstrate, I’ve created a simple hello world application using RequireJS and Knockout here.  The code is available on GitHub.  This is just a very simple app.  I am planning to write a more complicated app demonstrating knockout later.

 

<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="css/bootstrap.css" rel="stylesheet" media="screen"/>
<script type="text/javascript" data-main="js/app/main/main" src="js/lib/require-jquery.js"></script>
</head>
<body>
<div class="container">
<div class="row">
	<div class="offset3 span5">
		<form class="form-horizontal">
			<div class="control-group">
				<label for="name" class="control-label">Name</label>
				<div class="controls">
					<input type="text" id="inputName" placeholder="Enter your name to say hello" data-bind="value: name, valueUpdate: 'keyup'">
				</div>
			</div>
		</form>
	</div>
</div>
<div class="row">
<div class="offset5 span5">
<h1>Hello <span data-bind="text: name"></span></h1>
</div>
</div>
</div>
</body>
</html>

Line 7 above is where you include RequireJS.  Notice the data-main property in the tag.  This is where you reference your main application file that RequireJS will load.  In this example, that file is main.js located in the js/app/main directory.  That file is here:

requirejs.config({
	baseUrl: "js"
});

require(["app/model/HelloWorldModel", "lib/knockout"],function(HelloWorldModel, ko){
	var helloWorldModel = new HelloWorldModel();
	ko.applyBindings(helloWorldModel);
});

The first statement on line 1 above is where the configuration of RequireJS is specified.  It is just an object literal.  In this simple example I am telling RequireJS to use the js directory as the base url.  Without this statement RequireJS will try to resolve all urls relative to the directory of this script.  On line 5 is the require statement.  The first argument is the array of dependencies.  Here it is a file called HelloWorldModel.js located in the js/app/model directory, and knockout.js located in the js/lib directory.  The baseUrl property allows you to omit the js/ directory for each file, and you do not need to specify the .js file extension.  The 2nd argument is a function callback that will be provided with the HelloWorldModel and knockout as the first and second arguments respectively.  RequireJS will download these files and their dependencies and then provide these as arguments to the callback.  The last statement binds the HelloWorldModel to the HTML page above.

The last file is HelloWorldModel:

define(["lib/knockout"],function(ko){
	return function(){
		var self = this;
		self.name = ko.observable();
	};
});

On line 1 is the define statement.  Here the dependency list has only one entry which is knockout.  Again RequireJS will locate this dependency and provide it to the 2nd argument which like the require statement is a function callback.  Here we are defining a module that can be used as a dependency in other define or require statements.  In this example I am defining a simple object that has one property called name.  You notice that it is set to a value that is the result of a call to a function provided by Knockout called observable.  This is the most basic functionality provided by Knockout.  It is what allows for two way binding between your JavaScript model and your view.

The ko.applyBindings function in main.js bound the HelloWorldModel to the view shown in the first example.  If you look at the view you notice there is a text box on line 17 as follows:

					<input type="text" id="inputName" placeholder="Enter your name to say hello" data-bind="value: name, valueUpdate: 'keyup'">

The attribute data-bind=”value: name” bind this text box to the value in HelloWorldModel.  Typing in the text box changes the value contained in the model automatically.  To illustrate, the value of name is also bound to a span element.  Typing in the text box automatically displays the value of the text box in the span just to the right of the word Hello:

<h1>Hello <span data-bind="text: name"></span></h1>

You can try the example here.  I think it is a pretty simple example of how easy it is to bind values from your domain model to your view with very little code.  I will dive more into Knockout in my next example

My first post can be found here.

Single Page Web Application – part one

In the past year I have done a lot of JavaScript development.  My assignment was to create an application with a rich user interface that had the interactivity of a desktop application.  

I had been part of the development of a single page web application once before about 3 years ago.  That application utilized Dojo which is a very powerful front end JavaScript framework and toolkit.  Dojo comes with many prebuilt widgets and has a powerful mechanism to extend existing widgets and create new ones.  On that application I mainly wrote the services that the browser app required.

Most of the development I had done prior to that had been traditional web applications.  I have a Java background so that meant I used Struts 2 and Spring MVC.  This architecture relies on the user submitting a request to the server.  The server then processes the request and generates the html to display back to the user.  Many times with this type of architecture, much of the page does not change, but you force a complete re-rendering of the entire page.  It is rather wasteful.

Single page web applications on the other hand only refresh a part of the page.  In the example I mentioned above for the first single page app I wrote, we would make an AJAX request to a Struts 2 web application.  It would call whatever necessary back end services we required,  However instead of generating HTML, we would populate a view model and then Struts 2 would automatically serialize it to JSON.  Thus the only thing going back and forth between the browser and the server was JSON.  All rendering was done client side.  You can also have the server render a snippet of HTML to update part of the page.

The benefit of this model of development is the page is much more responsive.  The amount of information going across the wire is generally smaller.

Since the development of that app, there has been a lot going on with client side web development.  Google has been a big leader demonstrating what you can do with JavaScript.  Google Maps, Gmail and Google Docs are all awesome examples of what can be done with JavaScript.

The first thing that I did was do a lot of reading about some of the various frameworks and libraries that were out there.  I was probably reading about 2-4 hours per day.  I also dove back into JavaScript because it had been a while.  You are not going to be able to create a large Single Page Application without a strong foundation in JavaScript.  (I love learning computer languages.  I had spent the last year playing around with Erlang).

Some resources I’ve used to learn.

  • Javascript: The Definitive Guide - This would be the first JavaScript book I’d read.  It is a large book, but you don’t need to read the whole thing.  I’d focus on the core JavaScript part of the book.  The back of the book is mainly an appendix.  I’ve owned two editions of this book.
  • Secrets of the Javascript Ninja - This book was written by John Resig, the creator of jQuery.  He stresses the importance of the functional nature of JavaScript.  People coming from languages like Java and C# really need to understand the importance of functions.
  • Mozilla Developer Network - Great JavaScript resource.
  • DailyJS - Really good JavaScript blog.  Tells you what’s going on with new/existing libraries.  I read this every day.

The main library I ultimately decided to use for my app is called Knockout.  It is a data binding framework that allows two way binding between your JavaScript object model and your page.  Their website has excellent tutorials on the basics of the framework and the various bindings that are available.  If you click on the Tutorials link they have a few different lessons you can take.

My next post is here and talks about how to structure your code.

Using SpringSource Tool Suite

I’ve been a long time Java developer and have always used Eclipse.  Eclipse on it’s own though doesn’t always come with all the plugins you want.  Eclipse has gotten better over time with adding new plugins, but it used to be kind of painful to add new plugins as you’d have to also satisfy the plugin’s dependencies as well.  I have always like to start off using SpringSource Tool Suite.  It comes with plugins for Spring IDE, M2Eclipse for Maven projects, AspectJ tools, the web platform tools.

This post will detail getting started with Spring Source Tool Suite and creating an initial Maven project.  I will detail all the steps necessary.

  1. If you haven’t already, get the JDK and not just a JRE.  In Windows, set an environment variable  JAVA_HOME to the directory where the JDK is installed.  In my case I like to install a lot of things in an apps directory.  Many tools do not like a space in the path, so you don’t want to put it in Program Files.  In my case JAVA_HOME is set to C:\apps\Java\jdk1.7.0_10.  Next add %JAVA_HOME%\bin to your path.
  2. Download  and install Spring Source Tool Suite (SSTS) for your platform.
  3. The installer will prompt you to install Maven which you should. I also like to install Maven locally on my computer so I can run it from the command line.  Follow the instructions for installing Maven outside of Eclipse.
  4. Once everything is installed, open SSTS.  To get started with Maven, you’ll want to ensure you index the Maven Repositories.  The repositories are where many of the libraries you’ll want to use are made available.  For instance Apache has a repository.  You can browse it here.  Indexing the repository in Eclipse helps you to search for artifacts you will want to add to your project.
    1. You need to open the Maven Repositories view.  To do so, go to the Window->Show View->Other menu.
    2. In the filter box type Maven.  Maven Repositories will be shown in the list.  Select it and press OK.
    3. Now you will see the Maven Repositories.  There should be one entry called central under Global Repositories which you will see once you expand that view.  Right click on central and select Enable Full Index.  This will take a while.  While updating, the entry will show in italics and the word updating will show within brackets.
  5. Once the repository is finished updating, you are ready to create your first project using Maven.
    1. Go to File->New->Other menu.
    2. In the filter text box, type Maven.  Select Maven Project and click Next.
    3. Leave the defaults on the next screen and click Next.
    4. Now you will be on the screen where you pick your archetype.  In Maven, an archetype is like a template for creating a project.  In this example we will leave the default which is maven-archetype-quickstart.  This archetype is for a simple Java project.  I will use this in future posts that I am going to do about Spring Integration.  From here click Next
    5. Now you will be asked to enter the GroupId, ArtifactId, Version and Package.  The first three are the coordinates that another project would use if they wanted to reference your project. GroupId is similar to a Java Package.  I would usually put com.yourorg.  ArtifactId would be your project name.  Version is used to create different versions for your application.  If it is not an official release, you would typically have -SNAPSHOT appended to the end as it does when you create your first application.  Package I would leave the default.  After entering these, click Finish.
    6. Now you have your first Maven application.  To test your configuration, you can build it in Eclipse.  Right click your project and select Run As -> and the second Maven Build.  This will bring up the Edit Configuration window.  Under Goals, type package.  Then click the Run button.  In the Console window you will notice Maven downloading a bunch of packages.  If you go to the target folder in Maven and refresh it, you should see a new Jar file for your project.

To learn more about Maven, look at their Getting Started Guide.  My next post will start to look at Spring Integration.

Welcome to my blog

Welcome to my blog.  This is my first post.  I am a software architect at a Fortune 100 company.  I intend to write about some of the software that I’ve worked with.  I have been doing application development since June 1999.

Most recently I have been doing a lot of JavaScript development.  I am currently the lead architect for a Single Page Application.  We are using Knockout to handle two-way binding between the object model and the UI.  Amplify is used to allow various components on the page communicate with each other using events.  The page is loaded once and then all communication with the server is done via JSON.  All rendering is done client side.

I’ve primarily done front end development.  I read and experiment with lots of different technologies.  For work assignments, I’ve used Struts, Struts 2 and Spring MVC as the MVC framework.  Additionally I’ve been a heavy user of Spring for Inversion of Control.  I have used Hibernate for ORM for two applications.  I’ve written one application using Groovy and Grails.  I also spent a lot of time playing around with Erlang which is like a programming language, middleware system, and toolkit for creating highly available, very reliable and bulletproof applications rolled into one.