-
Notifications
You must be signed in to change notification settings - Fork 66
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
Option Compare Ordinal (and OrdinalIgnoreCase?) #193
Comments
This doesn't directly answer your question, but I would dearly love an As an example, (and if my memory serves me correctly), the _repository.CreateQuery<GalleryEntry>()
.Where(e => e.VsixID == model.ProductId)
.AsEnumerable()
.FirstOrDefault(); (the For the
Effectively the values are the two legacy values and one for each of the To answer your question (assuming I'm interpreting it correctly), no we should not automatically provide a string comparer to things like What about some sort of comparer instance that the compiler replaces with the current setting. For example: Dim x = New Dictionary(Of String, Integer)(Microsoft.VisualBasic.CurrentStringComparer) The compiler could translate the use of that comparer instance into the appropriate |
I'm withdrawing this proposal in favor of #218. |
#218 only handles the expression tree rewriting. What about case-insensitive |
Two problems:
String.Equals
; specifically, VB treats empty strings and null strings as equal. If neither string is null, and ifOption Compare Text
is in effect, VB usesCurrentCultureIgnoreCase
. Otherwise (Option Compare Binary
), VB usesOrdinal
string comparison.Due to this special rule in VB that treats null and empty as equivalent, VB string comparison calls out to a runtime method (
Operators.CompareString
). This method appears in the expression trees we produce from LINQ and every LINQ provider ever blows up on it. This adds an extra burden to supporting VB in LINQ providers and authors very often have no idea what to do with it.Beyond that, I think it's weird to educate new programmers that empty and null strings are equal as in most of the .NET ecosystem that will not be the case.
a) Abandon such lovely built-in constructs like the
Select Case
statement.b)
ToUpper()
all of your strings before comparing them.c) Turn
Option Compare Text
.(a) is just terrible. VB is a beautifully expressive language and that expressiveness shouldn't need to be jettisoned in order to do a very common thing--case insensitive string comparison. This could be felt even more if we add other string related constructs like #140 or an
In
operator.(b) Is against .NET performance best-practice because of the extra string allocations. Potentially massive waste if the strings are large.
(c) Still uses VB special rules about null and empty strings and also uses the current UI culture rather than the invariant culture or a case-insensitive ordinal (binary) comparison.
If we extend
Option Compare
to support more options and we implement #117 we could restore some of VB's productiveness with strings, extend the utility of built-in language constructs, and not force users into wasteful habits.Question
If there a way to get the same implicit-argument behavior we do today with
Option Compare
such that APIs which take a ComparisonType or an EqualityComparer(Of String) automatically take the correct inputs based on the current setting (e.g. VBsDistinct
operator given a sequence of strings or theDictionary(Of String, TValue)
constructor)? Seems unlikely since every method that takes such an argument has an overload that doesn't take it. Could that be done performantly? Should we do that? Maybe an analyzer that forces users to be consistent and explicit would be better.The text was updated successfully, but these errors were encountered: