-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] The field storing the number of items in a List or Dict should be named "length", not "size" #3511
Comments
+1, this makes sense to me. @JoeLoser wdyt? |
+1 to renaming the field names here for consistency (using var xs = List[String]()
xs.size = 10 # oops
# When we run the destructor for `xs` here, we'd try to free uninitialized memory Our team can do all this internally and fix up all the uses. |
Also, if we're renaming the word "size", it might also make sense to rename the Sized trait (that includes the (I'll open a different issue for this if desired.) |
We definitely had similar thoughts when we introduced the |
That said, given Mojo already invented the adjectives Intable and Stringable, maybe Lengthable would be fine. 🤷♀️ |
Let's use
+1. Or |
For discussing the |
Bug description
The field
List.size
should probably be renamed toList.length
, because:len()
function returns (it returns the # of elements in any collection)A similar reasoning applies to
Dict.size
. The expressionlen(my_dict)
obtains the number of elements, so we should probably be referring to the number of elements as the "length" of the dictionary.Also, the term "size" is more often used to refer to memory consumption, e.g. C++'s
sizeof
operator returns the number of bytes that an object consumes. It would be good to avoid this conflation.Steps to reproduce
N/A
System information
No response
The text was updated successfully, but these errors were encountered: