[ruby-core:116269] [Ruby master Feature#18576] Rename `ASCII-8BIT` encoding to `BINARY`

Issue #18576 has been updated by zverok (Victor Shepelev).
Such incompatibility is not acceptable.
In all honesty, a selective application of this dogma doesn’t always look justified. For better or worse, we break compatibility constantly. One of the recent telling examples was the removal of `File.exists?` (an alias of `.exist?`), which, while "deprecated a long time ago," actually * broke a lot of gems/other software (because even with the "typically we have bare words as predicates" rule, it was more natural for people to write `exists?`, so while it was available, a _lot_ of code was using it); * improved absolutely nothing in Ruby’s friendliness and learnability save for "removed a reason to ask for `String#starts_with?` and similar methods" (while, say, Rails continues to prefer third-person verbs in its core extensions, like `String#starts_with?` or `Range#overlaps?`) OTOH, renaming the unfortunately named encoding: * makes Ruby friendlier (as a mentor, I saw a _lot_ of people confused with `ASCII-8BIT`), * breaks not a lot of code: while fixing gems wouldn't fix _all_ of its usages, the (minuscule) amount of gems to fix gives a good estimation of how frequently this might be a problem, * breaks code that mostly written in the "unexpected" way, so rethinking it might be a good idea anyway. ---------------------------------------- Feature #18576: Rename `ASCII-8BIT` encoding to `BINARY` https://bugs.ruby-lang.org/issues/18576#change-106291 * Author: byroot (Jean Boussier) * Status: Open * Priority: Normal * Target version: 3.4 ---------------------------------------- ### 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/
participants (1)
-
zverok (Victor Shepelev)