Copy link to clipboard
Copied
Hello, all,
Just curious: In ColdFusion, why does an array have a length, but a struct has a count? You can take an array and get
arrayLen(array)
, but you can't
structLen(struct)
, it has to be
structCount(struct)
.
No biggie.. just curious.
V/r,
^_^
Copy link to clipboard
Copied
I think that 'len' measures objects that grow, one distinct unit at a time, in one dimension. For example, lists, arrays and Java objects (len(object) = number of characters).
Whereas 'count' measures objects that grow in one dimension, one composite entity at a time. For example, structs (which comprise key-value pairs) and (query) records (which comprise data rows) and ListValues (which may comprise composite entities such as objects).
My guess is that the Coldfusion naming team came to the naming system intuitively. Then the system stayed with tradition.
Copy link to clipboard
Copied
Hi, BKBK,
Thanks for the input. That makes sense. I just didn't originally see the differences between something that grows unit vs composite. I just assumed that even something with a key/value pair, or something that can be composited, still has to have a base (which, I assume, would comprise length). But if there are multiple sub-components, then length wouldn't really be a precise measure.
Have a great New Year!
V/r,
^_^