Understanding C++ 0x: Type safe enumerations

July 6, 2011

Categories: C++

The problem:

It takes only a quick switch to a language like PHP to recognize how handy enumerations (‘enums’) are in C++. Enumerations are especially useful for mapping from hard-to-express real-world concepts to code. For example:

enum Colors {
   Blue,
   Green,
   Purple
};
enum Animals {
   Donkey = 1,
   GiantSquid,
   Gazelle
};

Colors favoriteColor = Blue;
Animals desiredModeOfTransportation = GiantSquid;

Read more

Understanding C++ 0x: The ‘auto’ keyword

July 6, 2011

Categories: C++

There are few phrases that cause stoic C++ programmers to weep like “iterator loop”. Your run-of-the-mill iterator loop looks like this:

for(std::vector<std::wstring>::iterator it = fruits.begin();
    it != fruits.end();
    ++it)
{
   // The carpal tunnel hurts so badly
   std::cout << (*it) << std::endl;
}

Read more

Understanding C++ 0x: Lambda functions

July 2, 2011

Categories: C++

I’ll make a bet with you. I’m going to guess that, quite frequently, when coding in C++, you have the following thought: “I really need a function that does X, and the function is really only a couple lines long, but now I have to go declare and define the damn thing somewhere …” There’s no denying the fact that creating a new function in C++ comes with a certain amount of tedium and mental overhead, and there are just some times where the code within the function doesn’t seem like it would justify defining the function in an entirely different place. Well, have no fear, the C++ standards committee shares your concerns, and they’ve imported a nifty feature present in many other languages called a lambda function, and let me tell you, it is sweet. Read more

Understanding C++ 0x: Function pointers

July 1, 2011

Categories: C++

What is a function pointer, anyway? Well, imagine that you’re just a wee lad(dy) in your grassy backyard playing a game with your brother Al, your sister Beatrice (the name’s a family tradition – she never liked it), and one of your cousins in town for the holidays. The rules of the game are as follows: each person writes down one action on a slip of paper and then sticks that slip into a hat. You then take turns drawing actions from the hat, and whatever action you draw you’re stuck doing. The game goes as follows:

  1. Al draws a slip that says “Do three cartwheels”. He does three cartwheels.
  2. Your cousin draws a slip that says “Eat mud”. Luckily for your cousin, he won a mud-eating championship in his younger years. He eats the mud.
  3. Etc…

This situation is strikingly similar to how you can use functions and function pointers in C++.

Read more

A new series: Understanding C++ 0x!

July 1, 2011

Categories: C++

For those of you who are C++ lovers out there, you probably know that a new standard has been in the works for quite a while (some would argue since the dawn of time) that implements some pretty neat things. The standard is called C++ 0x and adds all sorts of handy tools to our pocket protectors including lambda functions, function binding, type inference, and a much prettier syntax for function pointers. If you don’t know what those mean, then fear not: over the next few days I’ll be trying to cover some of the more exciting features of the new standard and how you can use them in your everyday coding. Many of these will make your life much, much easier. The best part is that lots of the features are already implemented in many compilers, including most newer versions of gcc (UNIX) and Visual Studio (Windows). If you’re wondering whether the compiler you’re working on supports the new features, the best way is to get out there and try to compile some code.

Now that we’ve got that business out of the way, it’s time that we get to the meat: today’s topic is function pointers!

“Complexity – isn’t that what we’re paying you to hide?”

June 29, 2011

Categories: General

At the dawn of the computer age, when Tyrannosaurus Rex carefully crafted their punch cards to be used on non-time-sharing computers and threw their tiny arms up in frustration whenever a mosquito crawled into the system, there wasn’t a great divide between the programmer and the user. As a fact of the matter, it took so much skill just to use a computer that the programmer could assume that the user had some basic understanding of computers and their inner workings. When something unexpected happened in the program, it was perfectly acceptable to throw up some error message in a dialog box that cryptically proclaimed, “Unexpected HRESULT from function CreateWindow” because there was actually a pretty decent chance that the user understood what that meant.  Read more

The birth of Google+

June 28, 2011

Categories: General

Google announced its new social strategy today: Google+. It’s made up of a couple of features, which I’ll tackle one at a time: Read more

The Pomodoro Technique

June 27, 2011

Categories: Smart work

A few weeks ago I stumbled across a time management system called the Pomodoro Technique. “Ahhh, like GTD/Covey/yadayadayada” you say – I can hear your groans even across the entire interwebs. However, the system came highly recommended by the e-famous Microsoft evangelist Scott Hanselman and I knew how much of a nitwit I am next to Scott Hanselman, so like any other thinking human being, I just decided to rip his idea like nobody’s business. Regardless, I’ve tried other “focus” techniques in the past with mixed results, but the end result of each was the same – a few weeks of mediocre results followed by never thinking of the thing again. Read more

‘Why’ is more important than you might think

June 16, 2011

Categories: Smart work

We’ve all met people in our lives who’ve infuriated us with their ability to learn new concepts at amazing speeds. It’s inexplicable – it seems that any time I try to have a conversation about bettering the education system in the US, a person pops into the conversation asking why it was that he was able to succeed with minimal effort in school if education is really so important. It’s a topic that we should all be interested in – learning quickly is ultimately what makes us successful at the things we do.

Read more

SpryMap v2 (The Revenge?)

June 9, 2011

Categories: Javascript

So just call me Duke Nukem – I may have an absurdly long time between release cycles, but the important thing is that the next version is better. Such can be said about v2 of SpryMap, where three minors changes have been made to the original script:

  • Multiple SpryMaps can be now instantiated on the same page. Thanks to Matt for helping to figure out what was causing the problem. (Those pesky closures…)
  • The directory requirement for the hand cursor no longer applies. Thanks to Nathan Brauer for suggesting an alternative that eliminated this requirement.
  • The script is now under the MIT license.

Also, I’ve posted the original (unminified) source code for the world to see. You can download the script and examples here. Besides that, my original post regarding how to use SpryMap still applies. I’m hoping to continue some development on it in the future, but I wanted to at least fix the known bugs before moving forward. Read more