?

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

( Read 5 comments — Leave a comment )
publius_ovidius
Dec. 4th, 2005 06:46 am (UTC)
Out of curiosity, what part of that do you hate? The fact that you have to use an interface or the fact that you have set up a class just for this button to listen on?
brentdax
Dec. 4th, 2005 06:51 am (UTC)
The second. It's just such a lousy hack to get around the lack of closures, delegates, or other first-class-function features.
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.

sangochan
Dec. 4th, 2005 03:38 pm (UTC)
Don't you just LOVE Java?
codepoetica
Dec. 4th, 2005 03:38 pm (UTC)
System.exit(0);

Is just about the best call one could make in an event handler. Maybe prefixed by a

Runtime.getRuntime().exec("/usr/local/bin/firefox");

as every other UI I've written in the last few years has been implemented in xhtml/css.
( Read 5 comments — Leave a comment )