Hi, I'm ColdFusion, and so am I. (Is CF Schizophrenic?)

Hi, I'm ColdFusion, and so am I. (Is CF Schizophrenic?)

Posted by Brad Wood
Jul 05, 2008 23:18:00 UTC
Sometimes I wonder about ColdFusion. Mostly when it gets depressed and locks itself in the bathroom with a box of chocolates. Seriously though, the identity of CF can sometimes be illusive when you listen to what everybody wants all at once. ColdFusion is different than most languages and I think that's a good thing, but what pushes us to request the changes we want? Do we wish CF was easier to pick up for the beginner? Perhaps we want it to behave a bit more like our favorite scripting language for our benefit or to impress our friends.One thing I've struggled with is wondering how far we go before ColdFusion turns into all the other languages. (Not that I think we are anywhere close yet) These are really just questions so don't flame me over any of them but here is a quick list of notable differences that came to mind that I wanted to mull over:

Scope Hunting

One basic feature that is often overlooked or unnoticed is the fact that ColdFusion will not require you to scope your variables. In fact, it will go to great lengths to find the one you were looking for, but relying on that is not without its risks. Certain people will tell you that you should ALWAYS explicitly place all ColdFusion variables into a scope--if not to prevent bugs, at least to make your code easier to maintain. Well, that's a bit more typing, and it certainly makes sense at some level, but if it is true should Adobe abolish scope hunting? Backwards compatibility will probably keep it around forever, but is un-scoped variables part of what makes ColdFusion easy and useful for a beginner, or is it a death trap for your code?

Object Oriented

ColdFusion definitely supports OOP now (Encapsulation, polymorphism, inheritance), but it wasn't always that way. Is this just a sign of the changing programming landscape? Did the first versions of CF allow for mostly procedural code because CF didn't need to be OO, or was it always in the works and just hadn't came about yet?

Loosely Typed

Here's another one of those really handy parts of ColdFusion. You can declare a variable and not care about what you're about to place in it. Want to turn that array into a string? How about an integer now or a date? Bring it on! Arguments to CFC methods and UDFs don't even have to have a type specified. Heck, I don't even have to specify ANY arguments; I can just pass in whatever I want. Of course, there are those that tell you that not only should each argument should be specified, and typed, but your return type should also be correct as well. Well now that you mention it, that does sound like a good idea. But consider this: if you pass a string in where as array was expected, your code will error at run-time anyway, so what's the difference? Are we all too eager to make ColdFusion work just like Java and C++ that we lose sight of why it is so handy for Rapid Application Development?

ECMA Script Compliant

I've been on this bandwagon before (and I'm probably still on it). The question is, do I wish CFScript was ECMA compliant because I truly believe it will make the language faster, more efficient, or easier to code, or is it because I want to show it to my .NET and Java friends and say, "See, it's a real language. Look how easily you could switch over and not even notice!" Frankly, I'm afraid that I've personally fell in love with the idea because I've got it in my head that CF would somehow be a bit more validated and maybe the cool languages would let it hang out after school every once in a while.

1-based indexes

I don't think I've ever heard someone say that ColdFusion should change this, but I threw it in the list because it is a notable difference between CF and about every other language I have ever used. When I learned C++ it made perfect sense how an array of variables was simply a pointer in memory to the start of the array, and the index multiplied by the storage size of the data type was the memory offset for that index. But ignoring the gory implementation details, if you were to design a language by what made the most, simplest sense taking no existing languages into account, I'd start my array indexes at one any day of the week. Still I wonder sometimes if those other popular languages are snickering in the locker room saying, "Look at loser ColdFusion over there. It doesn't even start its array indexes at 0!"

Multi-threading and Interfaces

These are two items, but they are both pretty minor. Their commonality is that ColdFusion originally had no support for them and now it does--undoubtedly with the help of some community pressure. I can't deny the usefulness of them, but I do also wonder if our strong desire to be as OO as the Jones made us think we couldn't live without them. Some of my topics seem to have a different answer based on what you want ColdFusion to be. Should it be a basic domain specific language that can easily be picked up by a beginner and make the most sense, or should it cater to the advanced programmers out there who have a lot of expectations they have brought with them from their last language? Honestly I think Allaire, Macromedia, and now Adobe have done a bang-up job of bridging that gap and giving us the best of both worlds. I occasionally question my motives for alteration though. I'm not sure if I want some changes for the good of the language or just to make it more appealing to the outside world. What do you (and your other personalities) think?

 


radekg

"if you pass a string in where as array was expected, your code will error at run-time anyway, so what's the difference?" That is true but if we had nicely working IDE for CF it would not happen.

radekg

"I'd start my array indexes at one any day of the week." Another good point. Even Java in some places is incosistent with this. For example when you use ResuktSetMetaData.getColumnName(int) columns are indexed starting from 1. Other example is accessing cells and rows in Excel add-ins. Both cells and rows are indexed from 1 :)

Brad Wood

@radekg: You are correct that a good CF IDE could help check the things that compilers usually would stop you on, but it would never be possible to create a ColdFusion IDE to cover every base For instance, since CF is truly a dynamic language, methods can be injected into a CFC at run time. How does the IDE know that I'm not planning on replacing a method with another at run time that expects an entirely different set of arguments?

Thanks for the note on Java's inconsistencies on indexes. I didn't know that!

Adrian Lynch

I'm kinda proud that CF has 1 based indexes, so does Smalltalk, the GREATEST OO language out there :OD

CF hunts scopes cos it's fun, not cos it has to... it gets bored easily! ;O)

Site Updates

Entry Comments

Entries Search