Language Oddities

21 views
Skip to first unread message

Alan Williamson

unread,
Feb 17, 2010, 4:23:19 AM2/17/10
to CFML Conventional Wisdom
Did anyone spot this site doing the rounds regarding all the edge case
oddities that Javascript has?

http://wtfjs.com/

While there are some real humdingers in there. But as a typeless
language, we as CFML suffer from some of the things there that they
list as WTF where in actual fact we embrace in CFML. For example, 3
== "3"

For me, that has been one of the frustrating things with CFML at
times, is identifying which edge cases are in actual fact there by
design, or just by sheer fluke. It is the "sheer fluke" situations
that scare me, as they become folklore and expected to be there till
the end of time.

Matt Woodward

unread,
Feb 18, 2010, 4:58:59 PM2/18/10
to CFML Conventional Wisdom
On Feb 17, 1:23 am, Alan Williamson <a...@aw20.co.uk> wrote:
> It is the "sheer fluke" situations
> that scare me, as they become folklore and expected to be there till
> the end of time.

It would be nice to come up with a running list of things that should
be deprecated and eventually eliminated if there's no rational
justification for their existence. This way people would know well in
advance and since this is an open list, we'd hear from people who
might have legitimate arguments for some of these oddities.

At this point in CFML's history I think some cleanup is definitely in
order, and we certainly don't want to exacerbate the situation by
introducing new WTFs as new features are added to the language.

cfchris

unread,
Feb 18, 2010, 9:27:44 PM2/18/10
to CFML Conventional Wisdom
I can't understand why Adobe used the "index" attribute for "Array"
loops. What you really get is a handle on the "item" in the array. So,
since there is already a "collection" loop that uses an "item"
attribute, why did Adobe use "index"? And would it be a big deal to
make it work with the "item" attribute while leaving support for
"index"?

Dennis Clark

unread,
Feb 18, 2010, 11:47:41 PM2/18/10
to cfml-convent...@googlegroups.com
I find even the "item" attribute in collection loops counter-intuitive. Whenever I use a collection loop I often think that the "item" variable will be assigned the values of the structure being looped over. It's usually not until I get an error that I remember that the variable is actually assigned the keys in the structure.

Keys are a structure's equivalent of array indexes, so why didn't Adobe use the "index" attribute for looping over structure keys in a collection loop, and use the "item" attribute for looping over the structure values in a collection loop?

If you accept this logic, then for consistency's sake using the "index" attribute for array loops ought to assign the variable with each valid index in the array. Such a feature is not quite as dumb as it sounds as ColdFusion arrays can contain holes (such arrays often called "sparse"). In other words:

  <cfloop index="i" array="#array#">
    <!--- loop body --->
  </cfloop>

ought to be equivalent to:

  <cfloop index="i" from="1" to="#ArrayLen(array)#">
    <cfif ArrayIsDefined(array,i)>
      <!--- loop body --->
    </cfif>
  </cfloop>

And:

  <cfloop item="item" array="#array#">
    <!--- loop body --->
  </cfloop>

ought to be equivalent to:

  <cfloop index="i" from="1" to="#ArrayLen(array)#">
    <cfif ArrayIsDefined(array,i)>
      <cfset item = array[i] />
      <!--- loop body --->
    </cfif>
  </cfloop>

Unlike cfchris's suggestion, these changes would break compatibility with existing code, so they are really more of a WTF than a serious suggestion.

-- Dennis


Alan Williamson

unread,
Feb 19, 2010, 2:58:47 AM2/19/10
to CFML Conventional Wisdom
This is definitely an area that catches me out every so often.

I think we could propose adding an extra couple of attributes so we
didn't break backward compatability, but at the same time, clean up a
lot of confusion for new people coming to CFML

<cfloop collection="#c#" key="mykey">
<cfset a = c[ mykey ]>
</cfloop>

<cfloop array="#a#" element="el">

</cfloop>

On Feb 19, 4:47 am, Dennis Clark <boomf...@gmail.com> wrote:
> Keys are a structure's equivalent of array indexes, so why didn't Adobe use
> the "index" attribute for looping over structure keys in a collection loop,

> and use the "item" attribute for looping over the structure *values* in a
> collection loop?

Mark Drew

unread,
Feb 19, 2010, 7:00:52 AM2/19/10
to cfml-convent...@googlegroups.com
That always gets me, since I want an "item" in an array... the index being a number normally right?

MD

On 19 Feb 2010, at 02:27, cfchris wrote:

> I can't understand why Adobe used the "index" attribute for "Array"
> loops. What you really get is a handle on the "item" in the array. So,
> since there is already a "collection" loop that uses an "item"
> attribute, why did Adobe use "index"? And would it be a big deal to
> make it work with the "item" attribute while leaving support for
> "index"?

Mark Drew
Railo Technologies UK
Professional Open Source
skype: mark_railo
email: ma...@getrailo.com
gtalk: ma...@getrailo.com
tel: +44 7971 85 22 96
web: http://www.getrailo.com

Mark Drew

unread,
Feb 19, 2010, 7:01:49 AM2/19/10
to cfml-convent...@googlegroups.com
This would make a lot more sense too!

On 19 Feb 2010, at 07:58, Alan Williamson wrote:

> <cfloop collection="#c#" key="mykey">
> <cfset a = c[ mykey ]>
> </cfloop>

Mark Drew

Matthew Woodward

unread,
Feb 19, 2010, 10:50:39 AM2/19/10
to cfml-convent...@googlegroups.com
I'm going to start tracking some of this in "pages" on the google group so the details of the discussions don't get lost, and also so people who missed the original discussion can see a summary.

Here's the first one:
http://groups.google.com/group/cfml-conventional-wisdom/web/cfloop
--
Matthew Woodward
ma...@mattwoodward.com
http://blog.mattwoodward.com
identi.ca/Twitter: @mpwoodward

Please do not send me proprietary file formats such as Word, PowerPoint, etc. as attachments.
http://www.gnu.org/philosophy/no-word-attachments.html
Reply all
Reply to author
Forward
0 new messages