-
Notifications
You must be signed in to change notification settings - Fork 23
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
deprecate API's with string/seq + start/last in favor of ones with openArray #381
Comments
Well but Nim allows for func find*(a: SkipTable, s, sub: string, start: Natural = 0, last = sub.high): int it's just that the stdlib was written before this feature existed (and I personally don't like the feature). It's a minor point, but RFCs should be correct. :-) Regarding the RFC itself, IMO we can simply write new code with openArray and leave the old code untouched, I don't enjoy deprecating stuff that works well. Yes really, it does work well -- you can use Nim as a better Basic thanks to strutils and openArray soon enough will bite back with the required ownership rules. |
yes, I've updated RFC and included that
except that old code tends to not use So we can still introduce the openArray overload for old APIs (with the special care described in nim-lang/Nim#18173 (comment) to ensure the openArray overload is selected when stard/end is unspecified), and whether to deprecate/soft-deprecate (with just a doc comment)/no-deprecate is secondary, at least new code can use old APIs using new style.
do you have an example? |
You cannot write |
proposal
openArray[T]
param, while ensuring that the openArray overload is picked when no start/end param is passed (see default last in strutils.find to -1 Nim#18173 (comment) for how to do that)start
semantics Nim#14284 (comment)benefits
example 1
which would subsume all others and also be strictly more flexible, and less error prone
refs nim-lang/Nim#18028 (comment)
example 2
(refs nim-lang/Nim#18173)
optional start/last parameters lead to bad API's where a valid value ends up hijacked with a different meaning, eg:
here, when user specifies
last = 0
, it ends up meaning last = sub.high, so there's no way for user to specify the edge condition oflast = 0
, which should be a valid choicechanging the signature to
func find*(a: SkipTable, s, sub: string, start: Natural = 0, last = -1): int
would be an improvement but is still unsatisfactory, as this could equally be interpreted as meaning s.high or empty slice of s (EDIT:func find*(a: SkipTable, s, sub: string, start: Natural = 0, last = sub.high): int
would be possible too)instead,
func find*(a: SkipTable, s: openArray[char], sub: string): int
would be self-documenting and not have any edge cases, the user then would call simplytoOpenArray(s, start, end)
if they want a sliceThe text was updated successfully, but these errors were encountered: