Notice also that JavaScript itself is choosing size for types like Set or Map: size is a more generic (and mathematical) name that suits more needs better, but nitpicking and pedantry aside, length is perfectly a understandable (and I keep using it for Sets and Maps until I remember that's wrong).
Thanks for chiming in Daniel! Now I can see why Lodash chose
size
instead of length 😅Notice also that JavaScript itself is choosing
size
for types likeSet
orMap
:size
is a more generic (and mathematical) name that suits more needs better, but nitpicking and pedantry aside,length
is perfectly a understandable (and I keep using it forSet
s andMap
s until I remember that's wrong).Clarifying meaning isn't pedantic.
Using
size
andcapacity
instead oflength
on data structures with dynamic lengths was done before JS.There was probably a discussion somewhere, where they argued for/against both.
Python implements
len()
as a function with the magic method__len__
precisely to have one consistent way of retrieving an intuitive "length".