ColdFusion: Do we *need* interfaces?
One of the most requested features from the OO CF crowd has been the implementation of interfaces in ColdFusion. Sean Corfield has seems to be on the "don't need them" side of the fence nowadays and has sparked a lot of comments (a *lot*) with his entry on the subject. While I was for them for a while, I switched over last May, and thought it might be a good time to re-run my old blog entry on the subject:
Updated 11:05PM EST, Jan 11: I've shut off comments on this post, as it's becoming the same discussion as is on Corfield.org. Please visit Sean's Post to chime in!
Originally blogged May 16, 2005
Get over it: CF isn't Java
There's a lot of "We want interfaces! Nulls! Method overloading!" going on in some of the CF lists, and I really think it's a misunderstood push to become more "OO." Helping to implement CF solution in an OO manner really has nothing to do with any of the above demands, and a lot to do with shifting how you think.
Adobeflobiemedia (or whatever we'll call it this week) could implement all of the above, and it probably wouldn't make a lot of people's code any more OO. Having the constructs available (interfaces, nulls, overloading) doesn't make a language OO: just look at how much Java, C++, and C# is procedural code hammered into the OO constructs.
First: Formal, compile-time interfaces
Don't need 'em. Don't really want 'em enforced in the language.
My simple solution:
Draw a class diagram showing what the interface is, provide a shell CFC, and kick everyone's rear into following the contract. Let Macrodobe focus on cool features, not something a small percentage of CF developers will use.
Second: Nulls
They're championed because of code like this (ripping off a recent example from CFCDev):
if (person.getSpouse() == null) { write("Person is not married!") }
I really don't like this style of coding (even though it's really, really common in some languages). Instead, if a person doesn't have a spouse, and you ask for one, isn't that an exception?
try (person.getSpouce()) { catch { write("Person is not married") } }
Or, better yet:
if (!person.isMarried()) { write("Person is not married") }
Third: Overloading
He who can successfully implement overloading in a typeless language has a great big brain. Any implementation I can think of is a cheap hack that'd be endlessly debated to the harm of many and benefit of few.
I spent a good deal of my time at my last job chasing overloading hierarchies through a big inheritance tree. I really don't ever want to do it again, so please, look for more elegant ways to get things done.
PS: I'm contradicting myself a bit, as I am one of the votes for interfaces being added to the CF feature set. If possible, I'd like to retract my vote.
13 comments - Posted by Joe Rinehart at 9:03 AM - Categories: ColdFusion MX
