From: duerst Date: 2022-02-10T07:53:35+00:00 Subject: [ruby-core:107549] [Ruby master Feature#18576] Rename `ASCII-8BIT` encoding to `BINARY` Issue #18576 has been updated by duerst (Martin D��rst). Eregon (Benoit Daloze) wrote in #note-4: > The property that bytes < 128 are interpreted as US-ASCII is nothing special, every `Encoding#ascii_compatible?` behaves like that. > And almost all non-dummy Ruby encodings are `#ascii_compatible?`, the only two exceptions are UTF-16/32 (both LE/BE). > > Two things particularly confusing about the name ASCII-8BIT: > * It's completely unclear it might mean binary data or unknown encoding Well, binary data can be character data with unknown encoding (or with encoding not yet set), or it can be truly binary data (e.g. as in a .jpg file or .zip file,...). > * ISO-8859-* and many other encodings are 8-bit ascii-compatible encodings. Yet ASCII-8BIT which name seems to imply something close is nothing like that (the 8th bit is undefined, uninterpreted but valid). ASCII-8BIT is an 8-bit ascii-compatible encoding, isn't it? I think the idea of ASCII-8BIT goes back to the fact that in Ruby, many encodings can be used for source code, and as long as you only use ASCII in the code, it doesn't actually matter. That's to a large extent how Ruby 1.8 operated, and that was carried over into Ruby 1.9. Now that the default source encoding is UTF-8, we have an encoding pragma for source files in other encodings, and so on, the importance of "something where we know ASCII is ASCII, but we are not sure about the upper half of the byte values" may be quite a bit less important. ---------------------------------------- Feature #18576: Rename `ASCII-8BIT` encoding to `BINARY` https://bugs.ruby-lang.org/issues/18576#change-96461 * Author: byroot (Jean Boussier) * Status: Open * Priority: Normal ---------------------------------------- ### Context I'm now used to it, but something that confused me for years was errors such as: ```ruby >> "f��e" + "\xFF".b (irb):3:in `+': incompatible character encodings: UTF-8 and ASCII-8BIT (Encoding::CompatibilityError) ``` When you aren't that familiar with Ruby, it's really not evident that `ASCII-8BIT` basically means "no encoding" or "binary". And even when you know it, if you don't read carefully it's very easily confused with `US-ASCII`. The `Encoding::BINARY` alias is much more telling IMHO. ### Proposal Since `Encoding::ASCII_8BIT` has been aliased as `Encoding::BINARY` for years, I think renaming it to `BINARY` and then making asking `ASCII_8BIT` the alias would significantly improve usability without backward compatibility concerns. The only concern I could see would be the consistency with a handful of C API functions: - `rb_encoding *rb_ascii8bit_encoding(void)` - `int rb_ascii8bit_encindex(void)` - `VALUE rb_io_ascii8bit_binmode(VALUE io)` But that's for much more advanced users, so I don't think it's much of a concern. -- https://bugs.ruby-lang.org/ Unsubscribe: