Doing Arithmetic in Ant

Recently, I was surprised to find that Apache Ant has no built-in means to do simple arithmetic. Thankfully, there is a way to do arithmetic with a default installation of Ant (provided you are on the Windows platform).

In the Windows Command Prompt, you can do basic arithmetic as well as bit shifting by using the “set” command with the “/a” command line switch. (Type “set /?” for more details.)

If you wanted to store the result of ${propA} + ${propB} in the answer property, you could use the exec task like so:


<exec executable="cmd.exe" outputproperty="answer">
<arg line="/c set /a ${propA} + ${propB}"/>
</exec>

Here, the command prompt executable (cmd.exe) is used with the “/c” switch to run the “set” command with the “/a” switch. Everything that follows the “/a” is the arithmetic expression to evaluate.

Visual C++ 10 (Visual Studio 2010) Resources

Here are some great links to videos and pages about the changes and new features of Visual C++ 10 (Visual Studio 2010) for C++ developers:

Great series of posts about the new features in Visual Studio 2010

Very thorough coverage of “rvalue references” and how they can be used to improve performance

Lambda Expressions in Visual C++

Channel9 video about the C++0x nullptr and the situations in which you need it

Channel9 video about STL iterator debugging and some STL features in general

Capturing Ctrl+C, Ctrl+Break or the window close event in a Windows console application

Recently, I was developing a multi-threaded Win32 console application and I wanted it to run until the user hit Ctrl+C (or Ctrl+Break). It was difficult to find good example solutions using Google search. Because of this, I decided to post my solution here.
Continue reading →

A Simple Way to Improve the Quality of Your Code

When I write new code, or when I am modifying existing code, I ask myself a series of questions which force me to look at the code from different angles. This allows me to notice issues I might have missed otherwise.

Here are the kind of questions I tend to ask, organized by the situation in which I would ask them:
Continue reading →

How to Design a Good API and Why it Matters

Here is a great talk about designing an API (or even just a library) and good programming practices in general.

Visual Studio 2010 Release Candidate Now Available for All

In case you had not already heard, the Visual Studio 2010 and .NET Framework 4 Release Candidate are now available for anyone to download for free.

Earlier, I attempted to download Visual Studio 2010 Beta 2, but apparently, it did not work with 64-bit versions of Windows (or at least not Windows 7 x86-64). I’m looking forward to see how it performs, as it is probably time for me to upgrade from Visual Studio 2003.

The Super Bowl made me buy this song

If you’ve watched the Super Bowl, or if you’ve seen trailers for Where the Wild Things Are, you’ve probably heard this song. I heard it several times in various Super Bowl ads, and I thought, OK, I have to buy this now.

Wake Up by Arcade Fire

VMWare Fusion 3 Windows 7 Bootcamp Activation Issue Fix

I own a MacBook Pro. I love MacOS X, but I still regularly need to use Windows software, so I used bootcamp to install Windows 7 alongside MacOS X on my MacBook Pro.

Eventually, I got tired of having to reboot my machine to use Windows, so I installed VMware Fusion 3. I was amazed to find that Fusion could actually run my Windows 7 bootcamp partition as a virtual machine inside MacOS X. I was even more amazed to find that I could still directly boot into Windows 7 even after running it as a virtual machine. I figured that Windows would have a complete fit after having the underlying hardware swapped in and out so frequently.

Although Windows 7 runs fine in both environments, it turns out that Windows Activation cannot deal with the hardware differences in the VMWare Fusion virtual machine environment, and it thinks that you are either running a pirated version of Windows or that you tried to install Windows 7 on more than one machine. But, thankfully, it turns out that there is a fix.
Continue reading →

Kindle / Nook / iPad

I was in the bookstore yesterday looking for a book on CSS so I could make this website look pretty. Normally, I would just order the book from Amazon.com because it’s usually much cheaper than the local bookstore, but I was feeling impatient and wanted to start reading the book right away.

It was right after I entered the bookstore that it occurred to me: why am I still buying physical books? If I had a Kindle (or something similar) I could have almost any book I wanted, I could have it instantly, it would be much cheaper than if I ordered a physical book or bought one at the mall, (if the mall even had the book I was looking for) it wouldn’t take up any space on my bookshelf, (which is already full) nor would there be anything I had to drag around with me when I moved nor would there be anything to get rid of when I no longer wanted the book. Such a device would quickly pay for itself and may even save me money in the long run (provided I could hold off on buying newer versions of the device).

I wondered what would happen if many people came to this same conclusion. Would people still buy physical books? Would bookstores disappear? How would it affect the paper industry and industries that support the paper industry? Would it be greener? How much might it reduce CO2 emissions and air pollution (due to the reduction in tree harvesting, manufacturing and transportation of physical books)?

I do have some concern about the disruptions that this technology could cause, but the benefits are hard for me to ignore. I suspect devices like the Kindle will put us another step closer to the future often depicted in science fiction: all information instantly and conveniently available from anywhere.

Why you get errors when you try to access certain special folders on Vista and Windows 7

I remember poking around the directory structure when I was new to Windows Vista and I was puzzled by all these “Access Denied” errors I would get when I tried to open certain special folders. I figured it must have been some sort of bug or configuration issue and it made me seriously question the stability of Windows Vista. Well, turns out that behavior is by design.

The short version is that it’s designed that way on purpose to avoid an infinite loop on a recursive directory tree-walk.

The long version is explained by Raymond Chen.