All the Perl that's Practical to Extract and Report

Navigation

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
Without JavaScript enabled, you might want to
use the classic discussion system instead. If you login, you can remember this preference.

Please Log In to Continue

My first realization that I really wasn't "thinking" Java was when I wanted a dispatch table whose keys were anonymous subs closing over values determined at runtime. I wound up creating a class hierarchy and used polymorphism to handle the dispatching. Instead of having all of my logically connected behavior in one place, I wound up spreading it across multiple classes which were created solely for the purpose of handling this dispatching. Being forced to shoehorn everything into "one-size-fits-all-OO-s

There's actually a semi-decent way to handle some of that. You define an abstract class (or interface) with the method you want to be able to call. Then, you define anonymous inner subclasses of that class:

Wow. Ugly as hell, but yet, much better than what I wrote. Reminds me of how some Java programmers argue that they don't need closures because they have anonymous inner classes. It's true, I suppose, but it's an awful lot of grunt work.

Well, I just completed a class where I actually had to use this technique, and I'll testify that I definitely would've rather had something else. And you're right; it is ugly. In my case I don't think it was closures I was looking for, but I'm not sure what it was.

The good news is I replaced it with something even more amazing.

--J. David works really hard, has a passion for writing good software, and knows many of the world's best Perl programmers