Flatlander
All the maps agree...


Subscribe to "Flatlander" in Radio UserLand.

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog.


29 September 2002
 

The fish have started to reappear, and the mystery of what they've been up to all summer is solved: I'm pleased to announce the patter of tiny fins.
8:33:12 PM    

Andrei Alexandrescu, Modern C++ Design

Most good computer books enhance your understanding -- of theory, of practice, of process, whatever.  It's rare to find one that transforms your understanding.

Alexandrescu's thesis is simple: that modern C++ is expressive enough to be used as a design language instead of an implementation language.  His first example, policies, illustrates how the language enables you to express design choices -- for example, whether to create objects via operator new or from prototypes, or how a smart pointer should manage ownership or thread-safety -- as template parameters.

This in itself is a pretty dramatic step forward for C++, but Alexandrescu then combines it with the concept of typelists, a way for code to talk about types themselves instead of just object instances.  Armed with policies and typelists, Alexandrescu goes on to provide generic implementations of design patterns such as Visitor and Abstract Factory.

Think about this for a minute.  With Alexandrescu's techniques, you can express a design pattern directly in code.  It's no longer a matter of recognising the pattern and manually implementing the code for it.  Once you've made the design decision -- for example to use Abstract Factory -- you can express it directly in the code via Alexandrescu's AbstractFactory<> template.  And because AbstractFactory<> is parameterised by the list of types and the creation policy, you can equally easily express the design decisions of which types the factory creates and how it creates them.  The language allows you to directly express these design decisions instead of implementing them.

This, for me, is a transformational change.  I'm used to C++ as a language for expressing low-level choices.  I'm used to vocabularies for expressing design choices at a documentation level.  What's new is the way Alexandrescu's C++ gives us a vocabulary for expressing and executing design choices directly at the code level.

In the interests of realism, I should point out that Alexandrescu uses advanced language features that are currently poorly supported by some popular compilers.  (Oh, all right, let's name names: the Microsoft compiler isn't up to the job.  To be fair, Microsoft's C++ team have said that compiling the Alexandrescu library is one of their top priorities: but for the time being, if you're using Visual C++, you're out of luck.)  But this is almost beside the point.  Compliance will come, and pioneering yet practical work like Alexandrescu's is exactly the incentive the compiler vendors need: who wants to be the only vendor who can't handle AbstractFactory<>?

In any case, this would be worth reading even if no compiler were ever to implement the parts of the standard Alexandrescu needs.  It is worth reading whether or not you are interested in C++, just like Structure and Interpretation of Computer Programs is worth reading whether or not you're interested in Lisp, or Object-Oriented Software Construction is worth reading whether or not you're interested in Eiffel.  For the most part, it's not about libraries or C++; it's about the issues of writing programs at the level of design rather than implementation.  (There are some bits about how to abuse the C++ compiler to achieve design-level goals, but these are relatively few and far between.)  It is a manifesto as much as a cookbook, and it's certainly made me think about the expressiveness of code in a whole new way.


8:18:44 PM    

Verity Stob develops a Beaufort scale of cruft: "Cruft Force 3. Lived-in. Description: One time in seven when the user starts Word or other Office 2000 app, instead of running, it pretends it is installing itself for the first time and starts a setup program. Directory count in C: up to 17, and something has pooed a Paradox lock control file there, too."  When I sent this round the office, you could hear the muttering as people fired up Explorer and started counting... and yes, she was right about the Paradox files, too.


3:48:57 PM    


Click here to visit the Radio UserLand website. © Copyright 2003 Ivan Towlson.
Last update: 11/8/03; 20:05:04.
September 2002
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30          
Jul   Oct