Friday, December 30, 2011

Using a Mac for Visual Studio 2010 Development

For most of my development career I have exclusively used PCs. Things have changed now. My main PC was over four years old, limited to 4 GB and was painfully slow to work on, I needed to upgrade. Since my platforms were Android, iOS and the web, I needed to buy a Mac.  I had already had a Mac Mini for iOS development and liked it. I decided to replace my main system with a MacBook Pro.

The machine itself is sweet. It is an early 2011, 15" MacBook Pro. I bought it from Amazon discounted since the newer machine had just been released. Since I am an Amazon Prime member, shipping was free. And as an added bonus, I was able to use my American Express card reward points for an additional discount of 70 dollars. I bought it with 4 GB of ram but did the upgrade myself to 8 GB and 256 GB SSD. The upgrade was super easy and only took about 30 minutes to do. I bought a kit from

The problem was the back-end. I do all of my server development in either WCF or ASP.NET MVC. I had no desire to abandon all of my Microsoft knowledge. Since Mac are also Intel based I decided to try creating a virtual PC using software. There are several virtualization apps available, some are even free. But after a long weekend of reading every review I could find, I bought Parallels Desktop 7. It ROCKS! It is an amazing piece of software. The number one thing I like about it is that it has a mode called coherence, which makes PC apps appear on the Mac desktop just like native apps. I can navigate through the Mac file system from the PC too. They also seemed to have thoroughly optimized it. It seems only a hair or two slower than using a PC.

On my home WiFi network, from my iPhone, Android Nexus One, iPhone Simulator, Android Emulator, or any browser, I am able to see my IIS 7.5 server created with Visual Studio 2010. I can publish with a button click locally or to my Discount ASP.NET hosted web site, all from my Mac. In my next post I will give details on how I set everything up.

Monday, December 19, 2011

Make Regular Expressions Not More Code

Currently I am bug hunting at work. Product and QA have identify a number of issues engineering needs to fix before we begin A/B testing of our new website design. For the last few months while our website was being made feature complete, I'd been working on both our iPhone and Android apps. They were updated to use some newly available server data and fix some outstanding issues. So I missed out on a lot of the changes made to the site. Now I am catching up on the code by fixing bugs and refactoring code.

While the code in general is not too bad, there were a few things that troubled me. The first of which was a general ignorance of regular expressions. Every developer should learn regular expressions in their languages of choice and learn them well. They save time, minimize space, and increase code clarity. Here is the original code:

zipIsValid: function (zip, notify) {
var isValid = true;
var validCharacters = "0123456789";

if (zip.length != 5) {
isValid = false;
if (isValid) {
for (var i = 0; i < zip.length; i++) {
temp = "" + zip.substring(i, i + 1);
if (validCharacters.indexOf(temp) == "-1") {
isValid = false;
if (!isValid && notify) {
window.alert("The ZIP code you entered is invalid. Please enter a valid ZIP code. ");
return isValid;

All the above only checks to see if a zip code is valid and if not may display an alert box if a flag is set. I replaced it with the following code:

isZipCodeValid: function (zip) {
var re = /^\d{5}$/i;
return  zip && zip.match(re) != null;

The replacement consists of just two lines: a regular expression pattern and a line to test the expression. IMHO, this code is far more maintainable than the code above, if you understand regular expressions, that is.

Also, I moved the warning display to its own method, since every method should do only one thing. And I renamed the method to make it more readable.