Archive for August, 2004

Modern C++ Design

Thursday, August 19th, 2004

Every so often, a book comes along which changes the whole way you view programming: Stroustrup, Design Patterns, and Scott Meyer’s Effective C++ and More Effective C++ are all widely regarded as classic programming texts. And now a new volume joins these exalted tomes: Modern C++ Design: Generic Programming and Design Patterns Applied by Andrei Alexandrescu.

Existing books on C++ design have skipped lightly over templates and generic programming, perhaps mentioning them briefly as a useful way of creating containers for arbitrary types (as in the STL, for example). What Alexandrescu presents here is, effectively, template programming from another dimension: policy programming (using templates to genericise class functionality, not just the types they operate upon), compile-time manipulation of collections of types using template metaprogramming, compile-time assertions, generalised functors (any C++ processing invocation, encapsulated in a typesafe first-class object), template template parameters (not a typo – using templates as parameters to templates to incredible effect) and much, much more.

But this is more than just a clever set of techniques. What Alexandrescu is presenting here is nothing short of a whole new way of approaching C++ development, one in which generics aren’t simply a convenient way of cutting down on the number of linked list classes you have to write – they’re a fundamental and massively powerful way to genericise functionality in your code.

In some ways, it’s depressing to read books like this, because within the first 12 pages you will have had to throw away everything you thought you knew about OO design (how any of this stuff maps to UML, for example, I have no idea) and start all over again. But in the end, it’s worth it, simply because the ideas presented here are just so goddamned clever. Quite simply astonishing, and one of the most significant books on C++ I’ve ever read – if you’re a C++ developer, you need to read this book; it’s that simple.

Comedy goldmine

Thursday, August 19th, 2004

Whilst digging through some boxes last night, I discovered my old high school and sixth form leaving books; you know – those exercise books you stole from the store cupboard and passed round the room so everyone could write “I don’t know who you are but have a nice life anyway” in?

The comments range from the short and succinct to the needlessly verbose. There’s a common theme running through many of the comments – see if you can spot it.

Obviously, there are the inevitable references to my choice of course at University, abuse towards teachers, topical references and plenty of cheap innuendo and commentary on my (then non-existent) love life.

The highlight of the lot, though, is this – purely because I can now unveil what it was that she wrote two years ago and was so afeared of my revealing.

(names have been obscured to protect the innocent, but some of you can probably work out who wrote what anyway)

I’ll leave the final word to JC, though. Invaluable advice, I’m sure you’ll agree.

Plan

Tuesday, August 17th, 2004

Ducks. On helium.

One year on

Friday, August 13th, 2004

I swore I’d never have a blog, and this isn’t it. It’s been running for exactly a year now, which is quite an achievement for something that doesn’t actually exist.

I should probably write some sort of retrospective thing about all the great things that have happened to me as a result of having this thing which isn’t a blog, and all the interesting people I’ve met, and phrase it all in a really clever, semi-poetic way that’ll make it seem somehow more significant than it actually is. Frankly, though, this site subscribes to enough blogging cliches already without needing to make things worse.

So, thank you to everyone who’s ever read the rubbish I churn out, especially those of you who came back again (presumably out of a morbid curiosity, to find out if I’d actually started writing anything interesting). An even bigger thanks to all those other bloggers out there whose ideas and material I’ve shamelessly stolen over the last year (although I still claim I was the first one to come up with the chav-car-flag idea). And an even bigger thanks to my girlfriend, who has to suffer me in real life as well.

Oh, and finally – apologies to Tim Berners-Lee, because I’m sure this wasn’t quite the sort of thing he had in mind when he invented the web.

Email of the year

Thursday, August 12th, 2004

Chris,

My wife and I are fans of marmots (she’s Swiss, and we have various
pictures, sketches, carvings, etc. of marmots around the house). Where
did you find the image of marmots watching TV? Is there a larger version
somewhere?

Kind regards,

[name removed]

(He’s talking about this picture, which I made for b3ta. I hope he realises it’s not real. Maybe I should point him at this, too)

Life, liberty

Thursday, August 12th, 2004

In case you haven’t been paying attention to the Mail recently, our country has gone to the dogs. Crime is rife, morality is disappearing out the window and – heavens above – criminals are now winning the lottery, which simply won’t do.

But it’s all okay, because Big Blunkett and his merry band of lackeys are coming to save us! Apparently, the problem is that this whole “legal system” thing is just far too damned complicated, with all these different types of offences for when you do different things wrong – so why not just make every offense arrestable? Okay, it might seem a bit disproportionate for it to be arrestable if you, say, drop litter, but tt’ll just save so much hassle, y’know? And anyway, I’m sure we can trust the police to use these powers in a sensible, disciplined and non-discriminatory way.

Oooh! And! And! As everyone knows, drugs are the root of all evil in the world, so at the same time, we should test everyone (same article, further down the page), whether their offense is drug-related or not – nip the problem in the bud, so to speak! That’ll work!

I love The Onion

Wednesday, August 11th, 2004

Best. Onion. Story. Ever.

Programming C#

Wednesday, August 11th, 2004

O’Reilly have an enviable reputation in the field of technical publishing. For a large number of programmers, sysadmins, network engineers and other geeks in need of documentation in dead tree format, an O’Reilly will be their first port of call. And for good reason, too – ORA books are written by techies, for techies; the information in them is generally detailed, well presented, accurate and useful. You’d be hard pressed to find, say, a Perl programmer who doesn’t own at least one, and probably several, of O’Reilly’s Perl books. O’Reilly books form about 50% of my technical bookshelf, and I’ve always been thoroughly impressed by their quality, depth and simplicity of presentation. Naturally, then, when I decided to learn C#, my first port of call was O’Reilly, and in particular, Programming C#.

Programming C# follows the standard format of any ORA ‘Programming…’ book – the first section starts with with an overview of the language, its reason for being, and a walkthrough of ‘Hello World’ implemented in C#; this is followed by a detailed description of the language fundamentals – types, expressions, variables, statements, operators, etc – and then several chapters on the powerful OO features of C# – classes, objects, inheritance, interfaces, delegates and so on. The second section focuses on practical applications of C# – Windows applications, data access, web services and building solutions. The third and final section covers the CLR and .NET framework in some detail – this is where reflection, file IO, threads, marshalling and integration with unmanaged components are dealt with. So, all well and good, so far.

Problems begin to arise, though, in the way this information is presented. The first few chapters on language fundamentals are largely okay; however, as soon as OO concepts are introduced, things start to go wrong. Complex concepts are not dealth with in a simple way, and you often feel like the author is circling around a topic, as if they are not totally sure how to approach it correctly. This isn’t helped by the use of some badly chosen examples; complex concepts are often illustrated with inadequate (and sometimes inaccurate) code snippets, but simpler ideas are laboured, with several pages are taken up with unnecessary examples and discussion. In several places, the example code given doesn’t actually match up with the discussion in the text, and often variable and method names are badly chosen. Opening and closing braces are sometimes missing and, in one or two instances, entire function or class headers have been left out – basically, the examples feel like they have been put together quickly and without much care and attention to detail. In fact, this general feeling of rushedness pervades many of the more complex topics; the reader gets the feeling that the author doesn’t want to (or cannot) explain a certain topic in detail, and so it gets rushed over in a confusing manner.

A good example of the problems I encountered is in the chapter on Polymorphism and Inheritance. C# offers two ways of redeclaring a base class method in a derived class – virtual/override and new; the difference between the two is not complex (override replaces the base method entirely; new keeps the old method, but hides it, as with variable shadowing in Java) but the book manages to avoid making this simple distinction clear, instead leaving the reader confused as to the difference; however, it talks great length about the benefits the arrangement offers in terms of interface versioning. In the end, I had to go online and find out the difference from MSDN.

The thing is, all the information you need is actually in there – you can perfectly well learn C# from this book; it’s just not especially well presented or furnished with good examples. The whole book needs a thorough proof-reading and technical review, preferably by someone who is unfamiliar with C# and will therefore notice when something is confusing or inadequately explained. It’s adequate, but could be a lot, lot better, and is certainly well below the usual excellent standards I’ve come to expect from O’Reilly.

White

Tuesday, August 10th, 2004

Nothing much to say – a new theme for your delight and delectation. The look is partly stolen from Lori‘s new look, and partly because white is apparently the new slightly-dark-orange this season. It’s quite a serious looking theme, but I shouldn’t have thought that’s going to mean you’ll suddenly start to get thoughtful, serious postings from me, though; it’ll just be all the same old crap, I’m afraid. All the old themes are, naturally, still there to choose from.

(incidentally, I’ve checked the appearance of the theme in IE and Firefox and it seems to work in both; leave a comment if it’s broken in your browser and, if feasible, I shall endeavor to fix it.)

Edit – I’ve tweaked it slightly to put a nicer logo aligned with the right-hand edge of the article border. It took 30 seconds to do it in Firefox, and then another half-hour or so of swearing, consulting W3, cursing the name of Bill Gates, and eventually just trying stuff at random before it worked in IE; it appears to be something to do with IE getting terribly confused if you set both the left: and right: attributes of a block if the body block has margin-left: set to anything other than 0px. In other words, it’s well bent. Boy, am I ever glad I changed to Firefox.

Actionsampler

Saturday, August 7th, 2004

Just before I went to Prague, I picked up an ActionSampler from a shop in the Trafford Centre. It was only £15, and I figured it’d be a bit of fun if nothing else. In actual fact, it’s quite, quite remarkable – it’s a cheaply constructed piece of plastic rubbish that leaks light, sometimes fails to wind on, blurs, doesn’t focus, has no exposure control, or anything. But it takes some really quite astonishing pictures. The best of the first film is up over on the gallery now.