EXPECTED is in the eye of the [non-expecting type of ]expectant

by Michael S. Kaplan, published on 2007/10/30 10:31 -04:00, original URI: http://blogs.msdn.com/b/michkap/archive/2007/10/30/5774614.aspx

Lori asked:

I’m seeing results with VB’s StrComp function that I would not expect.  For example:

    StrComp("Lee-P", "Leema", vbTextCompare)

Returns 1, but

    StrComp("Lee-P", "Leema", vbBinaryCompare)

Returns -1 as I would expect.

Why does this first return a 1 rather than -1? 

PS: I see the same behavior in VB6 as well as VB.NET.

This may look familiar to regular readers, especially people who have seen Punctuation... now, isn't that SPECIAL [weights]? or the more recent A&P of Sort Keys, part 9 (aka Not always transitive, but punctual and punctuating)....

Yes, it is good old word sorting -- VB does it too! :-)

(The vbBinaryCompare constant is what it sounds like, and the vbTextCompare one is the default user locale)

Expected really is in the eye of the beholder, ain't it?

Now, we are sitting on the opposite side of an implementation that was first written over 15 years ago, though I wonder whether in retrospect it would be more intuitive to make SORT_STRINGSORT the default behavior and only do word sorting when it was explicitly asked for. There would be fewer complaints about cases that are not as intuitive since they aren't as straightforward as the co-op vs. coop case, but at the cost of a lot of less than ideal results.

I have gone back and forth on this one a whole bunch -- trying to make it easier on confused developers, trying to make it better for ordinary users who just wouldn't be expecting punctuation symbols to be weighed so heavily.

Kind of a time waster, but every time this issue comes up I walk through the alternatives again....

Which is better? If it were up to you, what would you have suggested as the default a decade and a half ago?


This post brought to you by - (U+002d, a.k.a. HYPHEN-MINUS)

# John Bates on 30 Oct 2007 10:31 PM:

I've been burnt by not-so-obvious defaults and other implicit API behaviours ... the memories still painful.

I would have chosen an option for both, something like vbWordCompare and vbStringCompare.

And I might have chosen 'Exact' (with Word and String variants) instead of 'Binary' -- I've seen people confused over this one.

# Michael S. Kaplan on 31 Oct 2007 8:11 AM:

Ah, no way to combine the binary with word/string sorting -- but most people find binary much less confusing than the new word first introduced in .NET -- ordinal.

referenced by

2010/06/10 WORD SORT...Why'd it have to be...WORD SORT?

go to newer or older post, or back to index or month or day