Idiomatic C/C++: Avoiding Assignment Vs. Equality Errors

October 25th, 2007

This is a bit of idiomatic c/c++, that is to say that this isn’t part of any standard, it is just “the way things are done” in c/c++. Ever made an error in a conditional using the assignment operator (=) instead of the equality operator (==)? I know I have, but not so much anymore. The trick is that when you are comparing a variable to a constant to put the constant first. This way if you mess up you will get a compiler error stating that you can’t assign to a constant. This is much preferable to a potentially subtle bug that will no doubt bite you when a deadline is looming. So instead of:

int x;
if( x == 5)
    ; //Do something


int x;
if( 5 == x)
    ;//Do something

Picking and Matching Colors the Easy Way

October 25th, 2007

If you’re developing a game or creating a web site for your game (or even just painting a room) you will need to pick out a color scheme. If you are anything like me you are a bit of a color idiot when it comes to this activity. I have found a great took that takes all the guesswork out of picking colors and makes it easy enough even I can do it: Agave. Agave lets you pick a color and it will generate a color scheme of your choice based on that color. It can generate any of the following six types of color schemes:

Split Complements

For a brief description of just what each of those color schemes are hit up the Wikipedia entry for Color Wheel. Once I started using Agave to pick out my color schemes, people stopped complaining about my color choices every time I asked for feedback. One more tool to keep in the arsenal.

Cygwin: Bash Prompt Here

October 24th, 2007

As I’ve already discussed it is quite easy to get yourself a nice little shell called Cygwin on Windows. Once you start using Cygwin it can be quite addictive, I can’t work on Windows without it. The biggest problem is that to get to any of your data outside of the home directory under Cygwin requires navigating through the sometimes unintuitive directory structure under Windows. Typically what happens is you locate the folder with the stuff you want to work on using the Windows explorer and then work your way to it again using Cygwin. This is a somewhat less than efficient use of your time.

Luckily Cygwin comes equipped with a little utility to help you out with this problem. It is called chere and make sure you install it when you install Cygwin. chere installs an entry in the context menu when you right click on directories named “Bash Prompt Here.” Selecting it will open a Cygwin shell with the current working directory set to the directory you right clicked on. To install it simply run this from Cygwin:

chere -i

For more information on chere run this from Cygwin:

man chere

From Madness to Synergy

October 24th, 2007

If you’re like me you have multiple machines all running at the same time (check this out to see how you can use some of that aggregate computing power to speed up your compile times). The problem becomes how to use all of those machines effectively. Do you give each machine a mouse, keyboard, and monitor? It works but it slows you down, you’re constantly moving to get to the keyboard and mouse and to see the monitor for another machine. It also requires an enormous amount of desk space. Do you buy a kvm switch and share a single mouse, keyboard, and monitor between the machines? This is somewhat less than ideal. You can’t see what you’re doing on one machine while working on another. There is no real coordination between the machines either. When you factor in the prices for a DVI kvm it really isn’t much cheaper than giving each machine its own accessories. The solution I’ve found is software-based and it is called Synergy.

Synergy allows you to share a single keyboard and mouse among a number of different machines. Those machines don’t even have to be running the same operating system! I have three machines and monitors set up with one for Linux, Windows XP, and Mac OS X. I share one keyboard and mouse among the machines using Synergy. You simply tell it the arrangement of your monitors and it will transfer keyboard and mouse input to another machine seamlessly as you reach the edge of the screen. That in and of itself is fantastic but on top of that Synergy will sync screensavers and, more impressively, will sync clipboards between machines (and operating systems). You read that right, you can copy on one machine (say running Linux) and paste what you copied onto another machine (say running Mac OS X).

For those running Mac OS X or Linux I highly suggest QuickSynergy. It allows you to more easily set up Synergy. For the Windows folks there is no QuickSynergy for you but the official Synergy software is fairly easy to set up.

Speed Up Your Compilation Times

October 23rd, 2007

For those who may have missed a couple of these, here is an index to the Speed Up Your Compilation Times series: