17 May, 2003

Coding frustrations with Petunia

I've been trying to work on my pet today and this coming week since my free time is about to be gobbled up by my new job. But I'm running into the same problem I was last time I almost gave up with the project. Here's a rundown. 
The program receives stimulus from any number of inputs. The dispatcher breaks this down into three simple variables:

my ($thischan, $thisuser, $thismsg) = (@_);
 
This way, no matter what our output method is (or where our data came from), or even what language our code is written in, we have a very smooth API for how to process data. At present we have about 55 modules responding in this API. However, some of them take a long time. Herein lies the crux of the problem. IRC wants you to respond to pings every N interval (I think its 60 seconds). Some of these modules are: 
select_map.pm: allows free-form database queries
slashdot.pm: grabs slashdot headlines, greps for older stories on request.
shorten.pm: uses's metamark's url shortening service
translation.pm: attempts to translate text via babelfish
market.pm: all kinds of stock market quotes and the ability to track a portfolio
Sometimes yahoo's quote service times out. Sometimes metamark is down. Sometimes, I want to run a query like:
select count(quip) from log
    where substr( date_trunc( 'day', stamp ), 1, 10 ) = substr( date_trunc( 'day', now() ), 1, 10 )
    and channel = lower( ? )
which might take more than a minute to run. So here is how I'm doing it presently:
foreach my $module (@modules) {
  $module -> run( @args );
}
Each module has a set of "trigger" subroutines. It runs through them to see if it has seen anything it wants to reply to, and then replies if it does. If not, it doesn't, and it really doesn't take much time to make that choice. However, Imagine this interaction: 
 
:last AAPL
Hello, petunia!

Normally, I'd like petunia to run off and grab the quote for Apple, and then say hello. But in this case, she actually has to form the LWP agent, make the request of yahoo's servers, scrape it, and reply. What if yahoo is down? Then the bot never comes back from "last", and the server disconnects her. So what we're looking for is this:

eval 'undef &utility::spew';
eval '*utility::spew = \&async_spew';

 foreach my $module (@modules) {
  $module -> run( @args );
}

sub async_spew {
  # shovel data to the kernel
  my $filter = POE::Filter::Reference->new();
  my %result = (  spew => [@_] );
  my $output = $filter->put( [ \%result ] );
}
 
where spew() was her original output handler, and async_spew() now runs in its own little POE container. I'm having problems, though with POE forking them off, and no longer having access to critical variables. Like the global %config hash, and the $dbh that I had originally passed them. I'm almost getting to the point where a rewrite is necessary, and I really hate to do that.


&c: wha? he can code? I thought all he did was whine about not having a job!

16 May, 2003

PHP is SHIT

mrcsparker: PHP gets "so much shit" because it is a royal pain in the ass. I don't suppose you've ever tried to build php on ultrasparc, 64-bit, on Solaris. As it turns out, you need to build from a snapshot since the stable tarball has bugs in it. Once you get it actually compiled, the 'make test' fails miserably. Basically the problem with the project is it is highly x86-centric and highly windows-centric. When I look at a project like ADODB, I get those godawful every-line-ends-with-^M files, and there are explicit paths that include things like C:\BLAH\ ...

I don't personally have much against the language. I think it can be used properly, and I think it has some technical merits. It does however suffer from the same problem perl does. I'm sure many perl programmers will attest to having been grouped with "duhvelopers." People tend to hate perl because the code that comes out of many perl programmers is awful (see below for more). This isn't a reflection of the language, but rather of its community. PHP has a lot of users out there without any understanding of community responsibility and responsible coding.


arhuman once mentioned on perlmonks (where I am known as deprecated), the book Musashi. While some may disagree with the notion of programmers-as-samurai (there is an extensive thread on perlmonks about this, which I decline to link to), the principle of honorable, learned people who believed in their craft would benefit most programmers immensely.


But I digress.


Job: I now work for British Aerospace. Let me tell you, the last two weeks have been hell. I mean, I've been on so many interviews, every single pair of slacks I own now needs to be dry cleaned. I interviewed with a pile of companies, and it eventually came down to two offers. I wasn't thrilled about either of them. I had finally chosen one when the BAE position came along and just blew everyone out of the water. More pay, 3 minute indoor walking commute (I live in the same building I work in now), and no benefits. (thank you, but I'll invest for my own retirement and get my own credit union and buy my own health insurance thankyouverymuch)

So I'll be hacking perl. My first task involves mostly auditing and fixing 270 perl scripts that need to be running with -T but aren't. Wee. Apparently the software in question is almost a decade old, and needs to be run by the DISA Web Applications STIG (sorry, it is unclassified, but it looks like DISA isn't very friendly). Basically this means they need to be secured to obtain an "Authority to Operate" ("ATO") on the SIPRnet. The STIG (Security Technical Implementation Guidance) is essentially a step-by-step process to secure a

Sounds like a daunting challenge, and something that will keep my very busy, which is the way I like it. I'll also be making enough money to pay off the debt I accrued (it has been six months since I received a paycheck), and rebuild my savings. I'm also thinking about picking up a Honda S2000 (silver, red leather). [ed: not a fucking chance. i'm way too tall]

What a long, strange trip it's been.

job

Got a job. Hacking perl. Doing government stuff. More soon. Yay money.