Polyglot 9: Moo
9 October 2004
Most programming environments are based around interchangeable modules. Apache or Zeus, Perl or Python, MySQL or PostgreSQL. Pick the ones you want, glue them together and your environment is ready to program. If one module can't cut it, replace it with another one. It's a good strategy with many obvious benefits.
The Moo takes the opposite approach. Everything is in the one monolithic database. The absolute joy of programming in a Moo as opposed to Apache/Perl/PostgreSQL is that when an error happens you get an entire traceback from the moment of the error all the way back to the starting command. Having everything in-Moo makes development, debugging and maintenance uniquely simple and straightforwards.
Which strategy is better? That's the stuff of holy wars. The truth is that in their pure forms both are good. But the monolithic approach only works in its pure form. Once you start bolting external dependencies onto the Moo the environment degrades to just another glue language (and not a very good one at that).
So when it comes to drawing an image (not something that's in the Moo's natural repertoire), one should try to avoid taking the modular approach of gluing some form of GD interface onto the environment. The Moo ought to create the image itself. There are two file formats which are suitable, SVG and BMP. This implementation used BMP. The verb that renders the bitmap automatically switches between paletted 8-bit colours and 24-bit true-colours as required. The only problem I encountered was that the spec I was using forgot to mention that BMPs are little-endian[?]. I only realised this when in desperation I started decoding a real BMP in a hex editor.
Update: Chris Allen pointed out that the generated BMP didn't render in MSIE. It turns out that the above menioned spec stated that a zero needed to be used where in fact a one was required. I've fixed the Moo's BMP renderer and informed the spec's author of the error. I've also found and corrected an unrelated off-by-one error that caused traceback in rare cases.