Discussion:
If UTF-8 is the default, is there any point in '# encoding: UTF-8' magic comments?
(too old to reply)
John Carter
2021-05-04 02:44:42 UTC
Permalink
I got it into my head they were needed, but
https://ruby-doc.org/core-3.0.1/Encoding.html#class-Encoding-label-Script+encoding
says it's been the default since V2_0
--
John Carter
Phone : (64)(3) 358 6639
Tait Electronics
PO Box 1645 Christchurch
New Zealand
--
This Communication is Confidential. We only send and receive email on the
basis of the terms set out at www.taitradio.com/email_disclaimer
<http://www.taitradio.com/email_disclaimer>
İsmail Arılık
2021-05-04 07:02:12 UTC
Permalink
For Ruby, there isn't anymore. But for editors, there may be. Most editors
can find the right encoding I guess but some old editors may not. So it is
still conventional to add an encoding to source code files. Do I add? No.
Post by John Carter
I got it into my head they were needed, but
https://ruby-doc.org/core-3.0.1/Encoding.html#class-Encoding-label-Script+encoding
says it's been the default since V2_0
--
John Carter
Phone : (64)(3) 358 6639
Tait Electronics
PO Box 1645 Christchurch
New Zealand
------------------------------
This Communication is Confidential. We only send and receive email on the
basis of the terms set out at www.taitradio.com/email_disclaimer
------------------------------
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
--
https://ismailarilik.com
Lee Hambley
2021-05-04 08:48:24 UTC
Permalink
John,

Here you can find the "git blame" for Rubocop's style check that ensures
you don't have these comment any more. Maybe the Git comments will offer
some insight

Llinks:

- https://docs.rubocop.org/rubocop/cops_style.html#styleencoding
- https://rubystyle.guide/#utf-8
-
https://github.com/rubocop/rubocop/blame/master/lib/rubocop/cop/style/encoding.rb

Lee Hambley
http://lee.hambley.name/
+49 (0) 170 298 5667
Post by İsmail Arılık
For Ruby, there isn't anymore. But for editors, there may be. Most editors
can find the right encoding I guess but some old editors may not. So it is
still conventional to add an encoding to source code files. Do I add? No.
Post by John Carter
I got it into my head they were needed, but
https://ruby-doc.org/core-3.0.1/Encoding.html#class-Encoding-label-Script+encoding
says it's been the default since V2_0
--
John Carter
Phone : (64)(3) 358 6639
Tait Electronics
PO Box 1645 Christchurch
New Zealand
------------------------------
This Communication is Confidential. We only send and receive email on the
basis of the terms set out at www.taitradio.com/email_disclaimer
------------------------------
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
--
https://ismailarilik.com
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
John Carter
2021-05-04 23:20:10 UTC
Permalink
Thanks!

Sigh! I have just understood another source of my confusion....

- unless you specify the -E command line option,
- or explicitly set the encoding on every io open....
- you get whatever darn external encoding your user happens to set with
the LANG environment variable....
- so when you read (unless you've set an internal encoding which might
trigger a transcoding),
- the string is encoding in whatever the environment variable said.

Which can, (on some strange users' box), result in much sadness if you do a
regexp match.

Not exactly robust if you expect a largish herd of cats to be running your
scripts.

I guess I had the happy (but incorrect) expectation that the default
external encoding would be the same as the script encoding (aka the default
regexp encoding).

I think I understand it all now... I think.
Post by Lee Hambley
John,
Here you can find the "git blame" for Rubocop's style check that ensures
you don't have these comment any more. Maybe the Git comments will offer
some insight
- https://docs.rubocop.org/rubocop/cops_style.html#styleencoding
- https://rubystyle.guide/#utf-8
-
https://github.com/rubocop/rubocop/blame/master/lib/rubocop/cop/style/encoding.rb
Lee Hambley
http://lee.hambley.name/
+49 (0) 170 298 5667
Post by İsmail Arılık
For Ruby, there isn't anymore. But for editors, there may be. Most
editors can find the right encoding I guess but some old editors may not.
So it is still conventional to add an encoding to source code files. Do I
add? No.
Post by John Carter
I got it into my head they were needed, but
https://ruby-doc.org/core-3.0.1/Encoding.html#class-Encoding-label-Script+encoding
says it's been the default since V2_0
--
John Carter
Phone : (64)(3) 358 6639
Tait Electronics
PO Box 1645 Christchurch
New Zealand
------------------------------
This Communication is Confidential. We only send and receive email on the
basis of the terms set out at www.taitradio.com/email_disclaimer
------------------------------
?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
--
https://ismailarilik.com
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
--
John Carter
Phone : (64)(3) 358 6639
Tait Electronics
PO Box 1645 Christchurch
New Zealand
--
This Communication is Confidential. We only send and receive email on the
basis of the terms set out at www.taitradio.com/email_disclaimer
<http://www.taitradio.com/email_disclaimer>
romanch sharma
2021-05-05 09:01:09 UTC
Permalink
I uncommented it, but I have a same question now?

Sent from my iPhone
Post by John Carter

Thanks!
Sigh! I have just understood another source of my confusion....
unless you specify the -E command line option,
or explicitly set the encoding on every io open....
you get whatever darn external encoding your user happens to set with the LANG environment variable....
so when you read (unless you've set an internal encoding which might trigger a transcoding),
the string is encoding in whatever the environment variable said.
Which can, (on some strange users' box), result in much sadness if you do a regexp match.
Not exactly robust if you expect a largish herd of cats to be running your scripts.
I guess I had the happy (but incorrect) expectation that the default external encoding would be the same as the script encoding (aka the default regexp encoding).
I think I understand it all now... I think.
John,
Here you can find the "git blame" for Rubocop's style check that ensures you don't have these comment any more. Maybe the Git comments will offer some insight
- https://docs.rubocop.org/rubocop/cops_style.html#styleencoding
- https://rubystyle.guide/#utf-8
- https://github.com/rubocop/rubocop/blame/master/lib/rubocop/cop/style/encoding.rb
Lee Hambley
http://lee.hambley.name/
+49 (0) 170 298 5667
For Ruby, there isn't anymore. But for editors, there may be. Most editors can find the right encoding I guess but some old editors may not. So it is still conventional to add an encoding to source code files. Do I add? No.
I got it into my head they were needed, but https://ruby-doc.org/core-3.0.1/Encoding.html#class-Encoding-label-Script+encoding says it's been the default since V2_0
--
John Carter
Phone : (64)(3) 358 6639
Tait Electronics
PO Box 1645 Christchurch
New Zealand
This Communication is Confidential. We only send and receive email on the
basis of the terms set out at www.taitradio.com/email_disclaimer
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
--
https://ismailarilik.com
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
--
John Carter
Phone : (64)(3) 358 6639
Tait Electronics
PO Box 1645 Christchurch
New Zealand
This Communication is Confidential. We only send and receive email on the
basis of the terms set out at www.taitradio.com/email_disclaimer
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
Loading...