Skip to content
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

[Feature Request] Rename the Sized trait (perhaps to Countable) #3514

Open
1 task done
nmsmith opened this issue Sep 21, 2024 · 2 comments
Open
1 task done

[Feature Request] Rename the Sized trait (perhaps to Countable) #3514

nmsmith opened this issue Sep 21, 2024 · 2 comments
Labels
enhancement New feature or request mojo-repo Tag all issues with this label

Comments

@nmsmith
Copy link
Contributor

nmsmith commented Sep 21, 2024

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:

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

@martinvuyk
Copy link
Contributor

+1 on renaming, though I'd rather go for HasLength or HasLen than the others since it aligns more with the discussion in issue #2924

@nmsmith
Copy link
Contributor Author

nmsmith commented Sep 21, 2024

Hmm... what if the trait was itself named __len__? And we could have an __int__ trait etc. One for every dunder method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request mojo-repo Tag all issues with this label
Projects
None yet
Development

No branches or pull requests

2 participants