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.
30 comments - Posted by Joe Rinehart at 12:13 PM - Categories: ColdFusion MX