Friday, March 30, 2012

Quick Tip: JavaScript Switch Statement

My friends, even those who are fellow coders, are always amazed by how many books, tutorials, and videos I go through on a regular basis. They assume, for some strange reason, that because I have been doing this for such a long time I should know all that I will ever need to know. I don't think you can ever reach such a point.

I have been programming in JavaScript since the 1990's. Admittedly my early JavaScript programs were amateurish. They were usually just there to do some kind of trick or effect. They were not doing any kind of serious coding. Later JavaScript was included to do both validation and Ajax. Nowadays I write full solutions in JavaScript.

I was reading the book, "Node.js in Action", when I realized that I missed something in JavaScript. For all of my years of coding JavaScript, I have thought that the switch statement required an expression which evaluates to an integer. This is not true. Looking back on things I realize that all of the examples of switch statements I have seen use integers in the case statements, but this is not a requirement of the language. The only thing that the language requires is that the switch and case statement expressions match in value and data type. So long as that is true, everything's a go.

Why was this important? With web programming lots of values are passed as strings, for example HTTP verbs. Now there are better patterns to use instead of long rambling switch statements, however when you have only a few possible values, nothing is more to the point than a switch.

This is perfectly legal JavaScript:

Wednesday, March 28, 2012

WebStorm Initial Review

I was up to nearly 1 AM last night getting familiar with JetBrains' WebStorm. My early opinion is simply wow! Since the beginning of the year I have been playing around with Node.js. Now, play time is over and I am trying to build real solutions with it. My current back-end of choice is Microsoft's ASP.NET MVC 3. It is a well made product which has served me well since MVC version one. But Node.js may  improve my server's responsiveness and availability to point where I can create new kinds of applications. So I want to explore and possibly switch over to Node.js.

The problem with Node.js so far has been the lack of a real IDE. I know there are a lot of Microsoft haters out there but Visual Studio is a world class IDE. Right out of the box, it is usable plus there are a large number of plug-ins available both free and paid.

My requirements of an IDE are:

  1. A capable editor
  2. Some form of auto-completion
  3. Debugger
  4. Able to use my code whether it is local or remote
  5. Integrates with Git.
I know that there are a lot of hard-core guys out there who scoff at using anything but the command line, but experience has taught me that being able to iterate quickly is key to meeting deadlines. I still use the command line but not for my day-to-day development work.

Initially I used TextWrangler on the Mac to code Node.js development. TextWrangler is a nice editor but it is just a text editor.

Next I looked at Nide. It shows a lot of promise but it is way to early in its development cycle.

Then there was Cloud9IDE. This is an exceptional product. It is very usable, has everything I was looking for in an IDE, but it has two problems. The first is that it cost $15 dollars a month or $180 a year. It does offer a free version for public projects, but since I like to earn money with my development, I don't want everything I build available for free to the public. Don't get me wrong, $180 is not an excessive amount of money, I just don't like subscriptions. The second was it is tied to the web. Most of the time I have Internet access, but the few times I don't have access have taught me never to be dependent on it. I love killing a few hours waiting at the airport or in a hotel room coding so much, that I always want to be able to do it.

Last night I was just googling for a Node.js IDE and I happened upon WebStorm from JetBrains. Since it was from JetBrains I was hopeful. I like one of their products, ReSharper. I am still on day one of my 30 day trial, but the I like it so far. I was able to point it to all of the code I have written so far without a hitch. I can edit, run, and most importantly debug it. The auto-completion is excellent. It is familiar with Node syntax and like ReSharper on Visual Studio, it is able to some form of parsing of my files and add the results to its auto-completion mechanism.

I still need to do some hard coding with it. There are a lot of things I haven't played around with yet; CoffeeScript, Git integration, and the duplicate code detector, so I will write a more in-depth review later. But I like everything I have tried so far and its $49 price is reasonable. I will do another post closer to the end of my 30 day trial, when I will have to pay to use it.

Wednesday, March 21, 2012

San Diego.NET User Group

I had a great time presenting to the San Diego .NET User Group's, UI Developer SIG last night. The talk was interesting and very interactive. I am looking forward to seeing everyone again in a few months at Code Camp San Diego.

If you attended, please take the time to rate my talk and give me feedback. I am hoping to improve my presentations and good feedback is way to achieve that goal. The link to rate me is: Rate My Talk.

On the sidebar of this blog are the links to the slide deck and the source code. If you have any question please leave comments in this blog and I will respond here as well.

Tuesday, March 20, 2012

San Diego .NET, UI Developer SIG - March 20, 2012

I will speaking in front of the San Diego .NET User Group's UI Developer SIG on March 20th. The topic will be using jQuery Mobile, Backbone, and ASP.NET MVC to create mobile web applications.

San Diego .NET User Group

If you attended, please rate my talk!