-
-
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
String.find
/String.rfind
USize
proposal
#216
Merged
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
- Feature Name: string_find_usize | ||
- Start Date: 2024-12-09 | ||
- RFC PR: (leave this empty) | ||
- Pony Issue: (leave this empty) | ||
|
||
# Summary | ||
|
||
Change the return type of `String.find` and `String.rfind` from `ISize` to `USize`, aligning its return type with `Array.find`. | ||
|
||
# Motivation | ||
|
||
The current return type of `String.find` and `String.rfind` is `ISize`, which stems from its historical behavior of returning `-1` when no match was found. However, these methods now return `error` for such cases. Returning `USize` makes more sense because indices are always non-negative, and it aligns with `Array.find`'s method signature. | ||
|
||
# Detailed design | ||
|
||
The method signature of [String.find](https://github.com/ponylang/ponyc/blob/736220a34364a864fe0fd1f091a85852ded84d23/packages/builtin/string.pony#L640) and [String.rfind](https://github.com/ponylang/ponyc/blob/736220a34364a864fe0fd1f091a85852ded84d23/packages/builtin/string.pony#L669) would change to return `USize` instead of `ISize`. | ||
|
||
Specifically, the method signatures would be changed from this: | ||
|
||
```pony | ||
fun find(s: String box, offset: ISize = 0, nth: USize = 0): ISize ? | ||
fun rfind(s: String box, offset: ISize = -1, nth: USize = 0): ISize ? | ||
``` | ||
|
||
to this: | ||
|
||
```pony | ||
fun find(s: String box, offset: ISize = 0, nth: USize = 0): USize ? | ||
fun rfind(s: String box, offset: ISize = -1, nth: USize = 0): USize ? | ||
``` | ||
|
||
# How We Teach This | ||
|
||
Through the standard library documentation and the associated release notes. | ||
|
||
# How We Test This | ||
|
||
Standard CI and the compiler should identify most areas that need to be addressed. Additionally, any documentation, code examples, and guides should be reviewed and updated to reflect the new behavior. | ||
SeanTAllen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# Drawbacks | ||
|
||
It's a breaking change as the method signature has to change. Existing code relying on `String.find` and `String.rfind` will need to be migrated. | ||
|
||
# Alternatives | ||
|
||
Keep the existing method signature to avoid breaking changes introduced by this proposal. | ||
|
||
# Unresolved questions | ||
|
||
None at this time. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Such a review should happen before this RFC is accepted as fixing anything that this breaks that isn't programmatically caught should be part of the acceptance criteria for merging the change to the return type.
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.
There's no usage in the tutorial that I can find.
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.
There's no usage in pony-patterns that I can find.
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.
The only usage I can find on the website is a reference to this RFC from the most recent LWIP.
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.
So what should I write here instead, @SeanTAllen?
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.
That a review has been done so the tutorial, paterns, and website and that there's no changes needed to reflect the new behavior.