Wednesday, 22 October 2008

Book review: Extended STL

Details
Title: Extended STL Volume 1
Author: Matthew Wilson
Publisher: Addison-Wesley 2007
Pages: 572
ISBN: 978-0-321-30550-3
Links amazon | publisher
The prologue

This is an unusual book review for me. Normally, I digest a technical book in a matter of a week or two and then write a review. I don't like writing a review without having fully read the entire contents of a book; it's not a fair and representative review. Consequently this review is remarkably delayed as Extended STL has taken me literally months to read.

Why is this? The information in this book is dense and not easily digested. There's a lot of complex stuff in here that - especially in order to review fully - you really have to pay attention to. I'm not sure I can entirely blame this on the book, though. It's a natural consequence of the subject material.

What's it about?

Extended C++ is the first volume in Wilson's projected two part series. This tome covers collections and iterators. That is, it describes how to create STL-compliant containers and iterators from scratch or how to wrap existing pieces of code with STL-interfacable proxies. This is a non-trivial area, with many subtle problems. The meat of the book is an in-depth description of problems and solutions in the implementation of STL-like code.

Volume 2 of the series will cover (amongst other things) STL-like functions, algorithms, adaptors and allocators. No doubt that, too, will be a dense book covering complex subject matter.

Extended C++ is a fairly unusual book in the current marketplace, and so has little competition. There are many books on learning or using C++, on good C++ style, and on C++ programming idioms. There are many books describing particular C++ libraries. But there are few specifically about writing STL-like extensions, and interfacing existing code with the STL. So there's little competition for Extended C++. If you are doing this kind of stuff then the book looks like a sound investment.

So is it any good?

This book is not an easy read. It took me an incredibly long time to complete; it's not easy to read in small chunks, or when you brain is full of other stuff. You really have to study a chapter in depth from start to finish to follow the flow.

Extended C++ opens with a set of chapters on foundational concepts and terminology. These are a refresher in some important C++ STL-related techniques, and I suspect that the majority readers will take away the most useful stuff from these chapters alone!

The chapters in the subsequent two parts (collections first, then iterators) usually cover a single example of the implementation of a STL-like component: explaining the reason for writing the component, the problems discovered during implementation, and the ultimate solution. An included CD contains all the numerous code examples in the book.

Sometimes this example-driven approach makes it hard to determine the most important information presented in chapter. It also makes Extended C++ less than ideal as a reference-work to look techniques up in.

The book contains a scattering of "tips" in callout boxes. These appear to be a rather inconsistently applied narrative conceit. They should either have been scrapped or rationalised significantly.

As you read the text, it's clear that you are getting information from someone who really knows what he's talking about, and who has done a lot of this kind of legwork many times over. Wilson's writing style is clear although sometimes I wonder whether the information could have been presented better in a different structure.

Extended C++ is a testament to the incredible power and to the incredible complexity of the language. Many of C++'s detractors could cite it as a counter-example for use of the language!

I found very few technical problems or mistakes in the text. If I was being picky, I'd criticise the author's propensity for somewhat flowery language which will leave non-native (and some native) English speakers confused (or reaching for the dictionary).

Summary

Pros
  • Fairly unique coverage of this aspect of C++ coding
  • Clear writing style
  • The voice of an expert
Cons
  • Dense information, often hard to digest
  • Not ideal as a reference work
Recommended if you are writing STL-like C++ code, or want to interface legacy code with STL-style C++. Make sure you have plenty of time to sit down and digest the material, though.

Friday, 17 October 2008

The madness of glibc

Great. Something else for me to have a techie moan about. It's not as if I have any actual work to do, is it?

We build devices that run Linux. We make our Linux environment from scratch, so we have an in-house routine of building binutils, gcc, glibc, busybox, and so on. It's standard stuff for those used to the joys of getting Linux built from scatch.

Summary: it's embarrassingly hard to build Linux from scratch. Everything needs a bit of gentle bodging to work. If you change one component of the Linux build chain, it's odds-on that you'll have to tinker with many others.

That's just life. Programming was never supposed to be easy, was it? But you don't want people to make the job any harder than it has to be.

So helpfully, in these enlightened times, the glibc release dudes now no longer supply tarballs of their source releases. And they don't really tell you that they don't either.

Sigh.

Here are the details...

Everything old is new again

The glibc homepage is here: http://www.gnu.org/software/libc
  • The "Current status" section says that the latest version is 2.8
  • The "Availability" section says that releases are available from the GNU FTP site (http://ftp.gnu.org/gnu/glibc/)
  • The latest version available there is 2.7
  • There are no other hints or bits of documentation about this
I have a habit of just hitting the FTP site, and pulling down the latest revision posted there. So it took a long time and a lot of manual fixing of the (old) 2.7 release before I realised that I was working with an archaic version.

So what's any geek to do? I hit Google. And here's what I discovered:

Finding the truth

http://sourceware.org/ml/libc-alpha/2008-05/msg00074.html shows a mailing list post from the glibc maintainer which states that:
Tarballs are a completely outdated concept.
And he refused to package glibc releases any more. Go get it from CVS yourself. Crumbs!

Helpfully, he's not only not packaging releases, he's also not telling people how to get them easily. And he's not making it clear that the FTP site is now NOT the source of the latest releases.

There is some well reasoned comment to this (including http://sourceware.org/ml/libc-alpha/2008-05/msg00076.html) highlighting the advantages of packaged source releases. Still, that's not my choice, and I can't help it.

So how do you get it?

The glibc resources page (http://www.gnu.org/software/libc/resources.html) describes the location of the project's CVS repository, and how to get sources from it via annonymous pserver access. However, there's no mention of the release tag you need to get a release.

So it's up to you, luck, and the raw power of CVS. This was a culture shock for me; it's been years since I last used CVS! And my finger memory won't even allow me to type cvs. Every time I tried typing it, it came out 'svn')

Helpfully you can't even "cvs ls" the repository as the server does not support "ls". Good start.

A bit of digging in the glibc CVSweb interface helped me to discover the tag was called glibc-2_8 and that the two modules I needed to check out were called "libc" and "ports"

Since our build system requires the traditional glibc and glibs-ports
tarballs as input to the build process, I needed to recreate some tarballs, even if they are not official release sets.

The script below is how to do this, for those in a similar predicament.

Later I found http://sourceware.org/glibc/ which is another (unofficial) glibc homepage that has slightly more info on it. However, it still doesn't tell you the release tag for the latest source release. Sigh.

Whinge, whinge, whinge

So what? I can hardly complain can I? I can't demand a refund for this shocking lack of unpaid support for the free software I'm using without cost? So I'll just have to have a bloggy moan about it instead.

RELEASE_TAG=glibc-2_8
VERSION=2.8

cvs -z 9 -d :pserver:anoncvs@sources.redhat.com:/cvs/glibc login
cvs -z 9 -d :pserver:anoncvs@sources.redhat.com:/cvs/glibc export -r $RELEASE_TAG libc
cvs -z 9 -d :pserver:anoncvs@sources.redhat.com:/cvs/glibc export -r $RELEASE_TAG ports
mv ports/ glibc-ports-$VERSION
mv libc/ glibc-$VERSION
tar cfj glibc-ports-$VERSION.tar.bz2 glibc-ports-$VERSION
tar cfj glibc-$VERSION.tar.bz2 glibc-$VERSION

Thursday, 16 October 2008

Overload 87

The excellent Overload magazine's issue 87 is out now, available from ACCU.

Enjoy the cover artwork - another of my productions.

Friday, 10 October 2008

Book review: Beginning Xcode


Details
Book: Beginning Xcode
Author: James Bucanek
Publisher: Wrox 2006
ISBN: 978-0-471-75479-4
Pages: 590
Links: Amazon | Publisher
This book is way old now. It covers Xcode version 2.2, which is so far behind the cutting edge it's practically blunt. It's two years old, which is about 100 years in the tech book world. So why am I bothering to post a review of such a book? Simply, because I found it useful, and it's worth doing it justice here.

Previously, I reviewed Xcode Unleashed (published by SAMS) and found it good but not perfect. I obtained this book at the same time, and it turned out to be a great compliment. Whereas Xcode Unleashed was a rapid trip through Xcode, this book walks at a more lesuirely and detailed pace. It filled in holes in my understanding left from Xcode Unleashed.

Sometimes, it was a little too lesuirely (I didn't really need 55 pages on the basic operation of the code editor, for example). But you can't fault the detail.

The author writes clearly, and the layout is not fussy, contributing well to the book. Bucanek describes the basic operation of Xcode, its projects and group/target principles, describes editing and managing items within Xcode, and the processes you'd expect: developing code, interfaces, building, debugging, profiling, and unit testing.

Although Xcode has matured considerably since version 2.2, very little of the information in this tome is stale or factually incorrect. Some of the newer profiling and analysis tools will inevitably not be covered, but all the basics are there. I wonder whether the author is working on a revision for 2009?

Summary

Pros:
  • Comprehensive and detailed
  • Clear writing
Cons:
  • Old; it covers a rather old version of Xcode
A good, thorough, if old, book on Xcode developement. Suitable for complete novices to Apple development.

Recommended if you don't pay too much for it.

Monday, 6 October 2008

Breathe 2008 (the aftermath)

Phew! What a weekend...

From Friday through to Sunday I was playing keyboards at C3's awesome Breathe conference, at the Corn Exchange in Cambridge. It's a great venue to play, and it's nice to play on a much larger stage than usual. The band were excellent, and it was great fun to spend the entire weekend playing together, although very hard work.

During the event I had a very weird experience: In December last year, I had my bike stolen from outside my house. On Saturday I strolled into an enclosed service area out the back of the Corn Exchange, and what do you think I found? My stolen bike. A little worse for wear, but happily leaning against a wall.

Wednesday, 17 September 2008

Book review: Xcode 3 Unleashed

Details
Book: Xcode 3 Unleashed
Author: Fritz Anderson
Publisher: SAMS 2008
ISBN: 978-0321552631
Pages: 534
Links: Amazon | Safari | Publisher
This is a fairly well-paced introduction to the world of Xcode 3. It's suitably up-to-date (relevant for Leopard development using Xcode 3.0 , it works fine with Xcode 3.1; very little has changed). This means that it will probably have dated within a year, though.

It's well a produced book, printed in full colour with a large number of screenshots and an accessible writing style. The layout has been carefully prepared, with clear and useful warning and tip callouts. This makes it easy to follow.

Anderson begins with a whirlwind tour of the development of an application in Xcode. It is an interesting tutorial. However, it only serves to give you an idea of the available features without really explaining how to use them. You get a cursory look at: developing in C, using the debugger, making libraries, using Cocoa (a frankly too-fast romp through Objective C coding and making apps for the mac, this is too much for the book really - it's such a big and complex topic), using version control (Subversion in this case), plists, bundles, unit tests, documentation and more.

Phew! After that's over you have an idea what's going on, but no great understanding of how to put it into practice in your own Xcode projects.

The second part is a far-too-brief "detailed" description of the IDE. This covers just simple project navigation, the build system (for make veterans), debugging, and some of Apple's cool profiling instrumentation mojo. I'd've hoped that this second part would be about twice the size of the tutorial section. However, it's about half the size.

This book is a good introduction to using Xcode, but ultimately leaves you with as many questions as the answers it provides.

Summary

Pros:
  • Full colour, many screenshots
  • Good writing style
  • Good broad overview of development with Xcode
Cons:
  • Not in-depth on any topic
  • Fairly unless index
I'd recommend this as a fast-paced introductory text for an experienced programmer who knows nothing about Xcode. But it will only whet your appetite. You'll probably need another more in-depth tutorial afterwards to really get under the hood of Xcode.

Recommended with reservations

First steps with Xcode

This past week, I've been taking my first (faltering) steps with Xcode, Apple's development environment (IDE) for producing programs that run on Mac OS. It's been a bit of a mixed experience.

As with any piece of Apple software, the installation is a smooth experience and the program itself, when you fire it up, looks cute, lickable and friendly. So what could possibly go wrong?

Now, I have to admit that I have a first class aversion to IDEs. I use them as rarely as I can possibly manage - I'm a command-line controlling, Vim-loving power user. I've been building software for the Mac for some time, just using those tools and have been perfectly happy. Mac OS is just another UNIX, and everything tends to behave the way I'm used to. It just has perdy windows on the top. Kinda like KDE, but better.

Unfortunately, I don't want to build a simple "Hello, World!" program, and I don't want to learn Apple's freaky Objective-C right now. I need to get real work done, very quickly. I need to get our reasonably large codebase (320k lines of C++, or which 85k are test code, 1797 source files, of which 466 are those tests) which compiles under Linux (cross-targetting embedded ARM products, and local x86 machines) building and running on Mac OS as quickly as possible.

I could do this on the command line with my existing Makefile scaffolding, but I need all the good cross-OS-version/univeral binary magic that Xcode provides for you, and I need to share the project with people who have an aversion to the command line (they're a shifty bunch).

Enter Xcode stage left. Enter a period of stress and frustration for Pete.

So here's a synposis of my experience with Xcode so far:
  • Like any IDE, it's a large and unweidly beast. If you don't know your way around it at first, it's intimidating. I'll admit, though, that it's not as intimidating or just plain wierd (IMVHO) as either Eclipse or Visual Studio when you fire them up for the first time.
  • Like any online help, the bundled documentation is not very useful. Sure, its great that it's there. Sure, it probably describes every aspect of the program. But it's on the computer, it's hard to read, and it takes a while to work out your way around it. I gave up and bought some books from Amazon (more on these another time). Much more useful.
  • I don't like not being in control any more! You are rather more divorced from your file structure and SCM. If you don't work Xcode's way, then you'll be continually swimming upstream. Unfortunately, we have a large existing codebase that we need Xcode to work with, and this is goig to become frustrating.
  • This is the main observation: I imagine Xcode is great for a project that you start off from scratch. However, trying to get it happy with an existing project is a bit of a pain (perhaps less of a pain if you already know how to drive Xcode!)
  • Importing a large project into Xcode isn't too bad. But you have to understand the difference between source groups and folder references, or you'll struggle trying to work out why thinks don't work as you expect. Hint: use source groups.
  • Xcode doesn't really grok C++. Well, it doesnt understand reasonably complex modern C++. The Code Sense thingy just goes horribly wrong. It totally fails to understand anything inside a namespace (that's hardly rare these days!) and can't cope with nested classes, either. We have many, many classes using the Pimpl idiom, with internal classes called Impl. Code Sense throws it's hands up and shows you 367 top-level classes called Impl. Helpful. To add insult to injury, if you try to drill through any of these different Impl class you're always shown the same members for one of the 367 Impl's. It's very, very borked. In the end I had to switch of Code Sense and carry on as if I was still living in the dark ages.
  • Working with third party libraries seems tricky. External source trees appear to be the best way to do this. It's not obvious how to put them on the header include path - with a ittle experimentation I worked out you can list "$(external_tree_name)" in the pointy-clicky-typey-thing and it worked. If that's documented anywhere obvious, I'll be darned if I could find it.
  • The compiler is gcc (which is the compiler we use for our Linux builds) so there shouldn't be an porting issues, should there? Well, thankfully not too many apart from some small issues caused by different sized types.
  • However, it took a long time to get the compilation working. I was getting millions of bizarre errors through impossible header-file include chains. It made no sense at all. The errors seemingly came from inside standard headers (things like 'error: 'strcmp' os mpt a member of 'std' in c++locate.h:64' - last time I checked it was!). This turns out to be a problem with something called a header map, that seems to interact badly with HFS's weird slightly case sensitive/slightly case insensitive filesystem. You have to switch it off. Except there's no Xcode option to do that, and you have to waste time on Google to find the trick is adding a random secret user setting called USE_HEADERMAP and set it to false. This magically fixes the problem. And there was me thinking that IDEs are supposed to make your life easy.
  • The editor. It's OK. It's Mac OS-y. It's got syntax colouring and Code Sense (for what it's worth - for me very little) built in. But it's just not Vim.
  • The Xcode SCM integration (it supports Subversion out of the box) is almost adequate, and certainly a little underwhelming.
Goodness, I've rambled for a long time. You probably skipped most of that. But I found it cathartic. It's interesting to see how development experiences draw such deep emotions from programmers - but it's natural. We spend all day in front of these things, so it's important to be able to get it to work for you, not against you.

So am I converted to Xcode? Hardly. Am I warming to it? Gently. Does my application compile yet? No, but I'm working on it.