?

Log in

No account? Create an account

Previous Entry | Next Entry

Ugh.

As I was doing my reading for the unit six of my Oxford course, I started getting a sinking feeling. They were showing how GUI programming in Java worked, and as I thought ahead, the only way I could think of for them to handle an event was one I didn't want to contemplate...

And then it happened. My worst nightmare came true.

class StopButtonListener implements ActionListener {
    public void actionPerformed (ActionEvent e) {
        System.exit(0);
    }
}

My. Brain. Hurts.

Comments

publius_ovidius
Dec. 4th, 2005 07:08 am (UTC)

Oh, I know that feeling. Just the other day I was refactoring some code when I saw this getting repeated a few times:

  sub schema_for_class {
    my ( $self, $class ) = @_;
    return grep { $_ }
      $self->table_for_class($class),
      $self->indexes_for_class($class),
      $self->constraints_for_class($class),
      $self->view_for_class($class),
      $self->insert_for_class($class),
      $self->update_for_class($class),
      $self->delete_for_class($class);
  }

That's just ugly, so I reworked it a bit.

  sub schema_for_class {
    my ( $self, $class ) = @_;
    return
      grep { $_ }
        map {
          my $method = "${_}_for_class"; $self->$method($class)
        } qw(
          table
          indexes
          constraints
          view
          insert
          update
          delete
        );
  }

After a bit more work, I realized the method lists were sometimes duplicated so I'll abstract those out, too. I hate working in languages where I can't do basic things like that.

While I think that's much easier and cleaner, I do sometimes worry that if I abstract out too much, others will get confused.