Hi all
I'm just curious about this really, does anyone know why they broke convention on this one?
Thanks, Ciaran
Hi all
I'm just curious about this really, does anyone know why they broke convention on this one?
Thanks, Ciaran
There is no convention on the starting point of an array. Most Basics start at 1 also for example. Some languages let you start the array wherever you like, or allowarray indexes to be enumerations etc (Ada for example). C used the notion of sting at 0 and many languages have followed, but not all do. One reason why they don't is that arrays starting at 1 is far more intuitive.
There's two conventions, the one common to most programming languages, and the one common to most nonprogrammers. They were probably aiming at the people who don't start counting with 0.
If I had to guess, it's because ColdFusion was aimed to appeal to the novice, and 1-based arrays might make more sense - the first item is number 1, second is number 2 etc.
It's us computer scientists who are weird!
Well, unless we have any of the original designers, it's going to be tough to do anything but speculate. But having used CF in a previous life, I have some ideas.
If you look at the original language, it was designed for RAD type development for people who wanted to build dynamic applications without a lot of complexity. I still remember the joy when they finally released User-Defined Functions so I didn't have to use tags everywhere.
Based on that, then it would make sense that aspects of the language people had to deal with - such as arrays - they would make more "friendly". To me, seeing array[0] makes perfect sense. But to people new to the paradigm who haven't learned that, it wouldn't make any sense. Why would I access an object at position "0"?
The funny thing is that now that CF is Java in the backend, you actually have to deal with cases where your index starts at 1, and cases where it starts at 0. So by trying to be helpful, they actually added in more complexity as the language has grown.
Count the number of fingers you have on one hand. Did you start counting with 0 or with 1?
Abstract ideas that closely parallel real life are always more easily understood and applied (ex: think of a physical "stack" and then of the abstract data structure).
Even within the programming world of Java APIs there is an interesting exception the 0-based counting: The JDBC API. It starts counting with 1, much to the surprise of every programmer doing her first database access.
@Cory: You'd be surprised to know who lurking on StackOverflow. :-)
You are very much right. The original design of CFML was to allow non-programmers to build complex web applications. ColdFusion\CFML was the first language designed specifically for building web applications. Back in 1995 the web was mostly static HTML and your typical 'web developer' wasn't doing too much programming. The language itself was designed to be as simple as possible which is why it's still one of the fastest/easiest languages to learn.
It can lead to a bit of confusion, especially when ColdFusion code interacts directly with Java or .NET. However, it's just become one of those 'quirks'. The decision was revisited back in 2000/2001 when CF was rebuilt as a JEE application, but backward compatibility prevented the change.
The notion of starting arrays at 0 was popularized with the C language. Older languages such as FORTRAN and COBOL started counting arrays at 1 (actually called Tables in COBOL).