[RFC FS-1033] Discussion: Extend String module #187
Replies: 94 comments 34 replies
-
Just might two cents on the string split - 9/10 times I just want to split on a single char, without worrying about |
Beta Was this translation helpful? Give feedback.
-
Yeah maybe another function like |
Beta Was this translation helpful? Give feedback.
-
Regarding the issue with overloads for things like invariants - we already have this issue with things like |
Beta Was this translation helpful? Give feedback.
-
I've made a provisional branch from which to start a discussion on this... https://github.com/isaacabraham/visualfsharp/tree/string-module-extensions I've just done the first ten methods or so. A few points: -
Feedback welcome. |
Beta Was this translation helpful? Give feedback.
-
My first thoughts: I'm not a big fan of having the I like the handling of null strings as being basically equivalent to empty strings (e.g., |
Beta Was this translation helpful? Give feedback.
-
Ooops, good point. So perhaps just |
Beta Was this translation helpful? Give feedback.
-
Thinking about it, I actually think that the default of most of these in the BCL is |
Beta Was this translation helpful? Give feedback.
-
I'd prefer Edit: I've changed my mind and now prefer |
Beta Was this translation helpful? Give feedback.
-
So I see two possibilities:
|
Beta Was this translation helpful? Give feedback.
-
Having started to do a few more of these, I'm not especially fond of the null checks at the start of each of the functions. IMHO people should be pushing these strings into |
Beta Was this translation helpful? Give feedback.
-
As in the RFC, the default should do the BCL default. An explicit Invariant function should be added, as with the BCL. Finally a way to provide a custom comparison should also be added, again as with the BCL. Consistency with the BCL is key. Also any surprising behaviour, such as accepting null etc, should be removed. You shouldn't have to think "does C# string functions accept null or is it F#?" - I strongly advocate that we keep the F# String functions and the String class as close as possible. |
Beta Was this translation helpful? Give feedback.
-
I thought we (F#) settled on In general I agree with @dsyme here: fsharp/fslang-suggestions#112 (comment) |
Beta Was this translation helpful? Give feedback.
-
@saul I agree broadly with you. The only thing I wouldn't want to do is restrict the F# module to not take advantage of things like option where possible. So On the other hand, we also have consistency with the rest of F# to consider (for example, For someone coming from .NET already, they'll much prefer consistency with BCL methods. Someone who is an "F#-first" user might not. Discuss. |
Beta Was this translation helpful? Give feedback.
-
@saul I'm also concerned at the possible of massive amount of pseudo-overloads for these functions e.g. let indexOf // indexOf, default culture (whatever we decide upon)
let indexOfComparison // indexOf, custom culture etc. etc. etc. An alternative is that (just like |
Beta Was this translation helpful? Give feedback.
-
As @gusty pointed out in this comment, if the String module functions default to CurrentCulture then they won't be referentially transparent, as they will have an invisible dependency on an "outside" parameter (the system's current culture) which could change at any time. I've also found https://stackoverflow.com/a/20085219/2314532 which strongly suggests (to me) that we want to default to Ordinal, not InvariantCulture, for the string comparison. This also fits with the Best Practices for Using Strings in the .NET Framework guidelines, which state in part:
So for both consistency and safety reasons, I recommend using |
Beta Was this translation helpful? Give feedback.
-
Regarding the In order to get the desired functionality in a consistent way we should name that function Note that this is slightly related to the naming discussion on fsharp/fslang-suggestions#102 when considering names like |
Beta Was this translation helpful? Give feedback.
-
This is not quite the case: the |
Beta Was this translation helpful? Give feedback.
-
I know, and I find it a bit unfortunate. But it's already there, and we'll have to live with it. |
Beta Was this translation helpful? Give feedback.
-
In order to (maybe) give this issue a bit of a boost to get something reasonable in, I've created a single file which contains a version of the branch I created but as a standalone file. This can easily be added to your existing F# projects through Paket's github dependency feature:
Perhaps we can test this out and see if it "feels right" in this low-risk manner, and then makes changes to it as needed with PRs etc. to that file. Once we feel it's good to go, we can port it here with confidence that it'll be in a good position to move into the real Core library. |
Beta Was this translation helpful? Give feedback.
-
I've tried today incorporating this into an existing application of ours, replacing any instance methods with ones from the module. Some thoughts:
Just my two cents. |
Beta Was this translation helpful? Give feedback.
-
Just came across this today from StructOptions discussion. I have a library which I generate from script pointed at various BCL classes with static functions and or non side effect methods, and just produces many inline functions with argument reordering. Most of the signatures match except for the ones you've hand tuned for better default behaviors as my script I only give heuristics for argument order. Thought I might mention as an alternative, or as independent confirmation. But I cover a lot more than just string methods this way. http://jay.tuley.name/FSharp.Interop.Compose/reference/index.html |
Beta Was this translation helpful? Give feedback.
-
For context, dotnet/designs#207 suggests that having CurrentCulture by default for string APIs is a pit of failure. F# must not just copy .NET APIs, rather we should have Ordinal as default as well. |
Beta Was this translation helpful? Give feedback.
-
Hey, how about a canonical |
Beta Was this translation helpful? Give feedback.
-
apisof.net no longer lists usage statistics - Does anyone have a copy of the data? |
Beta Was this translation helpful? Give feedback.
-
Should add to drawbacks:
|
Beta Was this translation helpful? Give feedback.
-
How about instead of "changing" the default for Compare (and the likes), we instead implement |
Beta Was this translation helpful? Give feedback.
-
Also, what is the
|
Beta Was this translation helpful? Give feedback.
-
Should String.split and friends really return an array, or an immutable sequence? Returning an array would be good because it would more directly wrap the BCL (and avoid copying to an immutable type), but returning an immutable seq would be more idiomatic F#. |
Beta Was this translation helpful? Give feedback.
-
A reminder to everyone that the only thing "approved" so far is really based on this comment: fsharp/fslang-suggestions#112 (comment) Where I said:
Is the RFC up-to-date with the proposed list? Some comments on that list
Anyway, I added some content to the RFC here: #622, and I'd recommend we go back and clarify the methodology. |
Beta Was this translation helpful? Give feedback.
-
OK, well, I've been over the proposed list and to be honest I don't think we should proceed with this RFC. I was skeptical about it at the start and I don't find the current RFC compelling. Looking through the list of functions:
To be honest I just don't think there's a sound methodology here that substantially improves on the status quo. The .NET APIs are not bad, and they are canonical and documented. There is a very strong argument that List, Seq, Array bring excellent uniformity and sanity to immutable data programming (pretending Array is immutable). But these additions just aren't in that category. |
Beta Was this translation helpful? Give feedback.
-
Discussion for RFC FS-1033, suggestion at: fsharp/fslang-suggestions#112
RFC at: https://github.com/fsharp/fslang-design/blob/master/RFCs/FS-1033-extend-string-module.md
Beta Was this translation helpful? Give feedback.
All reactions