views:

411

answers:

8

Hi all

I'm just curious about this really, does anyone know why they broke convention on this one?

Thanks, Ciaran

+2  A: 

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.

David Arno
As David says, most Basics start arrays at 1. At the time when CF first emerged it was competing with Classic ASP, which was/is typically coded using VBscript, a subset of Visual Basic.
James Marshall
@James, VBScript was an odd one. If you asked for an array of size 50, it would give you a 51 element array that started at element 0. That menat you could start at 1 if you wanted to and not run past the end of the array, or you could start at 0.
David Arno
+9  A: 

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.

David Thornley
Well put. That same dichotomy persists in other areas too, such as WYSIWYG editors, and drag-drop file manipulation versus scripts.
Mike Dunlavey
This is a false dichotomy, but you made the point in a far more succinct fashion than I :)
David Arno
+7  A: 

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!

Paul Dixon
+5  A: 

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.

Cory Foy
+4  A: 

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).

Shane
zero always zero. My kid in kindergarten also had to tell its teacher counting starts at 0. Look at the age of children, bankaccount, nr of cars you own, nr of times you are married, etc, etc.Starting to count at 1 is an indication you are loosing touch with reality.
GvS
@GvS: As opposed to /losing/ touch...and not learning to spell properly. I doubt your counting skills based on this lack of basic English skills.
Jeff Yates
@GvS, you are talking nonsense. A child's age is never 0, it's already 9 months old when it's born and its age is then measured in seconds, then minutes, hours, days, weeks etc. Never 0, always a positive number. And many people's bank accounts count from a minus number downwards :p
David Arno
@GvS: So the first dollar in your bank account is dollar number 0? The first car you buy is considered car number 0? The first time you are married is considered wife number 0? It simply makes no real-life sense to number the first item of a collection as zero. Zero means NO items.
Shane
When I open my bankaccount, It does have € 0,- on it, after that, I can start putting money on it. Sorry I'm no native English speaker/writer, but the message was clear ;-) And naturally if you need to enter the kids age it is 0 years (not always months, etc is available to choose from)
GvS
And before you are married the first time, you are married 0 times. Before you own a car, you own 0 cars. Yes, counting starts as 0.
GvS
And now for counting fingers: Make a fist -> 0, eject thumb -> 1, add finger -> 2, ...
GvS
@GvS: Your fist is not a finger. Your first finger is finger number ONE. An array initially starts off with zero elements, but the first element you put in the array should be element number ONE.
Shane
@Shane: mmm, there you have a point. OK, you convinced me. Counting should start at 1.
GvS
Counting starts from 0, but the first element is element number 1.
Silvercode
A: 

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.

mkoeller
+14  A: 

@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.

Adrocknaphobia
+1  A: 

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).

Turnkey