Tuesday, 18 November 2008

Article: This "Software" Stuff

The next issue of ACCU's C Vu magazine is out now, containing my latest Professionalism in Programming column. Entitled This "Software" Stuff, it's the first part of a mini-series investigating what software development is really all about. It's your chance to find out what happens when you mix custard and spaghetti.

This issue of C Vu was editted by Gail Ollis, and contains articles on virtualisation, PC-Lint, debugging, as well as Matthew Wilson's ruminations on C and C++.

For the cover design. I thought I'd break the mold and go for an industrial "grunge" feel this month. I think it worked pretty well. It was the first time I've used Gimp 2.6 for print work, and it was great fun.

Friday, 7 November 2008

Kubuntu 8.10 on Parallels

Kubuntu 8.10 is out, full of KDE 4 goodness (honestly, that's not sarcasm - KDE4 is quite usable these days). I've been running it under Parallels on Mac OS, and there's good news and bad news...

The good news

Kubuntu 8.10 works really well under the beta of Parallels Desktop 4. But it's not out yet, and we're not allowed to talk about it. You never heard it from me.

The bad news

Kubuntu 8.10 does not work under the current release version of Parallels Desktop 3. As soon as KDE4 attempts to start, the video mode goes wobbly and X restarts. kdm goes on an infinite start-crash-start-crash loop. It's great fun for the first thirty restarts or so.

So what's going wrong? I'm not entirely sure. You can start X by hand fine. And you can run X apps, so it wouldn't appear to be a video support problem. I've been tinkering with bits of the startkde script. The failure stems from the call to the ksmserver, which handles the majority of the bringing up the KDE session. It's around about here that my enthusiasm for debugging left, and I escaped back into Parallels betaland for a simpler experience.

Helpfully, if you try to start a failsafe X session under Parallels 3, it fails for entirely different reasons.


Friday, 31 October 2008

C++: Restoring the meaning of a name

I have updated a previous blog entry about a C++ name-scope issue with a solution.

Thanks to the commenter jd who provided the solution.

A MacBook Pro hard drive upgrade

I have just upgraded my 15" Macbook Pro with a larger hard drive. The machine was shipped with a 120G hard drive when I bought it. Times move on, and data accumulates. Cubase projects and Parallels virtual machines quickly fill up precious space.

Hard drives are not a user-upgradable component of these notebook models, but there are plenty of descriptions of how to disassemble a MacBook Pro available on the net. To their credit, MacBook Pros are relatively easy to pull apart and very well-made machines. Still not as serviceable as an IBM (or Lenovo, or whatever they're called these days), but not bad at all.

The upgrade is perfectly simple for anyone with technical competence, a little bravery, and a torx size 6 screwdriver.

The drive

I installed a 320G Western Digital Scorpio drive, which seems a very good choice. It's a high-performance 7200RPM drive. WD claim that it consumes a comparable amount of power as an equivalent 5400RPM drive - a claim I can't validate this yet, except to say that battery life doesn't seem significantly shorter than with the previous drive.

A jump from 5400 to 7200RPM is great. The result is a snappier machine which handles better when running many tracks at once in Cubase. Software build speeds are marginally faster. The machine boots more quickly, too, but I tend to reboot infrequently anyway.

Running XBench tests before and after give compelling results:
  • Sequential uncached writes increase from 18.3MB/sec to 55.5MB/sec
  • Sequential uncached reads increase from 9.1MB/sec to 19.7MB/sec
  • Random uncached writes increase from 9.8MB/sec to 31.7MB/sec
  • Random uncached reads increase from 8.2MB/sec to 24.93MB/sec
Installation

The only interesting part of the process was working out how to migrate my old data onto the new drive.

Previously, I've performed a Leopard install with the old drive attached over USB; the Mac OS installer magically notices the old drive and offers to migrate the data over. I tried this. but it didn't go as planned - not all the data migrated over (a whole load of components and programs didn't move across) and the installer still forced me to register and add a new user, despite there being a number of users that had just migrated over. Less than full marks, then. I wonder whether this was due to the Leopard version on the old disk being ahead of the install DVD version?

There are suggestions that a Time Machine backup is a good migration strategy. But I fear that this will fail in pretty much the same way.

The solution is simple, though:
  • Boot the machine from the Leopard install disk.
  • Select Disk Utility from the Tools menu.
  • Partition the new drive with a suitable partition table to boot an Intel machine. Create a single journalled HFS+ partition.
  • Click on the "Restore" tab and restore data from the old drive (make the old drive the Source) onto the new drive (make the new drive the Destination).
  • Ensure that Erase desination checkbox is selected.
  • Click on OK.
  • The old data is copied onto the new drive's parition.
  • You now have a carbon copy of yor old drive, covering the entire surface of the new drive.

Friday, 24 October 2008

C++: Changing the meaning of a name

We've just bumped the version of gcc we use to build our codebase from 4.2.2 to the shiny, cutting edge 4.3.2. This involved the usual number of small tweaks to our source, to make it compatible with the latest gcc parser.

One change surprised me, though. The following pattern is no longer accepted by gcc:
template <typename T>
class Producer
{
public:
/// ...
};

template <typename T>
class Consumer
{
public:
typedef Producer<T> Producer;
};

void ThisWontCompile()
{
Producer<int> producer;
Consumer<int> consumer;
}
gcc now generates the following error:
test.cpp:13: error: declaration of 'typedef class Producer Consumer::Producer'
test.cpp:4: error: changes meaning of 'Producer' from 'class Producer'
We use this pattern quite a lot in our code, and it seems reasonably tasteful. Certainly, it seems morally equivalent to the following pattern:
class Foo
{
public:
/// ...
};

class Bar
{
public:
void Foo() {}
};

void ThisCompiles()
{
Bar bar;
}
...in the sense that they both change the meaning of a name within the scope of the second class.

Now I'm no C++ language lawyer, but I've yet to find a compelling part of the standard that shows this to be bad C++ code.

Update

Commenter jd pointed out the solution to this conundrum. The Producer example above will compile if the typedef is written slightly differently, thus:
template <typename T>
class Producer
{
public:
/// ...
};

template <typename T>
class Consumer
{
public:
typedef ::Producer<T> Producer;
};

void ThisDoesCompile_Hurrah()
{
Producer<int> producer;
Consumer<int> consumer;
}
This shows that the gcc change was not as drastic as I first feared, and the fix is still very valid (and very readable) C++ code.

The problem was gcc looking up the name Producer in the scope of the Consumer class, and finding the Producer typedef name that was in the process of being defined. A subtle problem with a non entirely useful error message (but we're used to those, aren't we?).

Although the other compilers I have tried (MSVC and Comeau) accept the original code, I'm not sure if it is correct according to the letter of the C++ standard or not.

Tarballs, tarballs everywhere (or "More madness of glibc")

My previous posting on the packaging of GNU's glibc project seems to have created quite a stir (see here and here). There's been lots of informed, and some uninformed, debate on the subject.

The glibc project has taken the informed choice to abandon the traditional tarball method of source code release, instead directing developers to get the code from the project's CVS repository directly. Thankfully, following my earlier post, instructions have been put up on the public website so it's now clearer how to obtain the latest version of the glibc source from CVS. So my initial problem has now been solved. Thanks, guys!

Now, clearly this isn't the End Of The World. And any developer capable of working usefully with glibc should be more than competent enough to operate CVS themselves. So stop whinging and get over it... right?

Wrong.

The madness of CVS

Source code projects should always be developed using a Source Code Management system, like CVS (or Subversion, or perhaps a more modern, fashionable, distributed SCM like Bazaar). This is common sense. It's good practice. It's important. Each release should be managed in the SCM on a release branch, and public code drops should be recorded with tags (or labels). This is accepted release engineering practice.

However, downloading a source code release from CVS (or any other SCM) is a really poor distribution mechanism. Here's why:
  • It's not conventional. Unix source packages are traditionally distributed as tarballs (either tar.gz or tar.bz2 tarballs). It's the way the world works. Not providing tarballs forces users to work harder, and makes them less likely to use your code. However, this is not a compelling reason for glibc to distribute tarballs. Indeed, for glibc it's not even an issue. The project is important enough that people will do whatever is necessary to get the source. The glibc developers can distribute their code however they like. And I'll always say thank you.
  • It's not secure. Downloads sometimes go wrong. Unusual, but it can happen. Servers can also be hacked, and the code fiddled with. The accepted convention for this is to distribute MD5 checksums of the source tarballs that the downloader can use to ensure that their tarball is indeed the original. It's far easier to do this on a tarball than a CVS checkout (and there is currently no check mechanism for CVS exports from glibc). This is important, but is also not a compelling reason for glibc to distribute tarballs.
  • It's failable. By definition, the code in an SCM is dynamic. It changes over time. The codeline in the release branch changes as the release nears completion. True, the 2.7 relelase, and the 2.8 release and the 2.8.1 release can be individually tagged. However, these tags are dynamic. There is no guarantee that at a point some time after the 2.7 release, someone can't go back to the CVS repository and move the 2.7 release tag. The glibc 2.7 release could be different on Tuesday that it was on Monday! Sure, good developers shouldn't do that. But they might. By mistake or otherwise. In less capable SCM systems, like CVS, there is no way of usefully tracking the history of the tag. Release tags in CVS are not static. The only safe way to construct a stable, unchanging release snapshot of the code is to archive a tarball. Say, on an FTP site. This is a compelling reason not to download glibc source code releases from the project's CVS repository.
I believe that CVS access is simply not an acceptable release mechanism for the glibc, or for any other, project.

There has to be another way

Additionally, people have been pointing out third party ways to get glibc more easily, or to track its progress more easily, like an external gitweb interface. This is also not an acceptable solution for easily pulling glibc releases. As a developer who would like to use pure, unadulterated glibc source code release, I can only accept source code that I obtain directly from the glibc project themselves.

I know these third parties are trying to perform a useful service, and are doing this with the best intentions. But, unfortunately, I can only accept source code drops that come directly form the official project. Not from unverifiable third party mirrors, or from tarballs packaged by a third party (like Fedora - how can I be sure that over time they won't put their own Fedora-specific patches in their version of glibc?)

If these are useful services, the providers should join the hard working glibc team, and perform their packaging services under their umbrella as an official service.

Postscript

I have nothing against the glib developers, or the glibc project itself. I appreciate all of their hard work. I offer this as constructive feedback. And I particularly do not like personal abuse directed at individual people. They are all hard working, clever guys who benefit the community greatly. I hope that I give back to the community a fraction of what they have done!

Thursday, 23 October 2008

On GIMP 2.6 and the Mac.

Not so long ago, version 2.6 of The GIMP (The Gnu Image Manipulation Package) came out. If you don't know the GIMP, think Photoshop but open source. Well, GNU actually, but that's a different bunfight...

Version 2.6 isn't massively different from the previous 2.4 versions, but has enough new stuff to be very interesting.

Since I'm mostly a card-carrying mac Weenie these days, I waited patiently for a 2.6 release to arrive. To no avail. Until very recently, there has been no official mention of a 2.6 release on the gimp download page.

So I did a little digging. The GIMP website used to point you to the Wilber Loves Apple pages. But that project has unfortunately nose-dived with an acrimonious ending. Shame, they did a great service for the Mac community.

But, fear not... it turns out there are a few other GIMP port projects for the Mac. (Let's not spoil things by complaining that there should be just the one port, and it should be under the auspices of the actual GIMP project proper):
  • Gimp.app has existed for some time, but when I investigated, it's 2.6 port was still considered very experimental, and that doesn't inspire me with confidence.
  • MacPorts provides a way to build The GIMP from source. But unless you want to commit to the MacPorts world this is a somewhat heavy-handed way to get The GIMP. And the average graphic weenie doesn't have the technical nonse to do this. (Let's not consider whether the average graphic weenie would be using The GIMP in the first place).
  • MacGimp either doesn't exist any more (I can't get the website to load) or is commercial - which kinda defeats the purpose of using The GIMP.
  • gimponosx appears to be the new kid on the block, started by the main contributor to the Wilber Loves Apple project. They've produced a 2.6 release that appears (as far as I can see) to be perfectly stable and works as well as the previous ports. I've used it under Leopard on PPC and Intel machines. Go get it now if you like The Gimp!
Postscript: The GIMP download pages on a mac now point you to the gimponosx packages, so they have become the de-facto Mac GIMP port.

And whilst you're downloading, do yourself a favour and get an up-to-date version of X for Mac OS. It makes a huge difference.