From: Martin Duerst Date: 2007-09-29T16:07:44+09:00 Subject: Re: String.force_encoding Hello David, Sorry for doing half of the work in Japanese. At 13:39 07/09/29, David Flanagan wrote: >Hi, > >Nobu has just checked in a String.force_encoding method, which alters the encoding of a string (without, apparently modifying the underlying bytes at all: that is, it does not transcode from Unicode to SJIS or anything; it just changes the interpretation of the underlying bytes.) > >In the changelog, Martin Duerst is credited with suggesting the name force_encoding. Could Martin or Nobu or Matz explain to non-Japanese speakers the thinking behind this name. The last I heard it was going to be called "encode". I can see that the name "encode" has hints of transcoding, and a user might think that it did more than it actually does. Yes, this is exactly why I strongly advised against it. >I don't want to re-open a discussion if this decision has already been firmly made. It's not completely firm yet, it's just that Nobu had some code to check in, and needed a name, and it's better to start with a long and strange name and make it shorter if that's necessary than the other way round. >I can live with force_encoding; it is not likely to be used often. But I do want to suggest that it is awkward in English and I think we can do better. My primary complaint is that "force" has connotations of "something you shouldn't do". Putting "force" in a method name seems to me to be an inelegant substitute for ending the name with ! > >The only parts of the ruby-dev thread I can understand were some of the other names considered. One I liked was short and sweet: "as". Yes, I think something like that is still under consideration for the easy/frequent cases (in particular, 'changing' the encoding from binary to something else). For that case, we definitely want something shorter and more convenient. That will further reduce the number of cases where you have to use force_encoding. Having something in Shift_JIS, for example, and having to say "no, that was actually EUC-JP" should really be pretty rare, I think. >But for longer names, I think that either "set_encoding" or "alter_encoding" sound better than "force_encoding" and don't imply transcoding in the way that "encode" does. > >Also, one more request: can we make force_encoding accept nil as a way to specify ASCII (aka binary) encoding? If we have an shorter method for moving from binary to something real, we might also have a shorter method for the reverse. In the Japanese thead, there was a suggestions of the names encode/decode, but I don't like these, as explained above. Also, for most practical purposes, US-ASCII and binary will probably stay pretty close together, but at a recent meeting, we discussed making clearer distinctions between US-ASCII (7-bit clean) and binary, to reduce the number of cases where an exception is produced because of encoding conflicts. Regards, Martin. #-#-# Martin J. Du"rst, Assoc. Professor, Aoyama Gakuin University #-#-# http://www.sw.it.aoyama.ac.jp mailto:duerst@it.aoyama.ac.jp