ryan
02/09/2022, 2:43 PMcfloop
: Reading the documentation in Adobe about index
and item
attributes for a list is quite vague as to how these attributes work together. When only using index
attribute (ie index="idx"
), the list element is assigned to the idx
variable within the loop. However, when using both index
and item
attributes (ie index="idx" item="itm"
), the behavior of the index
attribute changes by assigning the true index number of the item in the list and the item
attribute is assigned the element, instead.
Why does the behavior for the index
attribute have to change? Is it because of backward compatibility? If a developer wants to only grab the true index number in a list, then they are forced to extraneously include the item
attribute. Am I missing something?Rich Wild
02/09/2022, 2:53 PMwebsolete
02/09/2022, 2:59 PMwebsolete
02/09/2022, 3:01 PMryan
02/09/2022, 3:03 PMfinal
and have to check and rename all of the places within the application for this, and I understand the impact is not as great as it would be for changing a cfloop index that probably exists in every application out there, but this implementation becomes hampered and bound to previous versions and devs continue to use the attribute in backwards compatibility, even if the application is new development. It seems the best bet would be to allow backwards compatibility flag settings for these sort of backwards enhancements so that ACF coding can advance correctly. Example: If folks upgrade and have index used only, then they will see a number if they don't turn on backwards compatibility for cfloop. Moving forward, devs can better understand the true purpose instead of having to find out how things work because of poor documentation and hand-tied implementation in order to appease older versions. It leads to crazy implementations like this that make no sense.ryan
02/09/2022, 3:07 PMitem
and index
mutually inclusive in order to make that happen, which changes the behavior of index
attribute. It makes it confusing as it is not documented in wording, except when seeing it in their examples. Either way, even if it was documented, the behavior flip flops and honestly, it should not. It should be item
is for the element and index
is for the index number in the list or array, always.Matt Jones
02/09/2022, 3:08 PMAdam Cameron
If a developer wants to only grab the true index number in a list...If you just want the index, just use an indexed loop. It's what it's for.
<cfset letters = "a,b,c,d">
<cfloop index="i" from="1" to="#letters.listLen()#">
<cfoutput>#i#</cfoutput>
</cfloop>
Adam Cameron
<cfloop>
handles lists becomes largely irrelevant.ryan
02/09/2022, 6:06 PMindex
attribute to always be used for grabbing the index number rather than attempting to understand how index
works in certain cases that changes the behavior of how index
is used. Especially, when item
is only used for the element. Let's "KISS" and keep index
only used for the index number.Adam Cameron
<cfloop>
is a mess.ryan
02/09/2022, 6:11 PMAdam Cameron
index
when used by itself means "the _item_" has been that way at least since CF5.
There is no reason to break that - purely out of a sense of pedantry - to accommodate both index
and item
. The way that's been done is legit. I mean what else were they gonna call the thing with the number in it in that situation?Adam Cameron
ryan
02/09/2022, 6:16 PMindex
, I don't think that the dev would think that the item would be returned, but rather, the index number. Moreover, now it flip flops in behavior, which is even worse.Adam Cameron
<cfloop>
for the best part of a decade, and seldom did even back then, but still remembered it's index for lists, item for structs, but if one uses both, then it's uniform for both lists and structs.Adam Cameron
If a new dev...hahahaha. Like there's new CFML devs. Nice one.
ryan
02/09/2022, 6:19 PMAdam Cameron
Adam Cameron
Adam Cameron
ryan
02/09/2022, 6:21 PMAdam Cameron
Adam Cameron
ryan
02/09/2022, 6:24 PMAdam Cameron