tracker issue : CF-3754577

select a category, or use search below
(searches all categories and all time range)
Title:

cfloop() does not support most of the <cfloop> tag's functionality

| View in Tracker

Status/Resolution/Reason: To Fix//

Reporter/Name(from Bugbase): Adam Cameron / Adam Cameron (Adam Cameron)

Created: 05/04/2014

Components: Language

Versions: 11.0

Failure Type:

Found In Build/Fixed In Build: PublicBeta /

Priority/Frequency: Major / Some users will encounter

Locale/System: English / Platforms All

Vote Count: 6

See: http://cfmlblog.adamcameron.me/2014/05/coldfusion-11-cfloop-in-cfscript-very.html

in summary. These sort of <cfloop> operations don't work:

collection
array
list
indexed
condition

All of them should, as the generic CFScript handling of tags should be a one-to-one mapping of functionality. Not just bits and pieces.

-- 
Adam

----------------------------- Additional Watson Details -----------------------------

Watson Bug ID:	3754577

External Customer Info:
External Company:  
External Customer Name: Adam Cameron.
External Customer Email:  
External Test Config: My Hardware and Environment details:

Attachments:

Comments:

Though we have added a generic approach for the script syntax for all tags, it does not work in cfloop's case as the tag implementation is directly in the generated code. the exception being query or file and that is why looping over a query or file works but others don't. Though it would be ideal to do this for completeness, is this really required? We already have cfloop equivalent in cfscript - using "for", "for-in" and "while" loops. file is the only thing that is not supported by "for" or "for-in". I feel we should stick to the "for", "for-in" & "while" and throw a good error for cfloop with indexed, array, list, collection and condition. Thoughts?
Comment by Rupesh K.
12343 | May 05, 2014 03:12:54 AM GMT
I'm split on this on. On one hand if you're gonna do this porting of tags to CFScript with this generic approach rather than with a situation-specific one, then I think the approach should be all-encompassing. If it's *generic* don't second-guess stuff, just do it. On the other hand, I think perhaps having implemented cfloop() *at all* was perhaps a bad move. Instead it would have been better to augment the existing CFScript looping construct: for(). There's no reason why that could not have accommodated query- and file-looping functionality. The benefit of this is that for() is a familiar construct for everyone, and it doesn't necessitate yet *another* looping construct. What you've ended up with is - same as with the list member functions - a situation where the language isn't "hackable". One cannot simply infer how the looping works from the behaviour of existing constructs. There is no rhyme or reason why one would use for() for arrays, but cfloop() for queries. It makes no sense. One needs to know the inner workings of what the CF Team decided to know how things work, which I think is fairly opaque language design. I am going to solicit more community input on this, to see what people think. -- Adam
Comment by External U.
12344 | May 05, 2014 03:32:04 AM GMT
Since the solution is generic, it applies to all the tags including cfloop. There is no specific implementation to get cfloop to work in cfscript. It happened automatically because of the generic solution. I agree that cfloop() should not be there in the script syntax at all. The current looping constructs - for, for-in and while are sufficient. "for-in" works for array, struct, list and query. All we need to is to add the support for 'file' in the same. Sounds good?
Comment by Rupesh K.
12345 | May 05, 2014 04:49:51 AM GMT
Hi Rupesh: IMO enhancing for() would be better. I guess the generic implementation is slightly borked if most of the cfloop() options don't actually work? You must have a way of *not* implementing the generic versions, given stuff like cfclient(){}, cfinvoke(){} etc haven't been implemented by design. I recommend doing the same for cfloop(){}, this being the case? I've asked for the bods in the community to pitch in here (http://cfmlblog.adamcameron.me/2014/05/looping-in-cfml-community-input.html), so might be good to see what other people's opinions are. -- Adam
Comment by External U.
12346 | May 05, 2014 05:55:47 AM GMT
Hi Rupesh and Adam, I just had a couple questions first (basically for Rupesh): 1) What would be the for() syntax for grouped query loop? 2) Would the for() syntax for grouped query loop support the enhancements in #CF-3041787? #CF-3041787 is specifically for _child_ _query_ loops. It is for naming these <cfloop>s so that they can be broken out of from any descendant loop. It is also for naming these <cfloop>s so that we have loop-specific CurrentRow & RecordCount (the CurrentRow & RecordCount of the slice of the query that the child loop is looping over) Thanks!, -Aaron
Comment by External U.
12347 | May 06, 2014 04:34:36 AM GMT
I vote for removing cfloop from cfscript and adding support in the "for" loops for the file loops (and whatever else cfloop has that "for" doesn't)
Vote by External U.
12358 | September 02, 2014 11:08:52 AM GMT
Rupesh, what's the status of this? It says "to track". I don't know what that means. Can you please clarify? Cheers.
Comment by External U.
12348 | September 09, 2014 01:31:17 AM GMT
We should definitely improve "for" to support 'file'. We would should also evaluate if all the variations of cfloop tag can be supported in the script syntax. If that is not possible or requires a lot of effort, we should just throw error for cfloop in script. We don't need these loop constructs if we already have 'for', 'for-in' and 'while'.
Comment by Rupesh K.
12349 | September 09, 2014 03:22:21 AM GMT
Hi Rupesh, Regarding: "We don't need these loop constructs if we already have 'for', 'for-in' and 'while'." What about grouped query looping as it isn't supported via for/for-in/while? Also, it'd be nice to have child-loop-specific CurrentRow & RecordCount (via giving each loop an id). And break/cfbreak could break out to a specific loop id. Thanks!, -Aaron
Comment by External U.
12350 | September 09, 2014 11:53:39 AM GMT
Aaron, Grouped looping in 'for' is a good usecase (though we need to find out the feasibility about this) Why would you need loop-specific CurrentRow and RecordCount? Wouldn't those variants with the queryName prefix suffice? And the 'break to a specific loop' sounds like the 'goto #lineNumber' statement. Any solid usecase?
Comment by Himavanth R.
12351 | September 12, 2014 03:12:46 AM GMT
There's a good case for keeping an iteration counter on internal loops as well as the outer loop. Indeed the main currentRow counter is pretty useless when doing a grouped loop.
Comment by External U.
12352 | September 12, 2014 03:47:48 AM GMT
Hi Himavanth, 1) Regarding "Grouped looping in 'for' is a good usecase": Awesome, thanks! 2) Regarding "Why would you need loop-specific CurrentRow and RecordCount?": To display loop-specific row counter and total rows. As Adam mentioned, the queryName prefix does not help here b/c it always references the outermost loop. 3) Regarding "'break to a specific loop' .... Any solid usecase?": Primarily to break out of the outermost loop from within any descendant loop. I'd included #2 and #3 in #CF-3041787. The group="" attribute was added to cfquery, but the loop-specific features were never implemented. I can attach use case code examples, but should I attach them to #CF-3041787 or create a new ticket? Thanks!, -Aaron
Comment by External U.
12353 | September 12, 2014 01:26:19 PM GMT
The group="" attribute was added to cfquery should've been The group="" attribute was added to cfloop
Comment by External U.
12354 | September 12, 2014 02:29:56 PM GMT
Grouped looping can stay here but the other 2 will have to move to a new bug since they are enhancements over the current features of cfloop tag. This bug is for replicating the existing features of cfloop tag in script syntax (most probably in 'for') I believe queryName.recordcount should suffice in all cases except when group is used. And queryName.currentrow should work fine even with group. We can discuss them in the new bug. Please include the usecase examples too.
Comment by Himavanth R.
12355 | September 15, 2014 02:32:53 AM GMT
Hi Himavanth, I already filed #CF-3041787. It just needs to be re-opened b/c it was never fixed. Thanks!, -Aaron
Comment by External U.
12356 | September 15, 2014 06:46:33 PM GMT
+1 ......................
Vote by External U.
12359 | September 27, 2015 01:17:27 PM GMT
+1 ...................................
Vote by External U.
12360 | October 01, 2015 05:11:03 PM GMT
+1. . . . . . . . . . . .
Vote by External U.
12361 | October 01, 2015 09:49:48 PM GMT
Can you please confirm in what version of ColdFusion this is going to be implemented in. It says "to fix" but does not say which version.
Comment by External U.
12357 | January 25, 2016 08:24:49 AM GMT
+1....this is an improvement worth adding.
Vote by External U.
12362 | January 28, 2016 03:47:08 AM GMT