Book Review: The Nomadic Developer

I recently bought a couple of new software development books from Amazon, including The Passionate Programmer, Programming Android, The Busy Coder’s Guide to Advanced Android Development, and The Nomadic Developer. Of these, the only book I’ve finished so far has been The Nomadic Developer, so I thought I’d write up a quick book review on the blog.

Why I bought this book

As an indie Android app developer, I have worked on a couple of apps that are selling in the Android Market, namely iSyncr WiFi and Cheetah Sync, as a software contractor for JRT Studio. I am very proud of these apps, and I enjoy adding new features and fixing bugs in them as they arise.

However, I get paid from these apps only when customers buy them, and while I could spend 40+ hours a week adding new features and fixing bugs, this won’t necessarily result in a dramatic increase in the number of people who buy these apps. In economic terms, according to the supply curve of labor, in general an increase in expected wages will tend to cause workers such as myself to supply more labor, but if the demand for the app remains relatively constant, my wages are fixed and so is my desire to trade off leisure time for labor time =)

What am I getting at? Basically, this year I’m looking to get into some paid, hourly contract / consulting work to supplement my indie app income, so that I could have some more control over the correlation between working more hours and earning more income. So I bought this book to see if it had any insights into the world of contracting as a “nomadic developer.”

Things I learned from this book

It’s embarrassing to admit, but before I bought this book I was a little bit confused about the difference between contracting and consulting. Before I started working on Android apps, I was employed full-time as a W-2 employee at National Instruments and then Microsoft, so I was painfully ignorant about the “other” methods of paid software development.

So, first and foremost, I learned that contracting typically means working on short-term software development projects as a “software mercenary” until the job is complete, and then you go back to doing whatever you were doing before. Whereas consulting typically means joining a consulting firm where you are expected to be work on projects to which you are assigned and you are expected to bill hours without spending too much time “on the bench.” Also, typically the scope of a software consultant goes much further beyond simply implementing software according to provided specifications – it often typically requires business acumen, people skills, and advising.

Because this book focuses exclusively on joining a consulting firm, I didn’t learn anything about what software contracting looks like or how to thrive in that environment, but I did learn a lot about what it’s like to work at a consulting firm, should I ever be interested in doing that in the future.

Things I didn’t like about this book

As I mentioned before, I initially bought this book because I thought it might have some insights into software contracting, so I didn’t realize when I purchased it that it was first and foremost a guide to surviving and thriving as a consultant working for a consulting firm. That was my mistake when I bought the book, but it meant that many of the chapters seemed completely irrelevant to my interests.

For example the chapter called “The Seven Deadly Firms” lays out 7 types of consulting firm personalities that are worth avoiding if possible when interviewing for a consulting job, and the chapter explains how you can identify these firms and avoid them. While somewhat interesting, it was pretty irrelevant to me. This also applies to “How Technology Consulting Firms Work”, which focused mostly on how to deal with the account executive, engagement manager, recruiter, consulting manager, etc., and the “Your Career Path” chapter, which focuses mostly on career paths inside of IT consulting.

Things I liked about this book

Now that I’ve got my complaints out of the way, I’ll focus on the things I did like about this book. There’s actually a lot of interesting insight in this book that’s really applicable to any software developer, not just consultants. Chapter 4, “Ten Unstated Traits That Technology Consulting Firms Look For”, is really a recipe for any software developer looking to become a valuable and well-known developer in their tech community. For example:

  • Be good at being interviewed for jobs
  • Always be learning
  • Be active in your technical community / develop your network
  • Work on your writing skills

Chapters 6 and 7, “Surviving” and “Thriving” are full of excellent advice for any developer as well, especially the advice to do what you enjoy, and that billing work = good work. After all, developers who create profit for a company don’t get fired.

Lastly, chapter 9, “Avoiding Career-Limiting Moves”, is a little bit silly, since it’s themed on the seven deadly sins, but it does offer some good (if obvious) advice about the traps that software developers often get themselves into.


Overall, I think that this book has a lot of insights for any software developer, especially those interested in becoming a software consultant, but if you’re not interested in doing consulting at a consulting firm then maybe this isn’t quite the right book for you. Many of the same insights and advice for surviving and thriving as a software developer are also in the similar book The Passionate Programmer, which is approximately half the cost and you won’t waste any time trying to read chapters that don’t apply to you =)

8 Rules for Losing Weight Like an Engineer


Well, it’s January, and that means that many Americans have recently made some new resolutions for 2012, and one of the most common resolutions is to lose weight. So, despite the fact that I am a software engineer and not a personal trainer or nutritionist, I’m going to offer some unsolicited advice on how to lose weight like an engineer =)

Engineers like to measure, quantize, track, and analyze data in order to achieve their goals, and this approach actually does make a lot of sense for losing weight.

Rule #1: 3500 calories is roughly equal to a pound

One of the underlying assumptions you’ll want to make when trying to lose weight like an engineer is that, roughly speaking, 3500 calories is equal to a pound of body weight. In other words, if you consume 3500 more calories in a day, a week, or a month than you burn, then at the end of that period of time you will be roughly one pound heavier. Conversely, if you burn 3500 more calories in a day, a week, or a month than you eat, then you will be roughly one pound lighter.

Rule #2: Calculate Your Caloric Baseline

Your caloric baseline is the average number of calories that you burn in a day, without factoring in workouts or exercise. This number is basically the sum of your Basal Metabolic Rate (your daily energy expenditure at rest) plus any other typical activity that you perform during your day while working, recreation, doing errands, etc. This number also happens to be the average number of calories you’d need to eat in a day to maintain the same weight indefinitely.

It would be pretty inconvenient to spend an entire day in bed hooked up to a calorimetry machine in order to calculate your basal metabolic rate, and it would also be pretty annoying to try to go about your daily business hooked up to a machine in order to figure out your caloric baseline. Fortunately, there are several caloric baseline calculators available on the web that can guesstimate your caloric needs based on your height, weight, age, and general activity level. You’ll probably want to choose the “sedentary” or “light” options so that you can track your exercise separately.

Rule #3: Calculate Your Caloric Goal

One of the biggest mistakes you can make is to try to lose too much weight at once via crash dieting. The generally accepted maximum amount of weight you should try to lose in a week is about two pounds. Why?

  • You could easily lose lean mass (muscle) in addition to fat.
  • You are physiologically and psychologically more likely to binge eat after an unsustainable crash diet.

So, let’s say you want to lose about one pound per week. So your goal is a 3500-calorie deficit per week, or 500 calories per day (when divided by seven). So subtract 500 calories from your caloric baseline and you have your average caloric goal.

Rule #4: Track What You Eat

Now that you have a caloric goal, the next step is to measure your diet to see how many calories it contains. There are a number of websites that provide calorie information and calorie tracking:

Personally, I like Daily Plate because it has a very large and easily-searchable food database, it allows you to track your exercise as well as food, and it can actually calculate and track your progress against a caloric goal.

Another thing you might want to consider, to make measuring calories easier, is to purchase a food scale and use it to determine exactly how much of certain ingredients you’re using when cooking or preparing food. For example if you’re making a sandwich, or cooking some chicken, it can be difficult to tell just how many ounces of meat you’re using without one.

Rule #5: All Calories Are Equal, Except When They’re Not

It’s true that all calories, whether they come from fat, protein, carbohydrates, or sugar, are all basically the same in that they will all cause you to gain weight if you eat too much of them. But, there are some caveats to the basic rule that “a calorie is a calorie”:

  • Your diet should include at least a sizable amount of protein so that you maintain muscle mass. Without protein, you’ll lose muscle mass fast.
  • Some foods are more filling than others per calorie, especially ones with low energy density. Fruits, vegetables, and lean proteins generally have high volume and/or fiber compared to their calorie content, so they help you feel full longer.
  • Salt is not necessarily as bad as we might think it is, but it can lead to water retention. Further, eating salty foods (like chips or fries) can lead to eating more of a food than you would have otherwise because it tastes so good.
  • Alcohol can be pretty bad for weight loss. First, because you are consuming “empty calories” that don’t actually make you feel full. Second, alcohol often leads to increased appetite, which explains late night post-drinking cravings for Jack in the Box. This article does a really good job of explaining alcohol’s overall effect on weight loss.

Rule #6: Track What You Do

If you calculated your daily caloric needs as a “sedentary” or “light” lifestyle, then you’ll want to keep track of how many calories you burn while doing exercise. There are three basic ways to track calories burned while working out:

  1. If you’re using a cardio machine, such as a treadmill or elliptical machine, these will generally estimate your calories burned based on your weight and your speed. However, cardio machines are notorious for overestimating calories burned while exercising.
  2. Use an online calories burned calculator to guesstimate how many calories you’ve burned. This is also not particularly accurate because these calculators assume a relatively consistent amount of calories burned per sport, but intensity levels can vary greatly among individuals.
  3. Buy and use a Heart-Rate Monitor with a calorie count feature. This should take the actual intensity of your workout into account and should be much more accurate than the other two methods.

In addition to the overestimation problem of counting calories, there’s another problem – we tend to focus on the total calories burned of an exercise, not the net caloric burn. In other words, we fail to subtract the extra calories we burned working out versus what we would have been doing instead (like working or using the computer). So when you track calories burned, you might want to intentionally under-report them or possibly not track them at all.

Rule #7: Track What You Weigh

This one is pretty simple. Get an accurate bathroom scale and make it a habit to weigh yourself every day right after you wake up (and after going to the bathroom). Your weight tends to be most “stable” in the morning, so this is the best time to do it. Why do this?

  • It keeps you accountable. Psychologically, it’s much harder to let yourself go and overeat if you see your numbers creeping up.
  • It gives you more data to play with, and engineers love data.

The second part is kind of a joke, but if you track your daily weight you could use it to plot a moving average to see how your weight is trending over time. Since weight tends to fluctuate day-to-day, it can be more visually motivating to see your weight tending downward over time as you stick to your caloric goals.

Rule #8: Weight Isn’t Everything

It’s funny, we tend to make resolutions like “Lose 10 pounds this year”, but we fail to account for the fact that losing weight and losing fat are not quite the same thing. We also tend to equate fitness with being thin, but they’re really not the same thing at all.

If you’ve been tracking your diet and your exercise, you may have noticed that it’s far easier to eat one less slice of pizza than it is to jog for half an hour per day, so you might be tempted to skip exercising and just focus on your diet. But this would be a mistake.

Consider this – would you rather be a slightly overweight person who runs half-marathons, or a very skinny person who can barely walk from their house to their car without getting winded? Let’s be honest, the first person is more fit, and fitness is more important than weight for health.

Further, for every pound of muscle mass that you have, your basal metabolic rate goes up, because those muscles are hungry for calories (especially protein). So over time as you develop more muscle from working out, lifting weights, or doing sports, it should become easier to burn more fat.

I could write an entirely new post on various pros and cons of different exercises and sports, but suffice to say that you should definitely include some kind of regular exercise into your routine while trying to lose weight, in order to maintain muscle mass while losing fat.

Top Ten Things I Like About Seattle

10. Portland / Vancouver

Both Portland and Vancouver are only a few short hours away from Seattle by car, or if you prefer, you can take the train. I’ve been to Portland a few times and I really like it. I’ve also spent about a week in Vancouver and it’s also a pretty cool place to be. I have to admit, I prefer the Portland / Vancouver combo to Houston and Dallas.

9. Sushi / Thai / Indian / Teriyaki / Chinese

Let’s face it, Seattle is not known for its Tex-Mex. But once you get over that (if that’s possible), you can learn to enjoy the diverse range of Asian cuisine available here. I’m especially fond of the Sushi… and the Indian… and the Thai. Okay, I’ll only pick my top three.

8. Nerd Culture (VG Live, PAX, Microsoft, etc.)

The nerd culture is very strong in Seattle / Bellevue, and I kinda like it. This is true of Austin too of course, but in Seattle I have attended PAX and Video Games Live, neither of which I did in Austin. Most of my best friends in Seattle play video games with me, which is all kinds of awesome. For some reason my friends in Austin were much harder to convince to play video games with me – weird!

7. Stone Gardens, Vertical World, and Marymoor Park

Seattle is host to two competing climbing gym companies, Verical World and Stone Gardens, and this is a good thing. Between the two and the three Seattle / Redmond locations, you can go for an awesome bouldering experience, an awesome toprope/lead experience, or a mix of both. Vertical World even hosts an “outdoor club” in the summer which takes people out for climbing on Friday evenings. Awesome. These gyms are truly key for the rainy winter season.

Marymoor Park is also excellent, because it features a sizable outdoor climbing structure in the park where you can climb for the completely reasonable price of $1 to park. This is a great place to practice some crack climbing and leading, if you’re into that sort of thing.

6. Greenlake

Seattle has a lot of bodies of water all over the place. Lake Washington, Lake Sammamish, even South Lake, but my favorite is Greenlake. A relatively small lake north of downtown Seattle, this lake features a 2.8 mile bike/walk path which is absolutely beautiful in the summer. This is my favorite place to run 2.8 miles.

5. Mount Rainier

I’ve never climbed Mount Rainier, but on a really clear day you can see it from Seattle, and it looks awesome. Like a huge distant giant, guarding over the city. You can make a pretty good day trip out of driving around this huge mountain, taking in views from Crystal Mountain, Sunrise Lookout Point, and more. You can also see it from the air when you fly into or out of Seattle.

4. Long Summer Days

The northern latitude makes winters miserable, but the summers more than make up for it. The omnipresent rain goes away, the weather turns into sunny 70s nearly every day, and best of all, the sun doesn’t go down until 9pm in June. I’m not kidding, it’s amazing.

3. Snowboarding at Snoqualmie, Stevens, Crystal, Bachelor, and Whistler

Washington isn’t known for its snow, and it’s certainly no rival to Colorado, but compared to Texas, it’s a winter wonderland. There’s actually quite a bit of variety available between Canada, Washington, and Oregon, with Snoqualmie, Steven’s Pass, Crystal Mountain, Mt. Bachelor, and more. I haven’t even been to them all yet. And did I mention Whistler? It’s like the biggest mountain ever. Seriously. It’s much bigger than Vail.

2. Surfing at Westport

I had no idea when I moved to Seattle that surfing was even an option here. But it is, thanks to the small town of Westport. The city doesn’t produce waves, but the nearby finger jetty does, and every time I’ve been to Westport I’ve caught waves. You might want to check the surf forecast of course, but this town is only 2.5 hours from Seattle, and has 2-3 surf shops that you can rent gear at, as well as a couple great places for lunch or a post-surf snack/beer. Part of me wants to move to Westport just so I can surf every day.

1. Rock Climbing at Vantage, Exit 38, and Smith Rock

Between Exit 38, Vantage, and Smith Rock, you can easily go sport climbing within a half-hour, 2.5 hours, or 8 hours from Seattle, respectively.

Exit 38 is not particularly big, and I’m not super fond of the granite, but it’s a ridiculously convenient crag for its proximity to Seattle. Great for post-work evening climbs in the summer.

Vantage is easily my favorite sport area in Washington. It’s basically several lines of columnar basalt, varying from about 50 feet tall to nearly 100, and I absolutely love the way this rock feels. Since it’s located east of the Cascades in a somewhat desert-like part of Washington, it’s often hot and sunny here even when it’s raining and miserable in Seattle. Some truly epic climbs here, and I have only explored a portion of it.

Smith Rock is well known even outside of Oregon for being an epic place for sport climbing. There are literally hundreds of routes here, and they are stiff. It’s a bit harder to get to, since it’s about an 8-hour drive, but it’s definitely worth it for a long weekend.

In addition to these three, there are numerous other places nearby: Squamish in Canada, Index, Leavenworth, Darrington, Mount Erie, Tieton, and Mazama, half of which I’ve never even visited yet.



For better or for worse, I use iTunes to manage the music on my iPhone. And since I have to have iTunes installed on my computer, I might as well also use it to rip my audio CDs into music files. Traditionally, the file format of choice was MP3, also known as MPEG-1 Audio Layer 3. However, a few years ago I heard about a new file format called AAC (Advanced Audio Coding) promising better sound quality than MP3s at similar bitrates, which iTunes also supports. So I went ahead with a project to re-rip all of my CDs from MP3 into AAC files, which by the way, have the file extension .m4a.

The problem I encountered was that I really disliked the file/folder structure that iTunes automatically uses when it rips your CDs. There seems to be no way to customize this file/folder structure in iTunes, so if you really care about what your files are named and in what directories they are placed, as I do, you’re stuck renaming all of your music files by hand, which is a major pain.

Therefore RenameM4A was born. This simple C# program allows you to select a set of M4A files and rename them according to a rename rule.

Rename Rules: Using RenameM4A

A rename rule is a simple way of enforcing a particular file/folder structure for any M4A file that is to be renamed. Because this is a very simple project, right now the rename rules support the following tags:

As you can see, the tags are surrounded by brackets which denote some kind of information contained within the file. All AAC files have metadata embedded in them which tells you information about the track and where it came from. When RenameM4A processes each file, it looks at the rename rule and replaces any tags encountered with information gathered from the file itself. This step takes place when you press the Preview button, which generates a list of files to be renamed, giving their original file locations and the new file location.

Then, you can hit either the Rename button or the Copy button to move or copy the file according to the destination paths given in the GridView. In fact, if you want to you can edit the GridView in order to fix any discrepancies that may have occurred when running the rule. For example, you might have a track from a particular band’s album where another artist is featured. Since you want the entire album contained within the same folder, you might edit the line for that track to remove the name of the other artist from the directory name.

If you take a look at the rename rule combo box, you can also see that there are a number of pre-loaded rename rules that may appeal to you.

How is AAC better than MP3?

In short, AAC files have superior sound quality and transparency than MP3s do, for the same bitrate. Put another way, you can encode your music at a lower bitrate than an MP3 for the same sound quality. Of course, there are a lot of other improvements, including:

  • More sample frequencies
  • Up to 48 channels of audio
  • Better handling of audio frequencies above 16 kHz
  • More flexibility in designing codecs

Advanced Audio Coding File Format

A SourceForge project called Atomic Parsley appears to have a lot of good information on the MPEG-4 file format, especially as it relates to M4A files. As it turns out, the AAC data is actually just a section within an MPEG-4 file, which can actually contain all kinds of nested data. Each nested section in an MPEG-4 file is called an atom (or sometimes a box); the first four bytes of each box defines its length in bytes, the next four is the name of the box, and the rest is either data or other nested boxes. In a way, that’s pretty similar to how XML works.

Since the only thing that RenameM4A really cares about is the album, artist, year, title, and track number, it simply scans the file for the five atoms it’s interested in and grabs the data. It’s also worth noting that text data appears to be stored in UTF-8 format, so you can’t simply assume that it will be straight-up ASCII.

Recent Improvements

This blog post actually took me a ridiculously long time to write. Mainly that’s because I was a bit embarrassed to release my source code; it was written several years ago and the way it was parsing M4A files was extremely naive. Recently, I rewrote most of the parsing code to make the following improvements:

  • More intelligent parsing; use atom information to jump to the sub-atoms of interest instead of scanning the entire file for “udta” and then each meta tag.
  • Reading only part of the file; since all metadata is under the “moov” atom, RenameM4A only needs to load the portion of the file under moov. The vast majority of a music file’s size is its music data, which is under the separate mdat atom, so we can avoid loading the entire file into memory when we don’t need to.

I did a simple benchmark test of the new and old parsing algorithms by trying to parse 14 half-hour audio files ten times each. The old parser takes about 36 seconds; the new one takes 0.14 seconds; an improvement of around 270 times faster. Not bad.

Download RenameM4A Source + Executable

[RenameM4A Source + Executable]
Note: Requires .NET Framework 2.0 or later.


MPEG-1 Audio Layer 3

Advanced Audio Coding

MPEG-4 Part 14

Atomic Parsley

Atoms, Boxes, Parents, Children & hex (oh my)

Subject: Dissection of m4a format – msg#00046

How To Install Perforce Source Control On Your Windows Home Server

Personal Source Control

If you’re a developer like me, chances are that in addition to the programming you do at work, you probably also have some personal projects that you work on at home as well. Whether you are consulting on the side, or just want to write your own applications, it may make sense for you to have a source control server of your own. There are many benefits to having a home source control system, including:

  • Having a backup of your source code
  • Access to revision history and previous versions
  • Single repository for source code across multiple machines

These are all very good things. It’s very reassuring to know that your source code will still exist on the source control server if your hard drive should crash and burn. It’s also nice to be able to revert to previous versions of your code should you irreparably break something. And lastly being able to easily synchronize source between multiple machines, such as your desktop and laptop, is very handy.

Why Perforce?

You can of course use any source control system you are most comfortable with. I used Perforce quite a bit at National Instruments, and it makes sense to me. I like the ability to have multiple changesets at once. I like that I have a consistent, semi-permanent mapping from my hard drive to the source depot. And most of all, I like that I can install it for free.

I also previously installed an SVN server, and was using TortoiseSVN for a while to check in code on my home network. This kinda sorta works, but… I don’t really like it. It’s hard to explain, but I am so familiar with the way that Perforce works that using TortoiseSVN is a pain. For example, it doesn’t seem like there is any permanent mapping between the source server and your hard drive. You can check out a folder to anywhere, and update a folder from anywhere, but it’s really easy to screw it up. And as for checking out code, well, it seems like you don’t check it out so much as you download it locally, edit it, and then try to commit your changes. I’m sure there are people out there that use it and love it, but I can’t wrap my head around the way it’s supposed to work, and I’d rather use a paradigm much more familiar to me like the one Perforce uses.

Installing P4D

You can download the Perforce Server, called P4D, from Perforce Downloads. I chose Windows for 32-bit Intel (x86) for my machine. Install it. You can pretty much keep all of the default options.

Once it’s installed, you can take a look at your system Services, and you should see that the Perforce service is Started and is Automatic.

Create a New User and a Depot

Use the command p4 user -f from a command prompt in the Perforce directory to create a new user. Your text editor will open a temporary file used to configure your user’s options. You can stick to simply editing the full name and adding a password.

Use the command p4 depot to create a new source depot. You will probably already have a default depot called “depot”, but I added a new one because I want it to be called Root, and I wanted it to be located in D:\Root\ on my server. As before, when you execute this command a temporary document will open in your text editor. Most likely you will just want to change the Map parameter.

Fix Your Firewall

In order to allow connections from other machines on your network, you need to tell your Windows Home Server to allow connections on port 1666, because that’s the port that the Perforce server uses by default. Open up your Windows Firewall Settings, select the Exceptions tab, and click on the Add Port button. Type in “Perforce” and “1666” respectively. Now your Perforce client should be able to connect to the server.

Installing P4V

Now you’re ready to install the Perforce Visual Client, or P4V, on your desktop or laptop. Again, you can download the client from Perforce Downloads. Go ahead and install. Again, you can leave most of the options as default, but you will want to change the server name to match the name of your Windows Home Server.

Go ahead and run the Connection Setup Wizard. You will probably have to manually choose your server name, and to login with the username and password you created on the server. Don’t bother copying files from the server to your workspace, as there are no files in your depot yet.

Once that’s done, your P4V window should look approximately like this:

Creating a Client Workspace

Perforce allows each user to have a set of client workspaces, which is essentially just a way of mapping the depot folders you are interested in to a local drive on your machine. Create a new workspace like so:

Enter a name for your new workspace; generally people use some combination of their username and machine name.

Now, you have to define your client spec. The most important two fields are the Root and the View. Here I set my root to D:/Perforce/Artemis_Hexar/. All of my source files will be under this directory. Next I set my View to a single line mapping of //Root/… //Artemis_Hexar/Root/… The ellipses are a symbol that means all subfolders and files. So here I’m just saying that everything under the Root depot should go under the clientspec, in the Root directory. You can do some interesting things with the View, including exclusions and inclusions, but it’s probably not necessary for our purposes here.

Now your client probably looks something like this:

Add Files to Source Control

Lastly, it’s time to add some files to source control. Take some files that you want to add, and copy them into your clientspec root. For me that means D:\Perforce\Artemis_Hexar\Root\. Next, click on the Workspace View tab so that you can see your local disk tree instead of the depot tree. Right click on the files/folders you want to add and choose “Mark for Add…” This will add them to the default changelist.

Lastly, right-click on the default changelist and submit. You should write a comment on the reason for the change, and make sure you really do want to submit all of the files in that changelist. Now, if you go back to the Depot view, you can see that your files have been added to the depot, and you can check them out for editing, deletion, or rename.


So that’s it! Congratulations, now your personal projects have professional source control. Check in some code, and celebrate with the food/beverage of your choice.

My Favorite iPhone Apps (So Far)

Why I have an iPhone

So I recently won a free iPhone 3GS 16GB because I entered my name into some kind of online contest. Amazingly, the day after I submitted my name I actually won, and about a month later my iPhone came in the mail. Being a cheap bastard, and afraid of signing a 2-year contract with AT&T, I declined to get a data plan but I kept the phone anyway so that I could play with it like a shiny new toy.

Anyway, I thought I’d go ahead and share my favorite iPhone apps so far:

Facebook – Free

This one is a no brainer. It’s just like, except with a more intuitive interface for the iPhone. Not all of the functionality is there yet, but still, this is the fastest and easiest way use Facebook on the iPhone without doing some kind of weird zooming dance with your fingers in a Safari browser.

Twitterific – Free

I haven’t tried any other Twitter apps, but this one works pretty well. Since I don’t spend a huge amount of time on Twitter this is good enough for me. Your mileage may vary.

Skype – Free

Thanks to Skype, I can use my iPhone like a phone, without paying AT&T a dime. I still have to pay Skype of course but hey, it’s pretty cheap and it works internationally. As long as I have wifi access.

Pandora – Free

Internet radio for free on your iPhone. This is for when I get bored of listening to all of the music I already have. Of course it would also be nice if my iPhone supported actual AM/FM radio but this is the next best thing.

SpanishDict – $1

I had a hard time finding an English-Spanish dictionary that works without Internet access, and this one does. It actually also has several other features, like a word game, some key phrases, a daily word, etc., but mostly I use it for the dictionary. This came in super handy in Colombia a couple of times actually.

Spanish! – $1

Yes, another Spanish app. This one is a pretty awesome flashcard application, with 1000 Spanish words built in. It somewhat reminds me of SuperMemo, in the way that it introduces new words to you slowly and as you master words you see them less often, whereas words you miss a lot show up more often. You can try to remember the English definition of Spanish words or vice versa, and it will even pronounce all 1000 Spanish words if you touch them. This app is a really awesome way to build your vocabulary, and much easier than making your own set of real-life flash cards.

Fling! – $1

Fling is an addictive puzzle game where you basically try to fling a set of furballs in a grid toward each other in order to knock them off the board, until only one furball remains. The gameplay is simple, but the puzzles get increasingly more difficult to sequence. This one is definitely a good way to waste some time if you need to do so, for example on a long bus ride or while waiting for the waiter to finally take your order.

Cube Runner – Free

A simple “racer” type game where you steer by tilting the iPhone itself, and the object of the game is to make it through a random field of cubes without hitting any at increasing speeds. There are three difficulty levels, but even on Easy you’ll be challenged to beat your own high score.

Flight Control – $1

This game is my latest obsession, and several of my friends’ as well. Basically a random sequence of different planes enter an airfield and your job is to touch and drag them into a path that will land them onto a runway, or in the case of helicopters, a landing pad. The object is to land as many aircraft as possible without any of them hitting each other. Add in some tricky things like planes of different speeds and this game becomes a really challenging multitasking clusterfield, if you will. You can also send planes to a buddy while playing multiplayer mode on wifi or Bluetooth. Definitely check this one out.

Your Favorite Apps?

Go ahead and leave a comment and tell me what your favorite iPhone apps are. What am I missing?

HexarViz: An XNA Music Visualizer

Media Player Visualization Data

Recently, at a local Microsoft GameDevz meeting that I attended, we had a short 45-minute contest to see which 2-3 person team could come up with the coolest visualization given a relatively simple XNA project that retrieves visualization data from the song currently playing in the Media Center. HexarViz is an evolution of the project that my partner Daniel Taylor and I came up with during this competition.

The way to retrieve music visualization data from XNA is very simple. Call the MediaPlayer.GetVisualizationData method in XNA 3.0 or later, and you will retrieve an object of type VisualizationData. The VisualizationData class provides only two properties, Samples and Frequencies. The former is an array of 256 float values from -1.0 to 1.0 indicating the raw amplitude of the currently playing sound sample. The latter is an array of 256 float values from 0 to 1.0 indicating the logarithmic scaled power value of each frequency band in the currently playing sound sample – essentially the result of a FFT on the sound data. The frequency distribution seemed like a more obvious choice to use in a visualizer, so that’s what we used.


The idea for this visualizer was inspired by the standard horizontal bar UI that is typically used to display the currently playing frequency bands. It looks like this:

And in fact, this is the first part we implemented, by using a simple 10×10 white square as a texture, and drawing one red rectangle per frequency band, from the left side of the screen to the right. But, let’s be honest, that’s boring, because it’s been done a million times.

We wanted something more interesting, so I thought maybe it would be cool to make the frequency band values rotate around a center point, kinda like a circle. Except since each rectangle drawn rotationally this way will have a different length depending on its power value – so the shape of this sound circle will change drastically over time. Here’s basically what that looks like:

This image depicts pretty closely what we ended up with for the competition, in about 45 minutes. We also had a few rudimentary features:

  • Previous Song / Next Song
  • Sound Circle Rotation

But like I said, HexarViz is an evolved version of the results of that competition, meaning that after the competition I added a lot of features, namely:

  • Pause
  • Volume Up / Volume Down
  • Displaying the currently playing playlist, album, artist, and song name
  • Playlist change support
  • Toggle individual Red/Green/Blue components of the target color
  • Color Cycling
  • Change the current texture

Color Cycling was probably the most difficult part to implement. In order to effect a smooth transition of target colors, I calculate the HSB (Hue/Saturation/Brightness) of the current target color, increment the hue, and then convert back to an RGB value. The color of each individual rectangle is also a linear interpolation between black and the target color, based on the frequency band’s percentage of maximum power.

Changing the current texture, from a 10×10 white square to something else, also has some very interesting effects on the way that the sound circle looks. Give that a try.

Source and Windows Installer




Change Playlist – P
Previous Song – Left Arrow
Next Song – Right Arrow
Pause – Spacebar
Increase Volume – Up Arrow
Decrease Volume – Down Arrow
Toggle Spin – S
Toggle Red – R
Toggle Green – G
Toggle Blue – B
Cycle Colors – C
Change Texture – T
Quit – Escape

HexShooter: An XNA 2D Tutorial Upgrade

XNA Game Studio 3.1

XNA Game Studio, if you haven’t heard of it, is an integrated development environment for the development of Windows and Xbox 360 games using either C# Express 2008 or Visual Studio 2008. It is essentially a Visual Studio Package which includes a set of XNA assemblies, as well as new project types to create Windows and Xbox 360 games. The latest version, 3.1, was released earlier this year and its newest features include video playback, an updated audio API, avatar support, and use of the XBox Live Party system.

In addition, budding game developers with a Premium Creators Club account can submit their game to the XNA Creators Club for peer review; if passed, these games can be sold on Xbox Live Indie Games for $1, $3, or $5. Developers receive 70% of all sales revenue for copies of their game that are purchased via Xbox Live. Not too bad a deal, though creating an independent game with mass market appeal and a decent purchase rate is no small task.

Creators Club Website

The epicenter of all things XNA is located at the XNA Creators Club Website. This is where you obtain a Premium account, submit your game for review, playtest others’ creations, and access a multitude of resources including forums and tutorials.

The 2D Tutorial

The Beginner’s 2D Tutorial uses video to demonstrate how to create a simple 2D shooter starting from a blank Windows Game project, given a couple of pre-created images. The videos walk you through creation of the game project, adding assets, drawing the background, creating cannons, firing cannonballs, adding enemies, and destroying enemies. It’s actually a very handy tutorial, and you end up with something like this (skip to 4:17)


As you can see in the video above, there are three enemy ships moving from right to left at all times, and you can shoot them to earn points. It’s pretty smooth, but there’s something important missing. Because there’s no inherent challenge, no sense of danger, and no real goal, this project is unfortunately little more than a toy, and the fun factor is completely missing. HexShooter is my attempt to take this project and change it in ways that will make it challenging and fun.

So here’s a list of some of the features I added:

  • Explosions and Smoke (from Joshua Foss’ excellent Adding 2D Particles and Explosions videos.
  • The ability to move the cannon from left to right with the left thumstick, aiming now with the right.
  • Enemies now spawn from either the left or right sides of the screen, and they bounce off the edges and come back with the same height and speed.
  • Player cannonballs are now very fast, but you can only have one on screen at once.
  • Enemies now fire green cannons back at you, and if they hit the center circle of your cannon, you lose.
  • For every ten enemies killed, a new enemy is added.

There are several reasons why I think this upgrade is a lot more fun to play than the original. First, there is the very real possibility of losing, and there is a challenge. Namely, kill as many aliens as you can while avoiding enemy fire for as long as possible. Because of the way that enemies are added, the game starts out easy but becomes increasingly challenging the more enemies you kill. Eventually you will find yourself spending most of your attention on dodging enemy fire, which reminds me of the fun and challenge of Galaga.

The choice to change the cannon to only fire one fast cannonball at once was also intentional. In the tutorial version, you can fire three cannonballs at once, but they are very slow. This makes aiming and firing tedious and somewhat pointless. With only one cannonball, you have to make your shots matter, so your aim counts.

For a while I considered creating a complete mesh-based collision detection system for the cannon, including not just the circle but the barrel too. But I realized that not only would that be a lot of extra work, but it would probably detract from the gameplay. Having to worry about your cannon aim in order to dodge enemy cannonballs is silly, and would make evasion nearly impossible in the late game.

Source and Executable

I am offering both the source code and executable for inspection and playtesting. If you want to compile and run the source you must have XNA Game Studio 3.1 installed.

[HexShooter Source]

If you just want to play the game, you need to have the Microsoft XNA Framework Redistributable 3.1 installed, and either:

Or, you could just use the keyboard.

[HexShooter Installer]

Using the keyboard isn’t too bad, but if you’d like to use an Xbox controller, I’d recommend the cheaper USB wired controller, unless you already have some Xbox 360 controllers lying around and you absolutely must have wireless controllers.


Move – Left thumbstick or A/D keys
Aim – Right thumbstick or Left/Right arrow keys
Shoot – Right trigger or Spacebar
New Game – Start or Enter

Visual Studio 2010 Beta 2 Now Available on MSDN

Visual Studio 2010 Beta 2 is now available for download on MSDN for MSDN subscribers, and will be available to the general public on October 21st. In addition, the new .NET Framework 4.0 is now available as well.

New Features in Visual Studio 2010 Beta 2

  • Team Foundation Server – Track and manage work items for your entire development team
  • Application Modeling – Create code dependency graphs, sequence diagrams, layer diagrams, and UML diagrams
  • Version Control – View source merges, branch hierarchies, and file history
  • Historical Debugger – Tracks system state as your application is running, so that you can backtrack to the source of any errors that occur
  • Performance Profiler – Measure, evaluate, and target performance issues in your .NET application
  • Editor Enhancements – Better docking control, code zoom, box selection, call hierarchy, and more
  • Brand New Start Page – Redesigned UI and new customization features
  • C# and VB.NET 4.0 – Late binding to dynamic types, covariance/contravariance, type equivalence

There are of course many other new features in this release. For a full list of new features in Visual Studio 2010 Beta 2, refer to What’s New in Beta 2 for Visual Studio Team System 2010.

New Features in the .NET Framework 4.0

  • Application Compatibility and Deployment – Applications developed on previous versions of the .NET Framework should still work smoothly in most cases. Also, the framework now supports in-process side-by-side execution of different framework versions
  • Parallel Computing – A new Task Parallel Library and Parallel LINQ
  • Improved Security Model
  • Core New Features and Improvements – Changes to diagnostics, garbage collection, code contracts, dynamic language runtime, tuples, and much more
  • Networking – Enhancements to the functionality in the System.Net namespace
  • Web – ASP.NET 4 provides many new web forms features
  • Client – New features in WPF and the Managed Extensibility Framework
  • Data – Improvements to ADO.NET
  • Communications and Workflow – Improvements in the Windows Communication Foundation

For more information, see What’s New in the .NET Framework 4.

Completely Redesigned MSDN

MSDN, the Microsoft Developer Network website, has been completely redesigned to coincide with Visual Studio 2010 Beta 2. Check it out!

Converting Managed C++ to C++/CLI

What is Managed C++?

Managed C++, also known as Managed Extensions for C++, was a set of syntactic extensions and keywords released with Visual Studio .NET in 2002 which allows you to target the .NET Framework in C++. In other words, with the release of Managed C++, it became possible to write .NET programs in C++. This is particularly interesting because unlike pure managed languages like C# and Visual Basic .NET, Managed C++ is also directly compatible with native C++ code, without having to use PInvoke or COM. In fact you can write code that mixes both unmanaged and managed C++ in the same assembly, and even within the same function! This kind of “mixed mode” interop is what makes Managed C++ so interesting.

So how does it work? Basically in addition to the standard C++ built-in types, references, and pointers, you can now declare what is known as a garbage-collected pointer to point to a managed .NET object that has been allocated with a managed new operation. As long as you keep your regular unmanaged classes and pointers separate from your managed, garbage-collected ones, you’re good to go. Here’s an example:

__gc class G { public: int i; }
G __gc* pG = new G;
pG->i = 5;
int i = pG->i;

The __gc keyword is by far the most ubiquitous in Managed C++, but there are a number of other ones:

  • __abstract: for declaring a class as abstract
  • __box: for “boxing” value types
  • __delegate: for declaring a .NET delegate
  • __event: for declaring a .NET event
  • __identifier: for using a C++ keyword as an identifier
  • __interface: for declaring a .NET interface
  • __nogc: for explicitly declaring an unmanaged type
  • __pin: for declaring a “pinning pointer”
  • __property: for declaring a .NET property
  • __sealed: protects a class or method from derivation
  • __try_cast: for a dynamic cast that throws an exception on failure
  • __typeof: for determining the .NET type of an object
  • __value: for declaring a value class

Used correctly, these keywords are all you need to write code in Managed C++.

What is C++/CLI?

Sometime after introducing Managed C++ to the world via Visual Studio .NET, Microsoft started working on a newer revision of the language specification in an attempt to supersede Managed C++. Why did they decide to revise the language? For one thing, although Microsoft chose the common extension prefix “__” for its managed keywords, developers generally thought that the syntax was ugly. Really ugly. Additionally, the code was often difficult to read and understand in ambiguous situations. So for Visual Studio 2005, Microsoft created a new language specification called C++/CLI which completely revised the language both for the aesthetics of prettier code and the clarity of unambiguous syntax.

How did the syntax change?

Handles: Where before you had to refer to managed classes using gc pointers (__gc*), now when you use a managed type you use the syntax ClassName^, to clearly differentiate managed and unmanaged objects.

Contextal and Spaced Keywords: Instead of introducing a slew of new .NET keywords, and marking them as off limits for identifiers, Microsoft chose only three new keywords (gcnew, generic, and nullptr), and the rest are either spaced keywords (for each, enum class, interface class, ref class, value class) or contextual keywords which only appear where an identifier would never appear. This was a great decision because it means that the syntax is prettier but you break very few existing programs, unless they call their variables nullptr and gcnew. Contextual keywords include abstract, finally, in, override, sealed, and where.

Tracking Reference to No Object: The keyword nullptr was introduced to represent the managed equivalent of null. Because of this change, the integral value zero no can no longer be used as a tracking reference; nullptr must be used instead.

Garbage-Collected New: To differentiate the standard C++ new keyword from a managed allocation which will automatically be garbage collected, the keyword gcnew was introduced. Anytime you allocate a new .NET object you must use this gcnew keyword.

Generics: Just as C# 2.0 added support for generics, so too did C++/CLI add support for .NET generics in C++ using the generic keyword.

Dispose and Finalize: The changes to destructor semantics in C++/CLI are complicated; destructors now go to Dispose instead of Finalize, but you can still declare an explicit finalizer if necessary. See the MSDN translation guide for more details.

There are other changes that are too numerous to list here; consult my References for more information.

Quick and Dirty Translation Guide

Managed Class Declaration
Old: public __gc class MyClass
New: public ref class MyClass

Property Declaration
Old: __property String *get_Name();
New: property String^ Name { String^ get(); }

Old: __property System::String __gc* get_Description();
Old: __property void set_Description(System::String __gc* value);
New: property String^ Description { String^ get(); void set(String^); }

Old: void Dispose();
New: ~MyClass();

Note: The Dispose/Finalize pattern has some tricky changes. See Translation Guide: Moving Your Programs from Managed Extensions for C++ to C++/CLI.

Old: String* ToString();
New: String^ ToString();

Pin Ptr
Old: std::list* __pin *pinner = &m_stringList;
New: pin_ptr<std::list > pinner = m_stringList;

Property Definition
Old: String *MyClass::get_Name() { }
New: String^ MyClass::Name::get() { }

Old: System::Double MyClass::get_Values() __gc[] { }
New: Array^ MyClass::Values::get() { }

Old: double MyReader::EndRead(IAsyncResult* asyncResult) __gc [,] { }
New: Array MyReader::EndRead(IAsyncResult^ asyncResult) { }

Array Declaration
Old: Object* args[] = { GetType()->Name, this->VirtualName };
New: array^ args = { GetType()->Name, this->VirtualName };

Managed Memory Allocation
Old: throw new ObjectDisposedException(S"MyClass");
New: throw gcnew ObjectDisposedException("MyClass");

Old: Object* myObjArray __gc[] = { __box(1), __box(2), __box(3) };
New: array^ myObjArray = {1, 2, 3}; // Now implicit

Old: System::Object* o = __box(123);
Old: int a = *(dynamic_cast(o));
New: Object^ o = z; // implicit boxing
New: int y = *reinterpret_cast(o); // unboxing

Dereferencing a GC Pointer / Handle
Old: this->Name
New: this->Name // no change

Public Inheritance
Old: public __gc class SubClass : public MyClass {
New: public ref class SubClass : MyClass { // Public inheritance by default

Implementing ICollection (New Syntax Only)
ref class MyCollection : ICollection
virtual IEnumerator^ GetEnumerator() = IEnumerable::GetEnumerator { return nullptr; }
virtual property int Count { int get() = ICollection::Count::get { return 0; } }
virtual property Object^ SyncRoot { Object^ get() = ICollection::SyncRoot::get { return nullptr; } }
virtual property bool IsSynchronized { bool get() = ICollection::IsSynchronized::get { return false; } }
virtual void CopyTo(Array^, int) = ICollection::CopyTo { return; }

For Each (New Syntax Only)
array^ classes = { gcnew MyClass() };
for each (MyClass^ c in classes)

String Literals
Old: S"Managed String"
New: "Managed String"

Try-Cast -> Safe-Cast
TypeOf -> TypeID
Old: m_bigFloat = *__try_cast(info->GetValue(S"_bigFloat",__typeof(f64)));
New: m_bigFloat = safe_cast(info->GetValue("_bigFloat", f64::typeid));

CLI Types
Old: __int64
New: Int64

Delegates / Events
Old: public __delegate void MyEventHandler(Object *sender, MyEventArgs *e);
Old: __gc class Task {
__event void add(MyEventHandler *eh);
__event void remove(MyEventHandler *eh);

New: public delegate void MyEventHandler(Object^ sender, MyEventArgs^ e);
New: ref class Task {
event MyEventHandler^ MyEvent { void add(MyEventHandler^ eh); void remove(MyEventHandler^ eh); }

Private Public
Old: private public:
New: internal:

Operator Overloading
Old: static bool op_Equality(DataFrequency d1, DataFrequency d2);
New: static bool operator ==(DataFrequency d1, DataFrequency d2);

Conversion Operators
Old: static double op_Implicit(int i);
Old: static float op_Explicit(int i);
New: static implicit operator double(int i);
New: static explicit operator float(int i);

CLI Enums
Old: __value enum Result { Pass, Fail };
Old: Result r = Pass;
New: enum class Result { Pass, Fail };
New: Result r = Result::Pass;

Old: Object* obj = 0;
New: Object^ obj = nullptr;

Visual Studio Search & Replace Strings

Use these in order, using Visual Studio 2005 with Regular Expressions, per .h file. Voila.

String RegExp
Find: String __gc\*
Replace: String^

Property RegExp
Find: __property
Replace: property

Get Property RegExp
Find: property {[^ ]*} get_{[^\(]*}\(\);
Replace: property \1 \2 { \1 get(); }

Set Property RegExp
Find: property void set_{[^\(]*}\({[^ ]*} value\);
Replace: property \1 { void set(\2 value); }

Get Array
Find: property {[^ ]*} get_{[^\(]*}\(\) __gc\[\];
Replace: property array^ \2 { array^ get(); }

Set Array
Find: property void set_{[^\(]*}\({[^ ]*} value __gc\[\]\);
Replace: property \1 { void set(array^ value); }

Combine RegExp
Find: property {[^ ]*} {[^ ]*} \{ [^ ]* get\(\); \}\n[^p]*property \2 \{ void set\(\1 value\); \}
Replace: property \1 \2 { \1 get(); void set(\1 value); }

Use the following in order per .cpp file:

Find: get_{[^(]*}\(\)
Replace: \1::get()

Find: set_{[^(]*}\({[^)]*}\)
Replace: \1::set(\2)


MSDN Translation Guide

Herb Sutter’s Blog