|P is for Practical|
Re^2: Simplest Possible Way To Disable Unicodeby BrowserUk (Pope)
|on May 25, 2011 at 10:17 UTC||Need Help??|
a lot of guru coders not so happy beacause some of their pack, syswrite or wha telse spells have lost the shining of primeval eras..
That simply isn't what is going on here.
The docs for pack say:
Now let's see what happens when we assign oversized values to other unsigned types:
It silently wraps (or truncates) as is expected and normal.
Contrast that with what now (since the advent of unicode support) happens with unsigned char values:
A dumb warning that can only be disabled by disabling *all* pack warnings. Don't forget the 'W' and 'U' types above.
It is perfectly reasonable to expect silent truncation of oversized values with unsigned char types ('C'). Just as was the case with 'C' before the addition of unicode support; and just as is still the case with all other unsigned types. This is not an error, nor "sloppy coding"; it is the norm for these types.
Now constrast this spurious warning with the what happens when you use chr with oversized values:
Perl silently accepts this error, and erroneously constructs a multi-byte character.
And you only discover this error when you try to print it:
Which may not happen until dozens or hundreds of lines further on into the code; perhaps in another of your source files; perhaps in a module you didn't write or even know that you were (indirectly) using.
That is the very worst kind of error situation: action at a distance.
So, the problem is not (only) that this breaks "spells have lost the shining of primeval eras", but rather that the current, here today and tomorrow, state of play is that Perl issues spurious warnings for code that has always (and still should by the evidence of other similar current operations) be considered normal. Whilst silently not just ignoring a possible programmer error, but then making asinine assumptions and implementing the wrong thing, in a way that means such errors are horribly difficult to track down.
You cannot have it both ways. Fobbing this off with "documentation error" or "ancient sloppy coding practices" doesn't cut it.
Either *all* oversized assignments to unsigned types should silently truncate; or *all* should warn.
Except the latter is impossible because Unicode is such a crock.
One solution would be to add a wchr function that accepted multi-byte ordinals. That would make it very clear that the programmer is expecting to program with MBCSs and allow chr to catch coding errors at source.
Another, in my opinion preferable, solution would be to have it so that pre-unicode support semantic were followed everywhere, unless a use Unicode; statement was seen.
Ie. Instead of having to try (and fail) to disable these changes when you don't want them with use bytes;, when you want Unicode semantics, you ask for them. Seem logical?
Unfortunately, it is too late for that.
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.