https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112017-12-26T08:12:33ZRuby Issue Tracking SystemRuby master - Feature #14240: warn four special variables: $; $, $/ $\https://bugs.ruby-lang.org/issues/14240?journal_id=689662017-12-26T08:12:33Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul><li><strong>Related to</strong> <i><a class="issue tracker-2 status-5 priority-4 priority-default closed" href="/issues/14138">Feature #14138</a>: Define English.rb aliases by default and eliminate the library</i> added</li></ul> Ruby master - Feature #14240: warn four special variables: $; $, $/ $\https://bugs.ruby-lang.org/issues/14240?journal_id=689672017-12-26T08:13:54Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul></ul><p>Agreed.</p>
<p>Besides that, we should warn for <code>$=</code> and <code>$.</code>, I think.</p>
<p>Matz.</p> Ruby master - Feature #14240: warn four special variables: $; $, $/ $\https://bugs.ruby-lang.org/issues/14240?journal_id=689822017-12-26T09:08:39Znormalperson (Eric Wong)normalperson@yhbt.net
<ul></ul><p>Shouldn't English posts be on ruby-core instead of ruby-dev?</p>
<p><a href="mailto:matz@ruby-lang.org" class="email">matz@ruby-lang.org</a> wrote:</p>
<blockquote>
<p>Agreed.</p>
<p>Besides that, we should warn for <code>$=</code> and <code>$.</code>, I think.</p>
</blockquote>
<p>I find $., $, and $/ useful for oneliners, at least. $.<br>
especially</p>
<p>I'm fine with awk-compatible English.rb names ($NR, $ORS, $RS)<br>
by default, but I do not like the long names in English.rb.</p>
<p>I like having some awk and Perl-isms in Ruby :></p> Ruby master - Feature #14240: warn four special variables: $; $, $/ $\https://bugs.ruby-lang.org/issues/14240?journal_id=689832017-12-26T09:08:40Znormalperson (Eric Wong)normalperson@yhbt.net
<ul></ul><p>Shouldn't English posts be on ruby-core instead of ruby-dev?</p>
<p><a href="mailto:matz@ruby-lang.org" class="email">matz@ruby-lang.org</a> wrote:</p>
<blockquote>
<p>Agreed.</p>
<p>Besides that, we should warn for <code>$=</code> and <code>$.</code>, I think.</p>
</blockquote>
<p>I find $., $, and $/ useful for oneliners, at least. $.<br>
especially</p>
<p>I'm fine with awk-compatible English.rb names ($NR, $ORS, $RS)<br>
by default, but I do not like the long names in English.rb.</p>
<p>I like having some awk and Perl-isms in Ruby :></p> Ruby master - Feature #14240: warn four special variables: $; $, $/ $\https://bugs.ruby-lang.org/issues/14240?journal_id=689862017-12-26T09:36:32Zakr (Akira Tanaka)akr@fsij.org
<ul></ul><p>2017-12-26 17:55 GMT+09:00 Eric Wong <a href="mailto:normalperson@yhbt.net" class="email">normalperson@yhbt.net</a>:</p>
<blockquote>
<p>Shouldn't English posts be on ruby-core instead of ruby-dev?</p>
</blockquote>
<p>Oops. Sorry.</p>
<blockquote>
<blockquote>
<p>Besides that, we should warn for <code>$=</code> and <code>$.</code>, I think.</p>
</blockquote>
<p>I find $., $, and $/ useful for oneliners, at least. $.<br>
especially</p>
</blockquote>
<h2>Hm. One idea to support oneliners is that warn the<br>
special variables when -e option is not given.</h2>
<p>Tanaka Akira</p> Ruby master - Feature #14240: warn four special variables: $; $, $/ $\https://bugs.ruby-lang.org/issues/14240?journal_id=689872017-12-26T09:36:33Zakr (Akira Tanaka)akr@fsij.org
<ul></ul><p>2017-12-26 17:55 GMT+09:00 Eric Wong <a href="mailto:normalperson@yhbt.net" class="email">normalperson@yhbt.net</a>:</p>
<blockquote>
<p>Shouldn't English posts be on ruby-core instead of ruby-dev?</p>
</blockquote>
<p>Oops. Sorry.</p>
<blockquote>
<blockquote>
<p>Besides that, we should warn for <code>$=</code> and <code>$.</code>, I think.</p>
</blockquote>
<p>I find $., $, and $/ useful for oneliners, at least. $.<br>
especially</p>
</blockquote>
<h2>Hm. One idea to support oneliners is that warn the<br>
special variables when -e option is not given.</h2>
<p>Tanaka Akira</p> Ruby master - Feature #14240: warn four special variables: $; $, $/ $\https://bugs.ruby-lang.org/issues/14240?journal_id=689932017-12-26T11:08:05Zshevegen (Robert A. Heiler)shevegen@gmail.com
<ul></ul><p>By the way, the awk-inspired names such as $NR, $ORS, $RS,<br>
also do not tell me anything. :-)</p>
<p>In fairness, I also have to admit that the english names also<br>
do not always tell me that much more. Depends on the name.</p>
<p><a href="http://ruby-doc.org/stdlib/libdoc/English/rdoc/English.html" class="external">http://ruby-doc.org/stdlib/libdoc/English/rdoc/English.html</a></p>
<pre><code>$\ = ' -- '
"waterbuffalo" =~ /buff/
print $', $$, "\n"
</code></pre>
<p>versus</p>
<pre><code>require "English"
$OUTPUT_FIELD_SEPARATOR = ' -- '
"waterbuffalo" =~ /buff/
print $POSTMATCH, $PID, "\n"
</code></pre>
<p>The second variant is a tiny bit more readable to me, but<br>
I also can not tell you what $OUTPUT_FIELD_SEPARATOR really<br>
means, without having to look at the docu. :)<br>
And $POSTMATCH hmm... I can try to make a guess, but I am<br>
not sure. I'd have to look at the docu. :D</p>
<p>Only $PID I can infer at once... to mean the PID of a<br>
process. I like that name. Please tell me that it does<br>
not mean anything else than PID ... :D</p>
<p>My brain takes more time for the first code variant and<br>
in general, I try to write only very simply code in ruby<br>
(which is also why I am absolutely bad at golfing and<br>
one-liners, but I understand if people want to be able<br>
to be super-succinct ... I remember the xmas tree in<br>
code golfing, that's more like art than code though).</p>
<p>What actually makes me not use "English" there is the require<br>
line - see also headius' suggestion elsewhere. I liked the recent<br>
change in regards to pp for similar reason, less to type. :)<br>
(Although I was using pp a LOT nonetheless, it is too useful to me<br>
to not make use of it. It just is less typing for me now<br>
past 2.5.x)</p>
<p>Anyway, I digress so I better stop now.</p> Ruby master - Feature #14240: warn four special variables: $; $, $/ $\https://bugs.ruby-lang.org/issues/14240?journal_id=690002017-12-26T20:08:45Znormalperson (Eric Wong)normalperson@yhbt.net
<ul></ul><p>Tanaka Akira <a href="mailto:akr@fsij.org" class="email">akr@fsij.org</a> wrote:</p>
<blockquote>
<blockquote>
<blockquote>
<p>Besides that, we should warn for <code>$=</code> and <code>$.</code>, I think.</p>
</blockquote>
</blockquote>
</blockquote>
<blockquote>
<p>2017-12-26 17:55 GMT+09:00 Eric Wong <a href="mailto:normalperson@yhbt.net" class="email">normalperson@yhbt.net</a>:</p>
<blockquote>
<p>I find $., $, and $/ useful for oneliners, at least. $.<br>
especially</p>
</blockquote>
<p>Hm. One idea to support oneliners is that warn the<br>
special variables when -e option is not given.</p>
</blockquote>
<p>Can we have the warnings forever? (No removal, ever).<br>
I would be happy with that :)</p>
<p>One important thing about oneliners is you won't find many<br>
examples of them in code search engines to judge popularity.</p> Ruby master - Feature #14240: warn four special variables: $; $, $/ $\https://bugs.ruby-lang.org/issues/14240?journal_id=690012017-12-26T20:08:46Znormalperson (Eric Wong)normalperson@yhbt.net
<ul></ul><p>Tanaka Akira <a href="mailto:akr@fsij.org" class="email">akr@fsij.org</a> wrote:</p>
<blockquote>
<blockquote>
<blockquote>
<p>Besides that, we should warn for <code>$=</code> and <code>$.</code>, I think.</p>
</blockquote>
</blockquote>
</blockquote>
<blockquote>
<p>2017-12-26 17:55 GMT+09:00 Eric Wong <a href="mailto:normalperson@yhbt.net" class="email">normalperson@yhbt.net</a>:</p>
<blockquote>
<p>I find $., $, and $/ useful for oneliners, at least. $.<br>
especially</p>
</blockquote>
<p>Hm. One idea to support oneliners is that warn the<br>
special variables when -e option is not given.</p>
</blockquote>
<p>Can we have the warnings forever? (No removal, ever).<br>
I would be happy with that :)</p>
<p>One important thing about oneliners is you won't find many<br>
examples of them in code search engines to judge popularity.</p> Ruby master - Feature #14240: warn four special variables: $; $, $/ $\https://bugs.ruby-lang.org/issues/14240?journal_id=690032017-12-26T21:15:11ZEregon (Benoit Daloze)
<ul></ul><p>I agree.<br>
These global variables can only be useful in tiny scripts,<br>
and even then I believe none of them are idiomatic Ruby code.</p>
<p>All of these are shortcuts saving at best a couple characters,<br>
but also threaten any usage of gets/print/split/join methods in larger programs.<br>
Giving an argument gets/print/split/join is much clearer and safer.</p>
<p>I was already thinking along the same lines 6 years ago about $, in <a href="https://bugs.ruby-lang.org/issues/5977" class="external">https://bugs.ruby-lang.org/issues/5977</a>,<br>
after being caught by a bug of some library setting $, and breaking the rest in very surprising ways iirc.</p> Ruby master - Feature #14240: warn four special variables: $; $, $/ $\https://bugs.ruby-lang.org/issues/14240?journal_id=690052017-12-26T21:15:23ZEregon (Benoit Daloze)
<ul><li><strong>Related to</strong> <i><a class="issue tracker-2 status-6 priority-4 priority-default closed" href="/issues/5977">Feature #5977</a>: Remove $, and avoid perlish global variables</i> added</li></ul> Ruby master - Feature #14240: warn four special variables: $; $, $/ $\https://bugs.ruby-lang.org/issues/14240?journal_id=697472018-01-24T08:22:30Zakr (Akira Tanaka)akr@fsij.org
<ul></ul><p>We discussed this issue at today's developper meeting.</p>
<p>We (including matz) agree produce warnings for 5 variables ($; $, $/ $\ $.) when it is written in<br>
ruby code except -e argument.</p>
<p>The warning is produced at compile time.<br>
So the warning is produced once for each occurrence (even if it occurs in a loop).</p>
<p>Note that $= already produces a warning since ruby 1.9.</p> Ruby master - Feature #14240: warn four special variables: $; $, $/ $\https://bugs.ruby-lang.org/issues/14240?journal_id=698212018-01-25T10:09:59Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p>I wonder that aliased variables also should be warned, <code>$-0</code>, <code>$-F</code>, and aliases in English.rb.</p>
<p>Currently, aliases of <code>$KCODE</code> are also warned.<br>
In other words, the feature of <code>$KCODE</code> is warned (and has no effect now).</p>
<p>Should we warn these four variable names, or their features?</p> Ruby master - Feature #14240: warn four special variables: $; $, $/ $\https://bugs.ruby-lang.org/issues/14240?journal_id=801252019-07-26T23:19:11Zjeremyevans0 (Jeremy Evans)merch-redmine@jeremyevans.net
<ul><li><strong>File</strong> <a href="/attachments/7919">warn-5-gvars.patch</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/7919/warn-5-gvars.patch">warn-5-gvars.patch</a> added</li></ul><p>Attached is a patch that adds a deprecation warning for the 5 global variables ($; $, $/ $\ $.), unless inside ruby <code>-e</code>. However, there is use of these variables inside Ruby that should be fixed if we plan to make this change. I've already seen the following issues:</p>
<pre><code>/path/ruby/lib/erb.rb:907: warning: global variable $. is deprecated
../.././ext/ripper/tools/preproc.rb: warning: global variable $/ is deprecated
/path/ruby/lib/rubygems/specification.rb:14: warning: global variable $. is deprecated
</code></pre>
<p>It is likely there are more issues than just these three.</p> Ruby master - Feature #14240: warn four special variables: $; $, $/ $\https://bugs.ruby-lang.org/issues/14240?journal_id=801272019-07-27T01:54:20Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p>It does not match to test <code>rb_warn</code> with <code>assert_warning</code>.<br>
Should be <code>rb_warn</code>+<code>assert_warn</code> or <code>rb_warning</code>+<code>assert_warning</code>.</p>
<p>And non-default <code>$;</code> and <code>$,</code> are warned now.<br>
Do you think these <strong>names</strong> should be warned too?</p> Ruby master - Feature #14240: warn four special variables: $; $, $/ $\https://bugs.ruby-lang.org/issues/14240?journal_id=802022019-07-29T19:03:34Zjeremyevans0 (Jeremy Evans)merch-redmine@jeremyevans.net
<ul><li><strong>File</strong> <a href="/attachments/7921">warn-5-gvars-v2.patch</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/7921/warn-5-gvars-v2.patch">warn-5-gvars-v2.patch</a> added</li></ul><p>nobu (Nobuyoshi Nakada) wrote:</p>
<blockquote>
<p>It does not match to test <code>rb_warn</code> with <code>assert_warning</code>.<br>
Should be <code>rb_warn</code>+<code>assert_warn</code> or <code>rb_warning</code>+<code>assert_warning</code>.</p>
</blockquote>
<p>Thanks. I switched to <code>assert_warn</code>, as I think deprecation warnings should be a regular warning, not a verbose warning. Verbose warnings are best used for warnings like unused variables. I only think verbose deprecation warnings should be used if there is a plan to follow it up with a non-verbose deprecation warning before removing it.</p>
<blockquote>
<p>And non-default <code>$;</code> and <code>$,</code> are warned now.<br>
Do you think these <strong>names</strong> should be warned too?</p>
</blockquote>
<p>I don't feel strongly about it. The <code>$;</code> and <code>$,</code> are currently run-time warnings based on the specific values passed when setting the values. akr's previous comment indicated that the warnings of the five variables should be at compile time.</p>
<p>One problem with the implementation in my previous patch is that it warns at the wrong location. Switching from <code>rb_warn</code> to <code>rb_compile_warn</code> fixes that issue.</p>
<p>Attached is an updated patch, as well as a few fixes where the global variables are currently used. Another file where they are also currently used is in:</p>
<pre><code>/path/ruby/lib/rubygems/stub_specification.rb:114: warning: global variable $. is deprecated
/path/ruby/lib/rubygems/stub_specification.rb:134: warning: global variable $. is deprecated
</code></pre>
<p>But a fix there should be filed upstream.</p>
<p>There are probably additional cases where these global variables are used internally. At the very least all tests that use them probably need modification to hide the warnings.</p> Ruby master - Feature #14240: warn four special variables: $; $, $/ $\https://bugs.ruby-lang.org/issues/14240?journal_id=802212019-07-30T01:52:50Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p>jeremyevans0 (Jeremy Evans) wrote:</p>
<blockquote>
<blockquote>
<p>And non-default <code>$;</code> and <code>$,</code> are warned now.<br>
Do you think these <strong>names</strong> should be warned too?</p>
</blockquote>
<p>I don't feel strongly about it. The <code>$;</code> and <code>$,</code> are currently run-time warnings based on the specific values passed when setting the values. akr's previous comment indicated that the warnings of the five variables should be at compile time.</p>
</blockquote>
<p>There are tons of that warnings, and it is not easy to suppress parser warning within the given file only.</p>
<blockquote>
<p>One problem with the implementation in my previous patch is that it warns at the wrong location. Switching from <code>rb_warn</code> to <code>rb_compile_warn</code> fixes that issue.</p>
</blockquote>
<p>It should be <code>rb_warn1</code> and <code>WARN_I(c)</code> for ripper.<br>
And a typo <code>f.line_no</code> in template/encdb.h.tmpl.</p> Ruby master - Feature #14240: warn four special variables: $; $, $/ $\https://bugs.ruby-lang.org/issues/14240?journal_id=810042019-08-26T00:58:22Zjeremyevans0 (Jeremy Evans)merch-redmine@jeremyevans.net
<ul><li><strong>File</strong> <a href="/attachments/8020">warn-5-gvars-v3.patch</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/8020/warn-5-gvars-v3.patch">warn-5-gvars-v3.patch</a> added</li></ul><p>nobu (Nobuyoshi Nakada) wrote:</p>
<blockquote>
<p>jeremyevans0 (Jeremy Evans) wrote:</p>
<blockquote>
<blockquote>
<p>And non-default <code>$;</code> and <code>$,</code> are warned now.<br>
Do you think these <strong>names</strong> should be warned too?</p>
</blockquote>
<p>I don't feel strongly about it. The <code>$;</code> and <code>$,</code> are currently run-time warnings based on the specific values passed when setting the values. akr's previous comment indicated that the warnings of the five variables should be at compile time.</p>
</blockquote>
<p>There are tons of that warnings, and it is not easy to suppress parser warning within the given file only.</p>
</blockquote>
<p>Agreed. I'm fine dropping these compile warnings if the run-time warnings are considered sufficient.</p>
<blockquote>
<blockquote>
<p>One problem with the implementation in my previous patch is that it warns at the wrong location. Switching from <code>rb_warn</code> to <code>rb_compile_warn</code> fixes that issue.</p>
</blockquote>
<p>It should be <code>rb_warn1</code> and <code>WARN_I(c)</code> for ripper.<br>
And a typo <code>f.line_no</code> in template/encdb.h.tmpl.</p>
</blockquote>
<p>Thanks for the review. Attached is an updated patch that fixes these issues.</p> Ruby master - Feature #14240: warn four special variables: $; $, $/ $\https://bugs.ruby-lang.org/issues/14240?journal_id=810092019-08-26T04:33:08Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p>jeremyevans0 (Jeremy Evans) wrote:</p>
<blockquote>
<p>nobu (Nobuyoshi Nakada) wrote:</p>
<blockquote>
<p>jeremyevans0 (Jeremy Evans) wrote:</p>
<blockquote>
<blockquote>
<p>And non-default <code>$;</code> and <code>$,</code> are warned now.<br>
Do you think these <strong>names</strong> should be warned too?</p>
</blockquote>
<p>I don't feel strongly about it. The <code>$;</code> and <code>$,</code> are currently run-time warnings based on the specific values passed when setting the values. akr's previous comment indicated that the warnings of the five variables should be at compile time.</p>
</blockquote>
<p>There are tons of that warnings, and it is not easy to suppress parser warning within the given file only.</p>
</blockquote>
<p>Agreed. I'm fine dropping these compile warnings if the run-time warnings are considered sufficient.</p>
</blockquote>
<p>Another point is that compile warnings are for the names.<br>
Use of aliases of them like English.rb will be still silent.</p>
<p>So, <a href="https://bugs.ruby-lang.org/issues/14240#note-13" class="external">this question</a>.</p>
<blockquote>
<p>Should we warn these four variable names, or their features?</p>
</blockquote> Ruby master - Feature #14240: warn four special variables: $; $, $/ $\https://bugs.ruby-lang.org/issues/14240?journal_id=833872019-12-25T02:24:00Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul><li><strong>Tracker</strong> changed from <i>Bug</i> to <i>Feature</i></li><li><strong>Backport</strong> deleted (<del><i>2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN</i></del>)</li></ul> Ruby master - Feature #14240: warn four special variables: $; $, $/ $\https://bugs.ruby-lang.org/issues/14240?journal_id=834102019-12-26T02:39:08Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul><li><strong>Assignee</strong> set to <i>jeremyevans0 (Jeremy Evans)</i></li><li><strong>Target version</strong> set to <i>36</i></li></ul><p>At the previous dev meeting, matz said that it should display a warning dynamically, i.e., not at the parsing time but when the variables are assigned. Variable aliases should be also warned. <a class="user active user-mention" href="https://bugs.ruby-lang.org/users/1604">@jeremyevans0 (Jeremy Evans)</a>, could you please progress?</p> Ruby master - Feature #14240: warn four special variables: $; $, $/ $\https://bugs.ruby-lang.org/issues/14240?journal_id=839762020-01-20T08:48:17Zjeremyevans (Jeremy Evans)code@jeremyevans.net
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li></ul><p>Applied in changeset <a class="changeset" title="Get rid of use of special variables Use `"\n"` and `IO#fileno` instead of `$/` and `$.` respecti..." href="https://bugs.ruby-lang.org/projects/ruby-master/repository/git/revisions/9f99760dafac6eaa53287470b8ff59b1be0bf6d6">git|9f99760dafac6eaa53287470b8ff59b1be0bf6d6</a>.</p>
<hr>
<p>Get rid of use of special variables</p>
<p>Use <code>"\n"</code> and <code>IO#fileno</code> instead of <code>$/</code> and <code>$.</code> respectively.<br>
[Feature <a class="issue tracker-2 status-5 priority-4 priority-default closed" title="Feature: warn four special variables: $; $, $/ $\ (Closed)" href="https://bugs.ruby-lang.org/issues/14240">#14240</a>]</p> Ruby master - Feature #14240: warn four special variables: $; $, $/ $\https://bugs.ruby-lang.org/issues/14240?journal_id=839772020-01-20T08:48:43Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Closed</i> to <i>Open</i></li></ul> Ruby master - Feature #14240: warn four special variables: $; $, $/ $\https://bugs.ruby-lang.org/issues/14240?journal_id=843542020-02-23T07:49:00Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li></ul><p>Applied in changeset <a class="changeset" title="Warn non-nil `$\` [Feature #14240]" href="https://bugs.ruby-lang.org/projects/ruby-master/repository/git/revisions/6298ec2875a6f1a1e75698c96ceac94362f20bcf">git|6298ec2875a6f1a1e75698c96ceac94362f20bcf</a>.</p>
<hr>
<p>Warn non-nil <code>$\</code> [Feature <a class="issue tracker-2 status-5 priority-4 priority-default closed" title="Feature: warn four special variables: $; $, $/ $\ (Closed)" href="https://bugs.ruby-lang.org/issues/14240">#14240</a>]</p> Ruby master - Feature #14240: warn four special variables: $; $, $/ $\https://bugs.ruby-lang.org/issues/14240?journal_id=877802020-09-29T03:37:27Zhsbt (Hiroshi SHIBATA)hsbt@ruby-lang.org
<ul><li><strong>Target version</strong> changed from <i>36</i> to <i>3.0</i></li></ul>