« October 1997 | Main | February 1998 »
December 01, 1997
Overload 23 Editorial
Once upon a time I held sway over a set of interacting multi-threaded objects marshaled with the power of object oriented design methods. Now I find myself faced with a large body of aging C code, written by mean fisted unix wizards. You know that tight scrawl they have: 40 columns wide, 80 columns deep. I've got that sleepless 'rewrite' feeling. But, change it, and break it. Not wise on a schedule that runs in internet time (one year = three months).
Why C?
This code builds and ships on 17 platforms. C is portable. C++ is not. But, the big news of this issue is that it will be next March! (See Francis' column in the Standard section.)
The C++ Standard has taken so long to arrive that many projects have switched to Java to provide the 'write once, run anywhere' holy grail.
Bad C
So, we're stuck with C for the moment. But, it's not the language that makes code bad. You can write really good C. So what's unpleasant about this code:
· Big functions
· Many exit points
· Backward and forward goto's. Both to repeat algorithms, and to
clean up resources.
· Unused functions, declarations, and includes.
· No function naming conventions.
· Features thinly spread over the source instead of tightly corralled in their own modules.
· Functions with many side-effects, instead of one operation.
· Transfer of object ownership between caller and callee.
· No hope for reuse.
Good C
So how can this general badness be migrated to something more palatable?
· Enforce partitioning. Low coupling, high cohe-sion.
· Define module interfaces.
· Provide explicit structure constructors and decon-structors.
· Provide object scoping with this pointers
· Naming convention of <object>_<operation>
Look at Safer C and Lakos for help
How can you build new features, in a timely manor, on top of old code? I think you've got to spend time re-organising and rewriting.
Movies
It's odd to work in a company where people can make it their lifestyle. They feed you, clothe you, and entertain you. Free food, drink, t-shirts, jackets, and film tickets. They'll book your holiday, arrange an evening out, send a birthday gift, or wait at home for the plumber. There's even a dentist on wheels. Weird!
Anyway, the point is that I've been to see some films recently, and I know you won't have got them yet, so I get to do some film reviews.
Starship Troopers was really bad. Teenage romance script with lots of limbs being ripped off. Unfortunately not so bad that it enters the 'so bad it's funny' category.
Alien Resurrection was ok'ish. Not as bad as Alien 3, but not as good as 1 or 2. A few neat twists on the theme but they've run out of ideas, and the ending was soppy.
Gattaca. Fantastic. Set in a near future around the theme of human genetic manipulation. Engrossing complex story with great cinematic atmosphere.
Sign off
Appropriate seasonal salutations to you all, and remember… every child is expecting an LDAP server under the tree this Christmas!
John Merrells
December 1997
Posted by John at 12:00 PM