Older blog entries for chromatic (starting at number 210)

No Compiler, Please:

I was thinking a bit about Parrot NCI this afternoon. I usually describe it by talking about C's calling conventions and Parrot's calling conventions and then explaining that you can generate the thunking layer beforehand as you know C's calling conventions won't change. That is, a C function that takes two shorts and returns a long looks the same to the thunking layer no matter what library it's from. You can compile it once and let it do its magic for any library function whose conventions it understands.

Then I realized that I had never previously realized that Perl 5 also has calling conventions. Sure, they're a lot less strict than Parrot, but any function that passes three scalars and returns one does the same stuff to the stack.

I bet porting something like NCI to Perl 5 wouldn't be very hard. Certainly it'd be nice to replace the simpler bits of XS with something that doesn't require end users to have a compiler. Complexity does increase rapidly, but there's enough regularity that you can go quite a ways.

Just Do Something:

I've been experimenting lately with task lists, both at work and away. Since I have dozens of little things to keep track of in the next three months (roll on October!), only luck would have kept me on top of things.

Of course, being prone to yak shaving, I wrote a program to keep track of these tasks. Go on and laugh, I'll wait. Ready? It works phenomenally well.

I've mentioned how much I like Maypole. I've also always admired the way Ingy makes the installation and configuration experience easy, as exemplified by Kwiki. I've tried to do the same thing with the new installer for Everything, though that's a work in progress.

Anyhow, since I run Maypole through Jellybean to power my task manager, I've been doing a bit of work on Jellybean lately. In the spirit of my new goal to Just Do SOMETHING, I wrote Jellybean::App to simplify configuring and running a Jellybean application. It still requires you to know a little bit about how Jellybean works, but once you understand that there are servers that listen for incoming requests and named containers that respond to requests, you should find this much easier than writing a little driver script.

For example, the Jellybean::App-enabled launcher for my task manager has around four lines of code and around ten or so lines of configuration data. That beats some twenty-plus lines of code. It also gives much better diagnostics when you do things incorrectly; that by itself is a major improvement.

Sure, it's syntactic sugar, but it's quite a bit easier to explain and it took me under two hours.

The Hacks of July:

This is the last day of a three-day weekend. It's always nice when a federal holiday falls on a weekend, as enlightened employers tend to make the Monday or Friday a holiday to make up for things. In one sense, I really should be finishing the book before OSCON, but in another sense I'll be a better editor having taken several days off to rest and recuperate.

Instead of working on the book, I did some hacking. The more I use Maypole, the more I like it. Part of the benefit is familiarity. It's fairly easy to do simple things, but difficult things aren't that difficult when you understand how things work.

For example, I'm having great success with my article manager database. It's even more practical now that I added an alternate view template that fills in a contract for the author. Filling in the fields manually isn't time-consuming, but it surely is tedious. Now it's just a click away.

Of course, I don't particularly want to run a web server loaded with little db-backed applications all of the time; I'd rather launch a program when I need it, fiddle around a little bit, and close it when I'm done. That's doubly-true when I'm on the go with my laptop.

That was originally the theory behind Jellybean, anyhow. I'm easily distracted though and had several other projects demand my attention. Still, the basic idea is solid and the program works.

For kicks, I wrote Jellybean::Container::Maypole to run Maypole apps under Jellybean. Maypole's installer doesn't quite like this, as it still assumes you're using Apache and mod_perl. It works, though, so I can run article_manager to launch a dedicated web server and a new tab in my browser and go about my business. Add in SQLite to make something really powerful.

Happiness Is...:

Happiness is ... free wireless in your hotel room.

Of course, if your laptop has a metal case and the wireless is in the lobby and, while your room is the one closest to the lobby, it's not really that close to the lobby and you have to have your laptop slightly sideways on the desk and keep adjusting its orientation to make it work stably, it's more Advanced Happiness Substitute than anything else. Oh yeah, and the "having to be in a hotel room instead of my nice comfy house" isn't exactly happiness either. Still, free wireless and the kind of quiet that lets me code for a couple of hours uninterrupted isn't so bad.

On the other hand, I keep running into limitations in both my knowledge and the capabilities of the software I'm using. That is a sign I'm on the right track.

This Parrot Plays Games:

Having promised to talk about Parrot SDL last night, I did indeed talk about Parrot SDL last night. It was a rambling talk through the whys and hows of Parrot, SDL, NCI, and, finally, Parrot SDL. As usual, you can look at my Introducing Parrot SDL slides online.

When you're finished with that, gaze in awe at my Parrot SDL homepage, download a snapshot, and try this out on your own.

(As you might expect, a recent checkin accidentally broke my style of method calling. I tried to debug it yesterday, but couldn't track it down to any one thing in time for my talk. It is a little tricky to demonstrate any graphical examples when method calling's broken. Fortunately, I figured out exactly what was failing this morning and the patchmonster fixed it nearly immediately. That guy scares me in a good way.)

If games aren't your style, Dan's Building a Parrot Compiler article went up today. Hmm, you'd think someone planned it that way.

Parrot SDL Objecty Goodness:

As seen in today's earlier Introducing Parrot SDL weblog (yes, that's my work weblog with a four-year old candid photo), I'm porting the existing Parrot SDL code to use real objects. Parrot barely had object support when I started this again several weeks ago. It's much nicer now.

After ninety minutes of hacking, including writing a small patch to improve subclassing exception messages, I can now load and display images and handle multiple surfaces simultaneously. Animation support is very near.

It's surprising that not only is PIR growing more and more familiar, but that it has workable idioms. Very few people have done or are doing anything large with the language, so I'm blazing a trail. How cool is that?

It's also surprising how nice the actual working code is. The bulk of the code in my example actually sets up parameters. Even considering that, aside from some function and method call sugar, you can only have one operation per line, this is surprisingly compact.

I still plan to port the two existing examples to the new code before checking anything in, but here's a followup to the blue rectangle example. This version displays the now-familiar Parrot logo.

.pcc_sub _main non_prototyped, @MAIN
	load_bytecode "library/SDL/App.imc"
	load_bytecode "library/SDL/Rect.imc"
	load_bytecode "library/SDL/Image.imc"

.sym pmc app .sym int app_type

find_type app_type, 'SDL::App' new app, app_type

.sym pmc args new args, .PerlHash set args['height'], 480 set args['width'], 640 set args['bpp'], 0 set args['flags'], 1

app.'_new'( args )

.sym int rect_type .sym pmc dest_rect .sym pmc source_rect

find_type rect_type, 'SDL::Rect' new dest_rect, rect_type new source_rect, rect_type

new args, .PerlHash set args['height'], 100 set args['width'], 100 set args['x'], 270 set args['y'], 190

dest_rect.'_new'( args )

set args['height'], 56 set args['width'], 100 set args['x'], 0 set args['y'], 0

source_rect.'_new'( args )

.sym pmc image .sym int image_type

find_type image_type, 'SDL::Image' new image, image_type

image.'_new'( 'examples/sdl/parrot_small.png' )

app.'blit'( image, source_rect, dest_rect ) app.'update_rect'( dest_rect )

sleep 2

app.'quit'() end .end

Death of a Thousand Little Bugs:

Well, perhaps death of three little bugs anyhow.

Today, after work (and don't talk to me about reviewing copyedits; it was hard to imagine anything more tedious than cleaning up a manuscript before submitting it to production, yet it exists!) I wrote up a patch to fix a header-including problem in SDL Perl. I have yet to hear if that works.

For my next trick, I went through the huge multi-thousand line patch of changes from the SDL Perl repository to the latest release, applied the smaller and less risky changes, and divided the rest into individual chunks. All tests still pass here.

With that work out of the way (hey, applying patches is fairly easy, it was breaking that huge diff into manageable chunks that was such a psychic barrier), I next bundled up Test::MockObject::Extends with Test::MockObject and uploaded a new version of the latter to the CPAN. T::MO::E will make your life easier or double your money back.

Finally, instead of sneaking around behind the backs of my absent buddies and playing Crystal Chronicles solo (and it's better in teams), I fixed a known bug in Mail::SimpleList that caused bounce messages and errors. On top of that, I improved the unsubscribe message slightly. Hey, since this software helps finish the new Perl 6 and Parrot Essentials book, it's important. Please upgrade, if you're running this code. (If you're not, you probably should be. At least, you could be.)

This weekend's trick will have to involve some Parrot SDL hacking, or else next month's PDX.pm meeting will be quite dull. Fortunately, my rather unplanned month-long hiatus meant that the fabulous Jens Rieks found all of the nasty bugs and corner cases in objects, libraries, and NCI, so they're mostly fixed and possibly even documented.

That, and writing a couple of Linux Desktop Hacks. Any GNOME writers in the audience care to join in?

Multipart Mail Hacks:

At the risk of finding a brown paper bag bug, I've released the latest version of my mailhacks modules. See my Perl projects page or wait for the Mail::Action 0.30, Mail::SimpleList 0.87, and Mail::TempAddress 0.56 to hit the CPAN.

Tomorrow's project? Test::MockObject::Extends.

(Mini-rant: Mail::Box is huge to pull in just for message handling, but it appears to work. It'd surely be nice if it were split into smaller pieces, though. I don't need IMAP, POP3, mbox, or maildir handling to parse a message.)

Mocking Parts of Objects:

The more I use Test::MockObject, the more I discover that I only need to mock small pieces of well-designed objects.

This came to a head today when I made the template() method of Jellybean::Response a little smarter. Instead of making repeated method calls to set individual pieces of template data, you can now pass a hash reference containing multiple pieces of data. That's less code! You can also request the whole template data in one chunk, too, but that's a separate issue.

My tests use a mock object to test that containers set template data correctly in the response object. After I improved template(), I converted one container to the new format. Suddenly, four tests failed. Since I'd mocked a template() method, the test code no longer matched the capabilities of the object it mocked.

Clearly, there was room in the world for Test::MockObject::Extends. So I wrote 52 lines of code (with liberal spacing and brace placement) and 44 lines of tests. More importantly, it required adding one line to the Jellybean test, changing another line, and deleting the not-so-accurate mocked template() implementation. Presto, all tests pass again.

I seem to promise to add documentation and post the code quite a bit lately, so replay the last few messages.

Oh yeah, dissatisfaction with the state of the world is great when it motivates me to improve things that need improving, but I originally set out today to add two small features to my article managing program. Of course, that lead me to make the templating simpler there, which lead to me refactoring and adding one nifty new feature to the Jellybean templating system.... So that's why I rarely finish anything. I'm too productive.

Vacation? Well, Not Really:

Due to a major family emergency, I'm spending the week with my parents. While that means spending time on family business -- and most definitely not on my usual work -- it does leave some other time for hacking and such.

Yesterday, I hooked Class::DBI to SQLite to Jellybean. (Yes, the latter really needs a release soon.) This isn't an academic exercise; I need a better solution to manage authors and articles. Now I have a database hooked up to a personal web server that lets me view, create, and edit author and article status information. It's a small step to write and send contracts automatically. It'll also be nice to have an API to our publishing system at work, but one step at a time.

Today, I ported Mail::Action (parent of Mail::SimpleList and Mail::TempAddress) from Mail::Internet to Mail::Message. This simplified the code slightly. More importantly, it will handle better multipart messages. I need to add a couple of enhancements, especially to signature handling, but now it's possible to send and receive attachments. Very handy. These'll probably hit the CPAN in the next couple of days as I revise the documentation.

Tomorrow or Friday I ought to port SDL Parrot to the new object system. I'm waiting for Leo, Dan, or Melvin to add the nice IMCC shortcuts, though. It's terrible being an early adopter and a trailblazer.

I also have some minor patches to Text::WikiFormat lying around. Oh, and there's SDL Perl stuff to manage, too. Still, progress is progress.

201 older entries...

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!