Friday, March 30, 2007

Online resources for understanding Aspect Oriented Programming


I was going to buy a book on Aspect Oriented Programming, but all of the books I can find use AspectJ, and I don't currently use Java for anything. So I went looking for online resources about the principles of AOP and found some good stuff:

  • Gregor Kiczales describes AOP to Google

    This is excellent. It starts a little dry - like every good thinker, he's pedantic in laying down his groundwork. But in the last half hour, after he's described the concepts of AOP, he goes on to describe some of the potential applications and you'll start to see, if you hadn't already, that this is Teh RoX0rz.

  • Gregor Kiczales's 1997 paper on AOP (download PS or PDF on the right)

I went ahead and ordered a book that uses AspectJ, but really I'm interested in applying AOP principles to Ruby programs. [1] [2]

If you've heard of AOP but haven't looked into it yet, don't think that AOP is trying to be a silver bullet supplanting OOP. Kiczales has OOP continuing to be the "primary decomposition" for most software designs. AOP is a "secondary decomposition" providing a way to formalize the parts of the solution that don't naturally decompose into an object model, and then cleanly graft their calls onto the object hierarchy without having to tear the whole thing apart and put it back together. How many of you have worked on an object-oriented design that had a "Utility" class which was a bag of miscellaneous yet essential functions? Yeah, that. AOP brings order, abstraction, and flexibility to the bag o' functions, and also makes it super easy to add new calls wherever they are needed.

To me, the most compelling example is the example of adding logging to an established system. Let's say you inherit a project that has 50 classes and each class has a method called log_message(). But, for whatever reason, log_message() is defined independently in each class. Further, the implementation of log_message() is woefully insufficient in 48 of the 50 classes. Normally, what do you do? You check out all 50 classes and edit their log_message() implementations one by one. Probably, since you're at it, you'll try to factor out the commonalities, but either way, you're editing 50 classes. But with AOP, you can define a new Logger aspect and then define a pointcut pattern that intercepts any call to log_message() from any of the 50 classes and invokes your Logger in place of, or in addition to, log_message() itself.

Another interesting example is the factory example. Say you have 3 or 4 classes with constructors, but these constructors are guarded by a Factory class and should not be called from outside the Factory. (Think singletons.) You could probably do something with protected to enforce this, but that can lead to brittle dependencies in your class hierarchy. With AOP, you can lay pointcuts over all of the constructors, and throw an error if the caller isn't coming from a method of the Factory class.

Thursday, March 15, 2007

New defensive scheme for the Colts


Now that they have a Super Bowl victory, the Colts are free to try some "experimental" game plans.

Like releasing the whole defense and having the offense play both ways.

Reggie Wayne is training at cornerback and Peyton Manning is training at linebacker.

Manning was quoted as saying "I get two paychecks this way."

Harrison plays corner, but since he has better hands than 99% of receivers, he just intercepts any balls thrown to his man. That way he never has to tackle.

Thursday, March 01, 2007

Favorite Simpsons episodes


One of the local TV stations just finished running a Top 50 countdown of the best Simpsons episodes ever. They had Homer's Religion at #2 and the Dental Plan at #1. Those are great episodes, but I wouldn't have put them at 1 and 2. They made some other very questionable choices, like putting the Spring Break episode way back in the 40s.

My top episodes would look like this:

8. The Swimming Pool ("See, your epidermis means your hair, so technically, it's true.")

7. The Lemon Tree ("Run faster boy! He's got a taste for meat now!")

6. Homer Goes on Disability ("Stupid bird! I never should have left you in charge!")

5. Dental Plan ("See here Mr. Burns, I don't go in for these backdoor shenanigans.")

4. Lisa's Beach Vacation ("SWEET MERCIFUL CRAP! My CAR!")

3. Homer's Religion ("If I'm wrong, I'll recant on my deathbed.")

2. Bart's Soul ("Milhouse give him his soul back! I've got work tomorrow!")

1. Bart's Spring Break ("No, Principal Skinner, Bart's never been to Thailand.")


#1 and #2 is a really close call, because the Spring Break episode probably has more laughs, but Bart's Soul is the only Simpsons episode that is also beautiful.