-
Notifications
You must be signed in to change notification settings - Fork 83
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
Use a more trait-oriented design #228
Comments
|
Short AnswerWe tried that and it proved fairly unwieldy and subpar. Long AnswerFirst and foremost: This is all still an experiment on nightly, so we remain entitled to rewrite everything. We will not exercise this entitlement frivolously, but some amount of tinkering is not frivolous (and, for instance, code using the type aliases has often remained stable in spite of massive internal changes). But it turns out the way that the core primitive types work
Please see rust-lang/rfcs#2581, which proposes generic integers as a way to deal with some of the existing problems. In essence, it is not actually clear that having something like But we still must provide methods that are, at minimum:
This means we can either use The principle "entities shall not be multiplied beyond necessity" (also known as Occam's razor, and often misquoted as something like "the simplest solution is often the best") undergirds much of logic, math, and even user experience design. This is also referred to as "Don't Repeat Yourself" in programming. The problem is that using macros still constitutes a certain amount of "repeating yourself", including in the form of documentation. And that is, at least, my major concern: The fact that two integers implement the same methods because they have the same macro applied to them is an implementation detail, one that is not guaranteed to be uniformly true. This came up with A trait forms a contract that the methods are indeed implemented on all entities that implement that trait, and at least notionally implement the "spec" of that trait. For a trait that is generic over u8, u16, u32, u64, and u128, this means you do not have to check that they still implement the same methods: you know they do. This means you do not have to concern yourself with details about those integers, you only interact with one entity: a "uint". While it is possible generic integers might change our approach significantly in multiple ways, they are not here at the moment. So, not using traits causes this library to add ~15 entities instead of, say, ~5. And it also, incidentally, when using it with |
We have coalesced consensus around a more direct application of using traits for the type-argument-specific functions on
std::simd::Simd
and finding other ways to resolve the too-many-imports problem, at least for now. While it is inconvenient to have to import such traits, "making imports more manageable" is something that should probably be addressed at a slightly higher design level than within this library's types (since it's of relevance to all of Rust).( Obviously, if people really want these traits in scope always, they can nominate them for the prelude as-is, though a solution that is less dependent on "being std", like inherent traits, would be nice. )
The text was updated successfully, but these errors were encountered: