Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

gav (2710)

  (email not shown publicly)
AOL IM: flufflegavin (Add Buddy, Send Message)

Hacker in NYC.

Journal of gav (2710)

Tuesday October 29, 2002
07:26 PM


[ #8670 ]
My housemate is finally moving out. This has been a painful and expensive learning process for me and I can sum it up into a simple rule: "only live with people you've married and/or sleeping with".

The worst thing is that I have to lend her $1100 so she can move into her new place and hope that she'll get her loan in 2 weeks time. She has cost me more or less $5000 (in lost rent, bills, loans, etc) over the last 11 months. Anyway, I am so glad to be seeing the back of her. I am looking forward to living by myself, having peace and quiet, being able to watch what TV I want and only having myself to blame for every plate, bowl, pan, and item of cutlery being dirty.

Today was the 2nd of my "code and pizza" lunches at work. The basic idea is that the programming team (3 of us) sits down and talk shop in an effort to all do better. I'm trying to structure it into 2 parts, a look over everyone's solutions to MJD's quiz of the week, and a small code review (several pages or so).

Unfortunately things aren't going so well. It's turned into a bit of an "I've been doing this all along and it's working" battle. I thought I'd start at easy things that I thought he could do better, not doing a 'use English', not calling his CGI object $cgiobj and calling subroutines with a '&' prefix. This didn't go too well.

I then tried to look at more general things, improving his use of DBI, better use of hashes, less repeated code, and tidying up some scary if-then-else statements. I think this went better thought I'll have to wait and see his next script. I then thought that I'd try to suggest using things like map and grep as I never see them used in is code. Then our senior engineer and him started to point out that it made code too complicated and basically unmaintainable. The code I was using was something ripped straight from some production code (at the bottom of this entry).

I'm feeling a bit disheartened about my progress, but it is only week 2. I do have the advantage of having a captive audience; they get free pizza for having to listen to me :)

if ($sort eq 'category') {

    $page{categories} = [
        sort {
            $sections->{$a->{key}}[SORT] <=> $sections->{$b->{key}}[SORT]
        values %gifts

    $page{sort_by} = 'category';

} else {

    $page{categories} = [{
         name => 'By Price',
        items => [ sort { $a->{price} <=> $b->{price} }
                     map @{$_->{items}}, values %gifts ]

    $page{sort_by} = 'price';


The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • That was an example of bad code, right?

    It's not clear from your journal entry whether that was what you want your co-workers to do, or they are currently doing. I'm hoping that this reflects your idea of bad code, though ;)
    • Nope. It wasn't my idea of the world's greatest code but I do think it's good.

      It's a bit out of context but it's basically turning a HoH into a sorted AoH, or a HoH into a flattened AoH with one element.

      I'd brave enough to welcome critisism :)

      • Hmm, two incompatible data structures for one hash key, use of both real hash keys and constants for array indexes. Not exactly crystal clear. And if you had 10 sort options it could get really ugly.