Discussion on cfloop

8 views
Skip to first unread message

cfchris

unread,
Feb 19, 2010, 12:42:23 PM2/19/10
to CFML Conventional Wisdom
I'd like to throw in my original suggestion for the array loops. Which
is to leave the <cfloop array="#a#" index="i"> syntax for backwards
compatibility (even though it was a mistake). And add the following
syntax which uses an existing attribute and I think communicates more
clearly what the array loop does.

<cfloop array="#a#" item="i">
<cfset i.setSomething('foo') />
<cfoutput>#i.getSomething()#</cfoutput>
</cfloop>

Chris Phillips

unread,
Feb 19, 2010, 1:06:01 PM2/19/10
to CFML Conventional Wisdom
OK,

Sorry for the extra email traffic. I was using the "Discuss this page" feature because I could not find a way to edit it. I thought it would show up at the bottom of the page like a comment. It doesn't. Now I know that now.

So, Matt, if you could add my suggestion (or allow others to edit the page?), I would appreciate it.

Thanks,

Chris P.



Matthew Woodward

unread,
Feb 19, 2010, 1:23:02 PM2/19/10
to cfml-convent...@googlegroups.com
On Fri, Feb 19, 2010 at 10:06 AM, Chris Phillips <cfc...@gmail.com> wrote:
So, Matt, if you could add my suggestion (or allow others to edit the page?), I would appreciate it.


Yep, I'll add it. I don't think there's a way to make pages publicly editable unfortunately. Probably good to have a bit of a filter on the pages anyway, so everyone should definitely speak up if any of the page summaries miss anything. Thanks.

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

Matthew Woodward

unread,
Feb 19, 2010, 1:40:37 PM2/19/10
to cfml-convent...@googlegroups.com
On Fri, Feb 19, 2010 at 10:06 AM, Chris Phillips <cfc...@gmail.com> wrote:
So, Matt, if you could add my suggestion (or allow others to edit the page?), I would appreciate it.


Updated the page.

Mark Jones

unread,
Feb 19, 2010, 1:20:22 PM2/19/10
to cfml-convent...@googlegroups.com
> Sorry for the extra email traffic. I was using the "Discuss this page"

If I didn't want email traffic I wouldn't have signed up for an email list :)

But on the topic of <cfloop> I'd also like to add my own pet peeve:
the inability to do <cfloop query="whatever" group="somecolumn"> .
There would need to be some thought on unambiguously connecting the
inner loop to the outer grouping one, but it just has always been
weird that you have to use <cfoutput> to do these sort of loops.

It's especially awkward if you're already inside a generic <cfoutput>
block and need to close that first.

Mark Drew

unread,
Feb 19, 2010, 1:47:32 PM2/19/10
to cfml-convent...@googlegroups.com
+ 1 for this, why was this just with cfouput? Well, I can understand the idea if we are just doing loops in templates.

Also, you might kick me for this, in cfscript I would love to see a loop construct, su) as:

loop(query=myquery){
var item = myquery.name;
}

and

loop(array=myArray, item="x"){


}

and

loop(collection=stCollection, item="x"){


}

AAAAND whilst we are at it, why isn't it:

<cfloop query="#queryname#">

instead of

<cfloop query="queryname">


On 19 Feb 2010, at 18:20, Mark Jones wrote:

> But on the topic of <cfloop> I'd also like to add my own pet peeve:
> the inability to do <cfloop query="whatever" group="somecolumn"> .
> There would need to be some thought on unambiguously connecting the
> inner loop to the outer grouping one, but it just has always been
> weird that you have to use <cfoutput> to do these sort of loops.

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

Alan Williamson

unread,
Feb 19, 2010, 1:50:43 PM2/19/10
to cfml-convent...@googlegroups.com
Mark Drew wrote:
> Also, you might kick me for this, in cfscript I would love to see a loop construct, su) as:
>
> loop(query=myquery){
> var item = myquery.name;
> }

do it with the "for(...){}" syntax and keep it like other langauges and
you have my support.


> AAAAND whilst we are at it, why isn't it:
>
> <cfloop query="#queryname#">
> instead of
> <cfloop query="queryname">

+++1 absolutely! That is a huge inconsistency and i have seen it
tripping up many a new CFML developer.

Matthew Woodward

unread,
Feb 19, 2010, 2:05:55 PM2/19/10
to cfml-convent...@googlegroups.com
Got all this added--let me know if anything doesn't accurately represent the points people are making. Great stuff!

Mark Jones

unread,
Feb 19, 2010, 2:22:48 PM2/19/10
to cfml-convent...@googlegroups.com
>> loop(query=myquery){
>>        var item = myquery.name;
>> }
>
> do it with the "for(...){}" syntax and keep it like other languages and you
> have my support.

I like the idea of a generic loop instruction like those examples
because it helps tie the script language to the tag language. I think
that's CFML's biggest organizational problem: making the two coding
methods feel like one language instead of two, being able to slip
between them at will. Obviously there will be stuff that's unique one
way or another, but it would be wonderful if you could do script <->
tags translation with a handful of syntax rules. But the inevitable
script/tag beatdowns are for another thread :)

>> <cfloop query="#queryname#">


>
> +++1  absolutely!   That is a huge inconsistency and i have seen it tripping
> up many a new CFML developer.

It might help in explaining to people why they don't need to do <cfset
newvar = "#oldvar#"> as well. To be honest, I've seen more people get
tripped up by the needed #s in <cfdump var="#quueryname#">. Of course,
that might not happen if the difference between strings/variable names
and the objects/variables themselves were more consistent across tags.
This is an example where the basic syntax of tags is actually the
problem, since all attributes are quoted and therefore assumed to be
strings.

Glen dunlop

unread,
Feb 20, 2010, 9:39:50 PM2/20/10
to cfml-convent...@googlegroups.com
Mark,

Adobe have already indicated that ColdFusion 9 updater 1 will have

for(arrayItem in array) {}

And I am sure the ticket also asked for others like list etc.



Baz

unread,
Feb 22, 2010, 5:25:51 AM2/22/10
to cfml-convent...@googlegroups.com
If you ask me, the perfect cfloop would simply be:

<cfloop object="#ANYOBJECT#">

- ANYOBJECT can be a query, array or struct and the engine loops accordingly.

- ITEM and INDEX should both be optional, and if not specified,
variables called "item" and "index" become available automatically in
the loop.

- Most importantly, *both* ITEM and INDEX should exist for every loop
- no matter what the object is. So if you loop through an array, you
get the position in the "index" and the actual value in the "item".
With a struct, you get the key name in the "index" and the value in
the "item". With a query you get the row in the "index" and the query
row in the "item". I find it happens a lot that you code an array
loop, only to find out later that you also need the position, so you
have to refactor to a from/to loop. Why not have both?

Baz

unread,
Feb 22, 2010, 5:27:45 AM2/22/10
to cfml-convent...@googlegroups.com
> With a query you get the row in the "index" and the query
> row in the "item".

Clarification: With a query you get the row NUMBER in the "index" and
the actual query row in the "item"

Reply all
Reply to author
Forward
0 new messages