From: "byroot (Jean Boussier)" Date: 2022-02-17T15:34:51+00:00 Subject: [ruby-core:107640] [Ruby master Feature#18576] Rename `ASCII-8BIT` encoding to `BINARY` Issue #18576 has been updated by byroot (Jean Boussier). Ok, so I went over all 71 matches after filtering vendored code: https://gist.github.com/casperisfine/5a26c7b85f7d15c4acd63d62d67eafbb I opened 31 pull requests, all where trivial changes `str.encoding.name == ""` -> `str.encoding == Encoding::BINARY` with the notable exception of `vcr` because it store the encoding names in files. The vast majority of the matches are abandoned gems with no update since 2013 or older ( I still opened PRs when I could). Some are even just old versions of `rack` republished under another name. The few high profiles gems impacted are: - Nokogiri: patch sent - VCR: patch sent - mongo: patch sent That being said, it's impossible to measure how much proprietary code may use the same pattern. ---------------------------------------- Feature #18576: Rename `ASCII-8BIT` encoding to `BINARY` https://bugs.ruby-lang.org/issues/18576#change-96552 * 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: