From: "tenderlovemaking (Aaron Patterson)" Date: 2022-02-09T23:35:30+00:00 Subject: [ruby-core:107537] [Ruby master Feature#18576] Rename `ASCII-8BIT` encoding to `BINARY` Issue #18576 has been updated by tenderlovemaking (Aaron Patterson). jeremyevans0 (Jeremy Evans) wrote in #note-9: > I'm also in favor of renaming `ASCII-8BIT` to `BINARY`, but I don't have strong feelings about it. I'm strongly against breaking `String#encode` for binary strings. Ya, sorry, I should be more clear. I think concatenation shouldn't try to guess at the encoding. If the user calls "encode" then it seems fine. Eregon (Benoit Daloze) wrote in #note-8: > As an example, the encoding negotiation rules (e.g. for concatenation) in Ruby are all based around whether one side is `#ascii_only?` and if yes then just use the other side's encoding. Preventing to e.g. concat with a ASCII-only binary string would break lots of programs. > Anyway, I think that's a separate issue indeed. Yes, this is the issue I have. IME the code is already broken, it just hasn't had the right input to break it yet (where would the binary string come from other than an external location?). Regardless, I made a ticket here: https://bugs.ruby-lang.org/issues/18579 ���� ---------------------------------------- Feature #18576: Rename `ASCII-8BIT` encoding to `BINARY` https://bugs.ruby-lang.org/issues/18576#change-96448 * 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: