-
-
Notifications
You must be signed in to change notification settings - Fork 48
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
added range_redesign rfc #147
base: main
Are you sure you want to change the base?
Conversation
Markdown formatting seems a little off based on the highlighting that GitHub is doing |
Looking at your reference code, its more explicit about inclusive and exclusive but reverse is now implicit. The reverse API is non-obvious in that fashion to me. I think this should be addressed in the RFC. |
Can you include the important points of the API design in the RFC, along with a few usage examples? I know you linked a reference implementation, but it's good to have the API design in the RFC itself for posterity, since the reference implementation link may become invalid later. Also, seeing usage examples would make this easier to talk about. |
I've addressed all the points you raised and I think the document is ready for another round of review. |
|
||
* be able to generate all the possible ranges, increasing and decreasing, for all the data types, without incurring in overflow errors. | ||
* offer a unified, usable, coherent API with the possibility to specify inclusive or exclusive bounds. To achieve this, the definition of the bounds and the range should be independent. The Range class should offer helper methods to cover the most common cases without explicitely instancing the bounds. | ||
* never raise errors but instead return an empty list. This decision arises from the assumption that a majority of ranges are defined with bounds known at compile time while declaring ranges using runtime values is less common. The error handling in that case has to be done by calling the `is_invalid()` method. A version of the class with explicit errors can be considered. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"majority of ranges are defined with bounds know at compile time" isn't my experience. if the majority of ranges were defined with bounds at runtime, would that change the "never raise errors" idea?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, because the assumption is that ranges defined with hardcoded value don't need error handling. The range will be either always valid or always invalid. If this is not the most common scenario, raising an error would be more idiomatic than checking is_invalid
. The idea is to renounce an idiomatic interface to save the user a lot of unnecessary error handling.
It was mentioned on today's sync call that this implementation adds some allocation overhead that will significantly slow down use of Having To fix the performance issue, From a usability standpoint, it is suggested that we make sure the defaults for those type parameters are matching the current behaviour of Range for compatibility purposes. |
Another issue for me is that dynamically determining forward or backward would interfere with high performance code patterns. For example, writing a loop that was intentionally a forward loop but that might (dynamically) intentionally perform zero iterations (by setting the Much like @jemc says above for inclusive and exclusive, forward and backward could be encoded as primitive type parameters, allowing zero-cost reification. |
Removing from final comment period until the above comments are addressed. |
RFC for the range redesign. All the details are in text/0000_range_redesign.md