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

String.{starts,ends}_with: use the label sub instead of prefix and suffix #10129

Closed
wants to merge 2 commits into from

Conversation

gasche
Copy link
Member

@gasche gasche commented Jan 7, 2021

This is a continuation of #9533 and #10105, a change proposal for String.{starts,ends}_with that had support from both @bschommer and @dbuenzli: use the ~sub label for both functions instead of ~prefix for one and ~suffix for the other.

I also changed ocamlmklib to use the standard library functions instead of a local reimplementation. It's interesting to see the impact of the change (the callsites do feel more verbose).

I must say that I find this change less convincing than #10127. To me the function calls do read slightly more nicely with the current label names than with the new ~sub labels.

@darioteixeira
Copy link

I agree that the label names prefix and suffix are way more readable and intuitive than sub.

@dbuenzli
Copy link
Contributor

dbuenzli commented Jan 8, 2021

If people prefer to keep it that way I don't mind but then one should think that there is still String.includes and a function to find the location of a substring in a larger one, say String.find_sub (feel free to find another name) that need to be added -- which in my opinion should be added now using the trivial n^2 algorithm with a warning that it does so. Labels for these will have to be found aswell and it's good to think about the whole package.

Here are two proposal, one with sub prefixes and one with per function specific labelling.

(* 1 *)
String.starts_with : sub:string -> string -> bool
String.includes : sub:string -> string -> bool
String.ends_with : sub:string -> string -> bool
String.find_sub : ?start:int -> sub:string -> string -> int option 
String.sub : string -> int -> int -> string

(* 2 *)
String.starts_with : prefix:string -> string -> bool 
String.includes : affix:string -> string -> bool
String.ends_with : suffix:string -> string -> bool
String.find_sub : ?start:int -> needle:string -> string -> int option 
String.sub : string -> int -> int -> string

@Octachron
Copy link
Member

It seems fine to me to revert to the generic label, sub (or substr), when there is no better specialized term:

Stringstarts_with : prefix:string -> string -> bool 
String.includes : sub:string -> string -> bool
String.ends_with : suffix:string -> string -> bool
String.find_sub : ?start:int -> sub:string -> string -> int option 
String.sub : string -> int -> int -> string

@xavierleroy
Copy link
Contributor

This use of sub was already proposed, discussed, and rejected in #9820. How many times do we need to propose, discuss, and reject this? We are running in circles.

@gasche
Copy link
Member Author

gasche commented Jan 9, 2021

Okay, okay. Don't shoot! I'll close this as I'm not convinced myself.

@gasche gasche closed this Jan 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants