Skip to main content
nikos101
Inspiring
November 17, 2010
Answered

Why does coldfusion number arrays and dates from 1

  • November 17, 2010
  • 3 replies
  • 1542 views

Why does coldfusion  number arrays and other structures from 1. Its pretty infuriating when the rest of the world mostly starts from 0?

    This topic has been closed for replies.
    Correct answer Adam Cameron.

    Zero-based arrays are a legacy of the days of the system needing to work out the offset from the base memory address that the array is stored at to locate the start address of each element.  So it makes kinda sense that the first element is offset from the base address by a factor of zero.

    There are languages that predate C (from which C++ sprouted as some sort of horrendous nightmare) which use 1 as the starting index... it's just C was pared down to minimise the translation from C to machine code, and in this case 0 makes more sense.  And other "curly bracket" languages just copied it.  It certainly - in modern times in which the source language is generally so far removed from machine language - makes little sense to persist with this sort of approach for any good reason other than copying what some other language has done.

    In human terms, there is not a zeroth element in a  collection, and given there isn't really any processing saving any more  in just starting the array from a more human-friendly position, why  not?

    I mean... how confusing is it really to remember which language does which?

    --

    Adam

    3 replies

    Adobe Expert
    November 18, 2010

    ColdFusion was originally intended for people who didn't have much (or any) programming experience. Without any programming experience, it's not immediately obvious why you'd want to start counting from zero instead of one. It's like COBOL for the web!

    Dave Watts, CTO, Fig Leaf Software

    http://www.figleaf.com/

    http://training.figleaf.com/

    Fig Leaf Software is a Veteran-Owned Small Business (VOSB) on

    GSA Schedule, and provides the highest caliber vendor-authorized

    instruction at our training centers, online, or onsite.

    Read this before you post:

    http://forums.adobe.com/thread/607238

    Dave Watts, Eidolon LLC
    Inspiring
    November 17, 2010

    ColdFusion's roots were to enable the development of server-side applications by HTML designers - at the time there were few tools for doing server side web development (PERL, etc), all of which were non-intuitive to someone with no programming language background.  Hence the tag-based syntax instead of a script-based language. In the real world very few things that are numbered start at 0.  Over the years ColdFusion has added more and more capabilities and until recently pretty much left the "real programming language" server-side technologies in its dust, but still has the reputation among many of not being a "real" programming language because of things like this.

    -reed

    Participating Frequently
    November 17, 2010

    It is interesting, though, isn't it, that C++ (which CF was written in

    prior to CFMX) is 0-based, too?

    http://go.microsoft.com/?linkid=8310949

    nikos101
    nikos101Author
    Inspiring
    November 18, 2010
    I mean... how confusing is it really to remember which language does which?

    Quite. For me it's normally this easy:

    Me: myArr[0] = myStr;

    CF: Array reference is out of bounds.

    Me: Oh yeah, right.

    EDIT: Really glad I spent time formatting that all in colours and fonts just for it to ignore it all when it displayed.


    Its also things like dates that confuse, sunday is 0

    in as3, t-sql but 1 in CF. Stuff like that really annoyes me.

    Owainnorth
    Inspiring
    November 17, 2010

    I can only assume it's to increase the usability of a Rapid Application Development (*shudder*) tool such as CF. If you had to explain arrays to a non-programmer it seems nonsensical to start with a zero; I'd guess in the early days it was assumed that if you wanted a tool that meant not having to learn a programming language then you probably weren't aware of C-style array offset notation, and didn't care to learn.

    If you're thinking logically and numerically then technically CF is the *correct* way of doing it, and perhaps it's a shame the entire world doesn't use that. After all, what makes more sense than notating the first value as Array[1]? However once you get into things like C it makes more sense to use a zero, so you do.

    One of those things I guess. It'd be nice if everyone drove on the correct side of the road (ahem, the left), spoke the same language and used the same currency. But then it'd be boring