8 ms·
Code Page 437 Refuses to Die
- lubujackson 11y agoMy heart goes out to anyone that ever has to work with encoding issues. I feel like I know 5% of this stuff and there looms a vast mass of chaos like a Gordian knot whenever I need to dip my toes in it.
- Motomorgen 11y agoAgreed completely, I recently had to work with some EBCDIC output files from old mainframe systems. Packed string data in a fixed delimited file. Nail bitingly frustrating stuff.
- _JamesA_ 11y agoHaving built countless similar conversions, EBCDIC[1] to ASCII can be as simple as a lookup table and "packed string data" is just binary coded decimal [2] with a sign. What is a fixed delimited file? A 'mainframe' file is generally fixed length or delimited. [1]: https://en.wikipedia.org/wiki/EBCDIC https://en.wikipedia.org/wiki/EBCDIC [2]: https://en.wikipedia.org/wiki/Binary-coded_decimal https://en.wikipedia.org/wiki/Binary-coded_decimal
- JoBrad 11y agoI have used delimiters within a fixed-width file so that I can fit more data in a width field in a fixed-width file layout. This is usually when I have to work with a mainframe, and can't define the layout, of course.
- nothrabannosir 11y agoEvery programmer has to deal with encoding; it's a fact of life. A list of bytes without encoding is just that: a list of bytes. Handling bytes as text (I.e.: "I/O")? You are now working with encodings. And the funny thing is: it's not that complex.[edit: let me rephrase: it is, but it doesn't have to be. C family is a nightmare, Python et al are delightful]. Unless you don't know how it works---then it's the mystery Gordian knot, as you describe it. The irony is that encoding is a worry precisely for those who try and stay away from it. Don't shy away from encodings; embrace them. Then you will learn to love them. (Another irony: with UTF8 gaining more and more mind share, encoding issues actually become harder to find and debug: they don't show up, and when they do, fewer and fewer people know how to deal with them. Everyone switching to UTF8 just hides the bugs, until it doesn't.)
- yoklov 11y agoPython is delightful? Many of the only times i've had issues were in python.
- mixmastamyk 11y agoPython3 is delightful.
- masklinn 11y ago> let me rephrase: it is, but it doesn't have to be. C family is a nightmare, Python et al are delightful Unless you do multiplatform development, then the language has a hard time saving you (and Python definitely does not) > (Another irony: with UTF8 gaining more and more mind share, encoding issues actually become harder to find and debug: they don't show up, and when they do, fewer and fewer people know how to deal with them. Everyone switching to UTF8 just hides the bugs, until it doesn't.) That's not true at all. A ton of byte sequences (and 13 standalone bytes) are outright illegal in UTF8, there's a fair amount of error handling in a validating UTF8 decoder[0], whereas there usually isn't any invalid byte (let alone byte sequence) in 8-bit codepages or character sets. When you decode random bytes in Windows-1256 or ISO-8859-9[1] and re-encode them as UTF8, the UTF8 encoder isn't the one at fault for your garbage output, as far as I could see it got perfectly valid unicode data. People passing through unvalidated data (possibly assuming it's UTF8) isn't a problem with UTF8 either, by the way. [0] whether that's used in strict mode or in replacement mode is a different concern and not a blemish on UTF8 itself [1] which will always succeed, you can try it at home, just get a bunch of bytes from urandom and feed them to various decoders, chances are low that you'll generate anything the UTF8 decoder will accept, chances are also low that you'll generate anything an ISO-8859 character set will reject.
- bluejekyll 11y agoThis article is trying to describe how to work on Windows specifically. I don't think it's saying ignore encodings, though honestly why -everything- isn't just encoded utf-8 I don't know. It's sad that a "modern" OS that had a mostly ground up rewrite (NT) after utf-8 was invented, doesn't have better support for it. I get in memory storage being utf-16, and I'd even accept modern OSes storing files in utf-16, but utf-8 is so elegantly backwards compatible with ascii, it's brain dead not to fix -everything- to work with it. Perhaps this is the biggest difference between a closed OS like Windows and it's more open counterparts, if Windows were open then the community could have fixed this issue long ago.
- dkersten 11y agoSome years ago I had to work with text encoded with 3GPP TS 23.038 [1], which is a 7bit packed encoding with a few quirks. It wasn't particularly fun. [1] https://en.m.wikipedia.org/wiki/GSM_03.38 https://en.m.wikipedia.org/wiki/GSM_03.38
- jfim 11y agoThe telephony standards are all kinds of bizarre. It's a testament as to how well the specs are written that it actually works.
- dkersten 11y agoThe specs are incredibly dense and hard to read, but they are quite detailed. I found many of the protocols to be both incredibly clever and incredibly annoying at the same time.
- Can_Not 11y agoI've noticed that Excel seems to assert that CSVs are not in UTF8. I know the standard is actually ASCII, but nobody on the team seemed willing to understand why their smart quotes came out as "weird characters" (or even understand what smart quotes are). It came out correctly in LibreOffice.
- moogly 11y agoThis is why I always write a BOM in CSV files (yes, even though it's UTF-8 and it shouldn't have a BOM). Excel will actually respect it. The bigger problem is when Excel tries to be helpful and reformats the data upon opening the file. I can't remember the intricacies, but it used to behave differently whether you opened it from a local path or directly from a browser. I seem to recall using an "incorrect" MIME type helped with that.
- Symbiote 11y agoAdding a BOM to a CSV file then causes many libraries to add the BOM to the first column's heading name.
- TAForObvReasons 11y agoExcel predates Unicode by a few years. The first true Excel version on Mac was released in 1985. The first generally recognized use of Unicode dates back to 1988. Excel CSVs default to the system codepage when reading and writing, which makes some sense given that the files are plain text. You can actually control what codepage is used when importing data but you have to use the import option.
- electroly 11y agoIt's an option that just defaults to the system ANSI codepage. After clicking Data > From Text, in the "Text Import Wizard - Step 1 of 3" screen, change the "File origin" to "65001: Unicode (UTF-8)"
- alexbock 11y agoTrying to handle character encoding on Windows in multi-platform programs is a nightmare. In C++ you can almost always get away with treating C strings as UTF-8 for input/output and you only need special consideration for the encoding if you want to do language-based tasks like converting to lowercase or measuring the "display width" of a string. Not on Windows. Whether or not you define the magical UNICODE macro, Windows will fail to open UTF-8 encoded filenames using standard C library functions. You have to use non-standard wchar overloads or use the Windows API. That is to say, there is no standard-conformant internationalization-friendly way to open a file by name on Windows in C or C++. I really wish Microsoft would at least support UTF-8, even if they want to stick with UTF-16 internally. The section titled "How to do text on Windows" on http://utf8everywhere.org/#windows http://utf8everywhere.org/#windows covers the insanity in more detail.
- Ono-Sendai 11y agoIt's a bit annoying and lame but not really a huge deal. For example, you can just open an fstream like so: std::ofstream file(convertUTF8ToFStreamPath(pathname).c_str()); Where convertUTF8ToFStreamPath converts from UTF-8 to the Windows wide encoding (UTF-16?)
- alexbock 11y agoIt gets even more fun when you have no choice but to use a poorly maintained closed-source third-party library (par for the course on Windows). If the library authors didn't use this trick themselves you can get stuck in situations where you have no way to make the library open the file without resorting to the DOS 8.3 name. And if the user disabled 8.3 names system-wide... then the only consolation is that something even more important on the system will probably break first. A sad state of affairs in 2016.
- Ono-Sendai 11y agoThe third party library situation is indeed trickier. I've never found a library that I couldn't get to open Unicode paths eventually though. Sometimes you have to open a file handle yourself and pass it to the library. Edit: By the way the worst handling of Unicode paths on Windows I have found is by Ruby, which is still partially broken. (last time I checked)
- 0x0 11y agoThe most hilarious issue with -Dfile.encoding is that if it set to, for example, UTF-8, then it is literally impossible to open files with names encoded in, say, ISO-8859-1, which can happen on a Linux system where users use different LC_CTYPE. You can do a "dir.listFiles()" and iterate it, and find that some of the entries are impossible to open because there is no way to represent the ISO-8859-1 bytes that make up the filename in a String object, and therefore no way to give the correct file name to the java io classes for opening.
- userbinator 11y agoYou can do a "dir.listFiles()" and iterate it, and find that some of the entries are impossible to open because there is no way to represent the ISO-8859-1 bytes that make up the filename in a String object, and therefore no way to give the correct file name to the java io classes for opening. That gives more weight to the argument that character encodings should be entirely a "presentation-layer" concern, and anything below that should treat strings as opaque byte sequences. There should also be a way to bypass that "presentation layer" transformation upon input.
- 0x0 11y agoAbsolutely, there's quite a few gaffes in java (other languages have similar issues too): * char being 16bit and thus can't hold a modern unicode character * lots and lots of string and byte stream methods that have variants without explicit charset parameters, making it very easy to accidentally have a hidden dependency on the implicit default charset (aka -Dfile.encoding) * Using strings instead of byte[] for filename values * Having to deal with UnsupportedEncodingExceptions as checked exceptions whenever referencing the UTF8 encoding
- jfim 11y agoThe reason for char being 16 bits is that the JLS predates Unicode 2.0 (1996), which added 32 bit codepoints. At that time, UCS-2 was widely believed to be sufficient to represent anything "international."
- 11y ago
- userbinator 11y ago437 is well-known for its use of line-drawing and other artistic characters: https://en.wikipedia.org/wiki/File:Norton_Commander_5.51.png https://en.wikipedia.org/wiki/File:Norton_Commander_5.51.png https://en.wikipedia.org/wiki/ASCII_art#.22Block_ASCII.22_.2F_.22High_ASCII.22_style_ASCII_art_on_the_IBM_PC https://en.wikipedia.org/wiki/ASCII_art#.22Block_ASCII.22_.2...
- speeder 11y agoI am from Brazil, meaning that we needed here a custom code-page for our language characters (including the Ç mentioned in the article). It never worked quite right, since ancient DOS times there was several bugs with this. What surprises me, is that it STILL doesn't work right. I have a Windows set to english, keyboard to Brazillian, and had to set "locale" to Japanese to play some Japanese games that outright crash otherwise (they don't even render wrong, they just crash). I lost count of how many times programs instead of using Unicode when they could, tried to figure a codepage from my location (and end with Brazillian), language (english) or "locale"( Japanese), and do it all mixed up and wrong. Stuff I saw: Important installers (for example drivers and expensive software) that render the interface in japanese and EULA in portuguese but with US codepage. Japanese font + portuguese text (ending in utterly non-sense). English text + brazillian font... and many others. Still, to my is is merely an "annoyance", but a similar issue made my mother panic completely: My dad coded for my family business a software to do some mandatory tax stuff in Brazil if you do any business at all (a sort of tax report for every single transaction), he did it in PHP, for Linux, but running on Windows, so far so good... Then one day he had to fix a bug, and the only machine was WinXP... he fixed the bug, and suddenly the program started to dump lots of corrupted data to government servers (as you can imagine that is really bad). We went to see, and fors ome reason now it is sending codepage 437 formatted data, and we have no idea why, we can't find what changed, an we didn't even used a windows based editor (we used Geany on WinXP).
- Latty 11y agoRather than using Japanese locale all the time, you can try Locale Emulator (https://xupefei.github.io/Locale-Emulator/ https://xupefei.github.io/Locale-Emulator/), which allows you to run individual programs in a given locale.
- ferongr 11y agoFrom personal experience I can say that Locale Emulation doesn't reliable work for many games.
- bradbeattie 11y ago
- lazyjones 11y agoThings would probably be slightly better if Unicode wasn't so difficult to support properly. For example, good luck getting your UTF-8 text output to render correctly in a terminal window under all circumstances (try combining diacritics or funny letters like "𖥶" - can you copy/paste that using the mouse?), or in a text editor like vi, Emacs with terminal UI. Using UTF-8 typically means having to think long and hard about filtering input/data, normalization and stuff like http://www.unicode.org/reports/tr36/ http://www.unicode.org/reports/tr36/ . If you don't, you'll run into such issues eventually even if you think your code needs to handle only a few "western" languages.
- Freak_NL 11y agoA decade ago that would be a valid argument, and processing Unicode text still isn't trivial, but nowadays Unicode support (UTF-8 in particular) is so well embedded in all operating systems and programming languages that this is not the problem. And on most operating systems the problem simply doesn't exist for most people because Unicode is the default. The problem here is Microsoft clinging to legacy character encodings that have no place on a modern operating system as default for anything.
- lazyjones 11y ago> so well embedded in all operating systems and programming languages that this is not the problem. It's not the "enabling" of Unicode that's problematic, it's the features of more exotic Unicode codepoints that aren't correctly supported by many programs in all major operating systems, because they weren't designed with these features in mind. Tell me, can you copy/paste the "𖥶" character with the mouse after double-clicking it in your browser? It's a letter - http://unicode-table.com/en/16976/ http://unicode-table.com/en/16976/, so it should IMO be treated like a quoted word (correct me if I'm wrong). Safari on OS X selects either the quote and the letter or just the right quote depending on where exactly on the letter I double click. Safari/Webkit is relatively modern and well-maintained too. Unicode "supported"? Sure. Working well? Nope, just for a few common use cases.
- 11y ago
- phyzome 11y ago"Disclaimer: The file.encoding property is undocumented and not officially supported, and it has been reported to act inconsistently across Java versions and platforms." Oh Christ on a cracker. Why doesn't Oracle just default everything to UTF-8 in the next version of Java?
- chillydawg 11y agoToo late for that kind of change, really. 20 years of legacy systems are not going to enjoy that.
- colejohnson66 11y agoIf their legacy system doesn't support UTF-8, I doubt they'd update their system at all.
- chillydawg 11y agoThey probably want update the JVM for security purposes, though. There's plenty that will absolutely kill you in any public facing JVM from more than a few years back. The first release of 7 has at least two very bad denial of service attacks that allow a remote user to saturate as many CPUs on your server as they like, all they need to do is send magic http headers to your tomcat or whatever.
- colejohnson66 11y agoPeople say that about operating systems, yet you have businesses running Windows XP still simply because they don't want to update. Yes, there's ones that don't for compatibility, but there are some that don't upgrade simply because they don't want to.
- hapless 11y agoNotably this is a Windows problem. Sane platforms default to UTF-8 and output exactly what you would expect: €Σ
- michaeledwards 11y agoNow imagine you are debugging the console output after it went thru a web server, your browser, your local dev environment, your local console, and then pasted into your text editor.
- gcb0 11y agolol. Just failed to mount a sd card on my openwrt modem yesterday. the error was that the exfat partition was using that code page and my modem didn't have it.
- be5invis 11y agoHowever if you use WriteConsoleW, you can actually output both of the "€∑" in ANY code page. The NT console is a matrix of UTF-16 code points, and there is an API to write it. So the question becomes why Java (and many other platforms, like Python) did not use this mechanism. Notably Java's internal encoding of strings is UTF-16 either, this should be a problem.
- mark-r 11y agoOne of the great benefits of a console interface is that it's a lowest common denominator between different OS. That interface is based on a byte-level I/O model. Things like I/O redirection depend on it.
- be5invis 11y agoThey can implement an alternative driver to convert IO streams into API calls. And that's how libuv did.
- yuhong 11y agoOn 16-bit vs 32-bit Unicode/ISO 10646, I think it basically boils down to ISO 10646 wanting 32-bit but had no software folks on that committee, while the Unicode people was basically software folks but thought that 16-bit was enough.