From: Brian Candler Date: 2010-11-17T21:54:37+09:00 Subject: [ruby-core:33237] Re: not use system for default encoding NARUSE, Yui (Guest) wrote on 2010-11-15 11:07 > > Open all files in BINARY mode, except where explicitly asked: > > File.open("/etc/passwd","r:locale") > > I want to do this if people accept this, but I think they don't. I agree that the difference between "r" and "rb" already exists for this purpose. However I think there is an inconsistency between the strict rules for source code (you must specify the encoding), and lax rules for data (ruby will make a guess). To me, either of the following resolutions make sense. (1) For files opened as text ("r" or "w", as opposed to "rb" or "wb"), make the encoding default to US-ASCII. If users want something else they can open as "r:utf-8" or "r:locale" - the latter would guess the encoding from the environment as is done today. This forces people to make an explicit choice of behaviour, in the same way that the #encoding tag forces an explicit choice for source files. (2) Make the default encoding for both text files and source code be UTF-8. This covers a large proportion of use cases. If you are writing a program which reads a UTF-8 template then you're excused from declaring it, but if it reads (say) a GB2312 template then you must say so. IMO this is better than writing a program which reads your GB2312 template successfully on your machine, but crashes when run on someone else's machine. Behaviour of STDIN can be argued, but I'd go for consistency (fixed US-ASCII or UTF-8). Scripts which want to be environment-sensitive can add: STDIN.set_encoding "locale" Regards, Brian.