[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: utf



On Wed, Apr 04, 2018 at 07:07:01PM +0200, Nicolas George wrote:
> Find me a case where you need to access the n-th char of a string, with
> n completely out of the blue, and I will explain how somebody botched
> their design.

Does it count if we want the 1st char, then the 2nd char, then the 3rd
char, then the 4th char, and so on?  Or is that not blue enough?

How about the last char?  Or the last two chars?  Or all chars starting
just after the last slash or period?

How about performing a checksum like the
<https://en.wikipedia.org/wiki/Luhn_algorithm> on a user input string
which is supposed to be a 10-digit
<https://en.wikipedia.org/wiki/National_Provider_Identifier> ?

Might it be useful to check the length of an input string before
bothering to decompose it into individual digits and perform the
arithmetic?  And here, by "length", I mean "number of characters".
You can see how that might be a handy thing, right?

Length as in "number of bytes required to store it" is also an
important value, of course.

Character length is also useful when displaying strings on
CHARACTER-ORIENTED OUTPUT MEDIA.  Like terminals.  You know, those
things that Unix-like systems use all the time?  How else are you
going to space-pad the fields so that the output columns line up,
if you don't know how many extra spaces you need, because you don't
know the length of the string?

(It's frankly disturbing to me that when I talked about length being
relevant when printing strings, you immediately jumped to "pixels" and
"fonts".  This tells me that you no longer accept the terminal as your
lord and savior.  If you ever did.)

All of these things matter, and are real, and don't necessarily indicate
"botched design".


Reply to: