<cfforeach> ..<cfforeach>

19 views
Skip to first unread message

Alan Williamson

unread,
Feb 21, 2010, 10:59:56 AM2/21/10
to cfml-convent...@googlegroups.com
"var" !!! of course! doh! yes. much better.

i like the fact you don't need to think of the data type of the object
when looping around. that is a really nice addition.

or maybe just: <cffor> .. </cffor>

Matthew Woodward wrote:
> On Sun, Feb 21, 2010 at 7:16 AM, Alan Williamson <al...@aw20.co.uk
> <mailto:al...@aw20.co.uk>> wrote:
>
> i was thinking about this in the plane yesterday ... how about a new
> tag for this:
>
> <cfforeach element="" object="">
> </cfforeach>
>
> i am not sold on the "object" parameter name.
>
>
> I like it! Maybe "var" instead of "object" for consistency with a couple
> of other tags?

Matthew Woodward

unread,
Feb 21, 2010, 11:12:38 AM2/21/10
to cfml-convent...@googlegroups.com
On Sun, Feb 21, 2010 at 7:59 AM, Alan Williamson <al...@aw20.co.uk> wrote:
"var" !!! of course! doh!  yes. much better.

i like the fact you don't need to think of the data type of the object when looping around.  that is a really nice addition.

or maybe just:  <cffor> .. </cffor>


If it's just <cffor> it's a bit redundant with the normal indexed <cfloop>, but I suppose then that same construct could be used for looping over objects/collections as well as just regular for loops. And actually this makes the attributes potentially a bit different:

<cffor each="element" in="collection"> ... </cffor>

and

<cffor index="i" from="1" to="10"> ... </cffor>

Not sure I'm a huge fan of this redundancy with the normal <cfloop> so I'm more throwing this out as fodder for discussion.
--
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

Alan Williamson

unread,
Feb 21, 2010, 11:19:06 AM2/21/10
to cfml-convent...@googlegroups.com
true ... is it better to have:

1. a new tag to illustrate the power of this type-less looping

_or_

2. add each/in attributes to CFLOOP instead of creating more tags?


i am favouring Option#2 here, but only 60% / 40%. Interesting to see
what others think.

Matthew Woodward

unread,
Feb 21, 2010, 11:25:27 AM2/21/10
to cfml-convent...@googlegroups.com
On Sun, Feb 21, 2010 at 8:19 AM, Alan Williamson <al...@aw20.co.uk> wrote:
i am favouring Option#2 here, but only 60% / 40%.  Interesting to see what others think.

I'd lean pretty heavily towards #2 after typing out those basic examples, but I'll be interested to see what others think as well.

Mark Jones

unread,
Feb 21, 2010, 11:43:53 AM2/21/10
to cfml-convent...@googlegroups.com
> i am favouring Option#2 here, but only 60% / 40%. Interesting to see what
> others think.

The only advantage to having a new tag is that you can ignore
backwards compatibility for the attributes. Beyond that, having
<cfloop> AND <cfforeach> is silly. I especially dislike <cffor>
because the most common use of for statements is a simple numeric
incrementing loop, which IS <cfloop from="" to="" index="">.

Wait.. isn't foreach effectively <cfloop collection="blah"> ? I know
that doesn't handle all datatypes at the moment.

Matthew Woodward

unread,
Feb 21, 2010, 11:46:05 AM2/21/10
to cfml-convent...@googlegroups.com
On Sun, Feb 21, 2010 at 8:43 AM, Mark Jones <mark...@visi.com> wrote:
Wait.. isn't foreach effectively <cfloop collection="blah"> ? I know
that doesn't handle all datatypes at the moment.
 

But it would address the looping syntax differences between datatypes, which I think is what's at the core of this discussion.

Alan Williamson

unread,
Feb 21, 2010, 11:46:54 AM2/21/10
to cfml-convent...@googlegroups.com
Mark Jones wrote:
> Wait.. isn't foreach effectively<cfloop collection="blah"> ? I know
> that doesn't handle all datatypes at the moment.

you are right Mark, that could be overloaded to use other data types
too. i fear that would break too much backward compatibility.

Sean Corfield

unread,
Feb 26, 2010, 12:52:06 AM2/26/10
to cfml-convent...@googlegroups.com
On Sun, Feb 21, 2010 at 8:46 AM, Alan Williamson <al...@aw20.co.uk> wrote:
> you are right Mark, that could be overloaded to use other data types too.  i
> fear that would break too much backward compatibility.

One reason for perhaps preferring <cffor>: it matches cfscript:

for ( key in collection ) { ... }
for ( i = 1; i <= n; ++i ) { ... }
--
Sean A Corfield -- (904) 302-SEAN
Railo Technologies US -- http://getrailo.com/
An Architect's View -- http://corfield.org/

"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood

Reply all
Reply to author
Forward
0 new messages