You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rust already has a Sized trait, and it denotes a type whose memory consumption is known at compile-time. Rust devs would be quite confused when encountering "Sized" in Mojo.
Unfortunately there isn't really an English adjective that means "has a length", or more accurately "its number of elements can be queried". The most accurate English adjective is probably Countable, so that would be my top recommendation. (len() probably should have been called count(), but that ship sailed decades ago.)
Here's a list of plausible trait names:
Countable
HasLength
Lengthable
Len (this is probably the least surprising trait name)
More generally though, I'm wondering if Mojo actually needs a trait specifically for the __len__ dunder method. A function that takes a parameter T bounded by Sized seems pretty useless, because you can't actually do anything useful with those instances of T. Perhaps the trait hierarchy should be structured a bit differently? Should the minimal trait be something like Container or Iterable?
The answer is probably "we need it because that's what len() needs". Which is a bit circular, but I suppose we might have to live with that.
Any other details?
No response
The text was updated successfully, but these errors were encountered:
Review Mojo's priorities
What is your request?
Mojo currently has a trait named Sized. This denotes a type that has the
__len__
dunder method. I am proposing that we rename this trait.What is your motivation for this change?
The name "Sized" seems problematic for a few reasons:
sizeof
operator in C++.Unfortunately there isn't really an English adjective that means "has a length", or more accurately "its number of elements can be queried". The most accurate English adjective is probably
Countable
, so that would be my top recommendation. (len()
probably should have been calledcount()
, but that ship sailed decades ago.)Here's a list of plausible trait names:
Countable
HasLength
Lengthable
Len
(this is probably the least surprising trait name)More generally though, I'm wondering if Mojo actually needs a trait specifically for the
__len__
dunder method. A function that takes a parameterT
bounded bySized
seems pretty useless, because you can't actually do anything useful with those instances ofT
. Perhaps the trait hierarchy should be structured a bit differently? Should the minimal trait be something likeContainer
orIterable
?The answer is probably "we need it because that's what
len()
needs". Which is a bit circular, but I suppose we might have to live with that.Any other details?
No response
The text was updated successfully, but these errors were encountered: