Reading recommendation: Pragmatic programmer

If you really enjoy programming, then this book is for you: The pragmatic programmer. Finally a book that does not try to put programming into a software engineering corset, but treats it more as a craft. Of course you still get ideas how to plan your project, but it clearly states where excessive planning can cause more problems than it solves.

Moreover, it has many small little helpers for everyday problems, and offers a lot of new insights. Very refreshing read!

Back, catching up

I've been totally cut off for the last two weeks (no internet access at all; the posts you saw were pre-recorded), and quite a lot happened in these two weeks. Coming back, I've found:

  • A new version of AnkhSVN
  • CMake 2.6.2 is out, fixing a nasty bug with Eclipse projects
  • Firefox went to 3.0.3 from 3.0.1
  • Thunderbird was upgraded to 2.0.0.17
  • Sunbird was upgraded to 0.9, bringing quite a few changes
  • Expression Media SP1 came out
  • A new nVidia driver

I mean, this was two weeks, not two months -- looking back, it's amazing to see at what pace the industry is moving sometimes. For more "on-the-topic" blog posts, I'll hope to have a new blog post ready for the next week. If you have a special wish what to post about (graphics related, C#/WPF development & C++ preferred), just drop me a line.

Fedora Linux: An easy to use Linux for work (with CUDA)

Recently, I wanted to play around with CUDA a bit. Unfortunately, CUDA does not support Visual Studio 2008 yet, so I had to fall back to Linux. As I didn't want to fiddle around with Linux on my desktop, I gave it a try on my notebook which also has a CUDA capable graphics device (GeForce 8600M GT).

Looking around for operating systems supported by CUDA, I thought I'd give Fedora a try. I've been mainly using Ubuntu/Debian when I needed Linux (during my last term, I had a cut-down Debian running in a VirtualBox), after I had some really bad experiences with Fedora.

This time however I'm really happy I've chosen it. I've used Fedora 9 for x64. Some observations:

  • Installation was pretty fast, and worked fine on the free disk space I provided
  • Installing the nVidia display driver for Fedora 8 worked. You have to run init 3 as root before you can install it. As my wireless LAN was configured using KDE, I had to use a cable so the display driver could download the kernel module during the installation. Moreover, you need the kernel-devel package (yum install kernel-devel and you are ready to go).
  • CUDA worked just fine. You need to install the toolkit first (as root), then the SDK (as a normal user). The toolkit does not compile with GCC 4.3 out of the box. There are several places where you must add #includes to get it working (mostly string.h, stdlib.h and similar. GCC 4.3 aggressively reduced inter-header-inclusion, which leads to undefined symbols here). You'll need some more packages to get everything compiled. Install the freeglut.i386 package. After that, you have to do some symlinks so it gets found -- ln -s /usr/lib/libglut.so.3 /usr/lib/libglut.so (same for lib64). Finally, you need the glibc-dev.i386 package.

    CUDA reduction example
    CUDA reduction example on Fedora 9

  • Compiling Boost 1.36 worked out-of-the-box. Just make sure you compile bjam yourself instead of running make, as by default, the attached makefile will build all of Boost, which can take a while.

  • Fedora 9 comes with an ancient version of CMake. Compiling works fine - CMake doesn't have any external dependencies.
  • Fedora 9 comes with KDE 4, but updates to 4.1 immediately. Don't worry if your desktop is mostly broken on the first run.
  • Power management doesn't work for me when on battery (yep, you read it right). That is, on battery, the CPU is running at 100% nearly all the time, while it gets clocked down when running with my power supply is attached.

All in all, I'm very pleased with Fedora so far, and I already started with porting some stuff over to Linux.

CMake – A build tool that just works

I've been using CMake 2.6 for quite some time now, and the more I do, the more I like it. Just a few days ago, I started with porting some project to Linux, and it took me literally a few minutes until I had the build going and started fixing portability problems in the code.

Basically, what CMake does (besides causing constant problems with my spelling checker who thinks it should be written Cmake) is to generate build files. It supports a variety of platforms and build tools. On Windows for example, you can generate build files for Visual Studio from version 6 to 9, including x64 versions, and nmake files (plus some other types). This is really helpful if you have for example an application that has to work on Win32 and Win64, as you don't have to maintain two sets for the configuration. Moreover, you keep the option of porting it to Linux open.

And this is the killer-feature: It really works! Even if you started on Windows, your project will work (unless you used non-portable stuff) directly on Linux. No matter how complicated the dependencies are, whether you have pre- & post-build steps, if it is valid for CMake and works on one platform, it'll also work on another. You can't take this for granted: Previously, I've been using SCons, which usually required quite some work even to support several compilers on one platform, which was a major pain.

There are still some caveats you should keep in mind:

  • Linux is case sensitive, Windows not. Make sure you spell the filenames right, or you'll get errors (you will get errors during #including later, too ;) ).
  • Beware that Linux comes usually with far more libraries than Windows, which will be found directly using the various Find* module scripts. I've been searching for Boost, and instead of finding my custom 1.36 install, it found (by default) the system installation which was 1.34.1.
  • Checking for the architecture on Linux requires to look at CMAKE_SYSTEM_PROCESSOR as there is no CMAKE_GCC_64. A simple IF("{CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64") should do the trick.

Displaying listings in LaTeX beamer slides

If you are using LaTeX for presentations, you usually use the Beamer package. If you are serious about listing, you probably use the Listings package -- but what if you want nice code listings in a presentation?

Actually, it's quite easy, all you need is:

\begin{frame}[fragile]
\frametitle{Your title}

\begin{lstlisting}
code
\end{lstlisting}
\end{frame}

That's it, and you can use all fancy formatting options inside your slides (boxes, shadows, line-numbers, etc.). Just make sure you don't use the short-hand \frame{ ... } and that you add the [fragile] to each slide that contains a listing.