https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17097754782015-07-22T21:13:49ZRuby Issue Tracking SystemRuby master - Feature #11390: Allow symbols starting with numbershttps://bugs.ruby-lang.org/issues/11390?journal_id=535092015-07-22T21:13:49Z0x0dea (D.E. Akers)0x0dea+redmine@gmail.com
<ul></ul><p>Permitting such syntax would needlessly complicate the parser for virtually no gain, and potentially break existing code that uses a numerical literal as the alternative of a non-padded ternary expression (<code>foo?1:2</code>). Just use <code>:'1twothree'</code>.</p> Ruby master - Feature #11390: Allow symbols starting with numbershttps://bugs.ruby-lang.org/issues/11390?journal_id=535282015-07-23T17:14:38Zv0dro (Sameer Deshmukh)sameer.deshmukh93@gmail.com
<ul></ul><p>But it goes against the principle of least surprise that ruby follows throughout the language. It's counter-intuitive and IMO from a layman ruby programmer's point of view the solution you propose does not confirm to the elegance of the syntax.</p> Ruby master - Feature #11390: Allow symbols starting with numbershttps://bugs.ruby-lang.org/issues/11390?journal_id=536142015-07-30T09:57:34Zduerst (Martin Dürst)duerst@it.aoyama.ac.jp
<ul><li><strong>Assignee</strong> set to <i>matz (Yukihiro Matsumoto)</i></li></ul><p>Sameer Deshmukh wrote:</p>
<blockquote>
<p>But it goes against the principle of least surprise that ruby follows throughout the language. It's counter-intuitive and IMO from a layman ruby programmer's point of view the solution you propose does not confirm to the elegance of the syntax.</p>
</blockquote>
<p>It's virtually impossible to make any language, even Ruby, unsurprising in all cases for all people. I agree with D.E. Akers that being able to write "foo?1:2" (as compared to that resulting in a syntax error, and forcing people to write "foo?1: 2" or so) is more important overall than to be able to write :1twothree.</p>
<p>I have assigned this issue to Matz so that he can reject it.</p> Ruby master - Feature #11390: Allow symbols starting with numbershttps://bugs.ruby-lang.org/issues/11390?journal_id=536582015-08-03T17:07:14Zshevegen (Robert A. Heiler)shevegen@gmail.com
<ul></ul><p>I have no particular pro or con on the suggestion itself, but I<br>
did want to comment on one part:</p>
<blockquote>
<p>But it goes against the principle of least surprise that<br>
ruby follows throughout the language.</p>
</blockquote>
<p>As far as I can tell, there is not really a general "principle of least<br>
surprise" - that one was coined by Dave, if I remember correctly, the<br>
Pickaxe author that also helped popularize Ruby.</p>
<p>While matz has had his story to share about the complexity of C++, and<br>
the use of orthogonal functionality, the principle of least surprise is<br>
primarily about how matz designed ruby, not as a "general principle of<br>
least surprise" applicable to everyone and everywhere all the time (because<br>
people have different opinions, different backgrounds, different expectations<br>
and so forth, so what may be surprising to some people, may be quite<br>
logical to others).</p>
<p>A good example is:</p>
<p>if File.exists? '/tmp/foo.txt'</p>
<p>versus</p>
<p>if File.exist? '/tmp/foo.txt'</p>
<p>Matz allowed the first alias at one point, because in written english<br>
this one is correct "if the file exists, do something". But this is<br>
not how one should ask the question in the Ruby way, one should ask:</p>
<p>"object, do you exist?</p>
<p>And then the second variant suddenly becomes the more consistent /<br>
logical one.</p>
<p>So the principle of least surprise is not a general one applicable<br>
all the time, in all situations. It will be specific to the example<br>
at hand.</p>
<p>Perhaps it should be called more an overall strive towards simplicity,<br>
elegance and consistency rather than complexity, but people will<br>
still disagree on where more complexity may be required and when<br>
it may not be. Someone has to decide on the features after all.</p>
<p>C++ gained new functionality too since 2010.</p>
<p><a href="http://www.codeproject.com/Articles/570638/Ten-Cplusplus-Features-Every-Cplusplus-Developer" class="external">http://www.codeproject.com/Articles/570638/Ten-Cplusplus-Features-Every-Cplusplus-Developer</a></p>
<blockquote>
<p>It's counter-intuitive and IMO from a layman ruby programmer's<br>
point of view the solution you propose does not confirm to the<br>
elegance of the syntax.</p>
</blockquote>
<p>Ruby does not always have elegant syntax. I found global variables<br>
not really elegant, for instance. I think Ruby is, in many ways,<br>
a cleaned-up, OOP-centric "sister" language to the old perl family,<br>
with features added to it that were found to be useful, and<br>
consistent - e. g. the usage of blocks. They give you additional<br>
flexibility when you require it.</p>
<p>There are other syntax elements such as -> rather than lambda.</p>
<p>Now I don't use lambdas much at all myself, but I always found<br>
the usage of -> really strange in my own code. It just does not<br>
seem to "fit" stylistically with the rest of the code that I<br>
write, so I opted to not use -> in my libraries.</p>
<p>My favourite interview from matz is still this one here, I think<br>
it is still applicable even 12 years lateron:</p>
<p><a href="http://www.artima.com/intv/rubyP.html" class="external">http://www.artima.com/intv/rubyP.html</a></p>
<p>Variables that start with numbers are often a bit strange, just<br>
see this:</p>
<p>$123456789123 = 42</p>
<p>foo.rb:1: Can't set variable $-1097262461</p>
<p>Peculiar error message - I was not using the variable -1097262461. :)</p>
<p>PS: By the way, other people actually propose to do away with the<br>
distinction between Symbols and Strings altogether, so your suggestion<br>
to allow more flexibility in Symbols, could be changed altogether<br>
when we say that we should not use Symbols at all. ;)</p>
<p>I am also neutral on the Symbol versus String debate, and it's not<br>
one to have for Ruby 2.x era, perhaps Ruby 3.x era, but these guys<br>
also have a point - see the strange HashWithIndifferentAccess,<br>
which arises only because one has to separate between symbols and<br>
string as keys. It might simplify the language if one could always<br>
use strings or string-like objects (and the conversion be handled<br>
internally - I understand that this is not easy to change since<br>
Symbols are internal anyway, but I myself used to wonder whether<br>
I should use a symbol as key or a string as key in the past).</p> Ruby master - Feature #11390: Allow symbols starting with numbershttps://bugs.ruby-lang.org/issues/11390?journal_id=537822015-08-14T05:23:27Zgwelch (Grant Welch)gwelch925@gmail.com
<ul></ul><p>Sameer Deshmukh wrote:</p>
<blockquote>
<p>Currently it is not possible to create a symbol that looks like <code>:1twothree</code>.</p>
<p>Converting to a string and then symbolizing causes hash lookup problems and proves counter-intuitive. What's also surprising is that ruby allows symbols to start with special characters but not numbers.</p>
</blockquote>
<p>The non-quoted symbol format follows the same naming rules as variables (local, instance, class, global), methods, and constants (Modules, Classes, and Constants). Otherwise, you'll have to resort to the quoted string format.</p>
<p>Also, notice that:</p>
<pre><code>:foo == :'foo' # => true
</code></pre>
<p>Variable and Method Naming Rules: <a href="http://ruby-doc.org/core-2.2.2/doc/syntax/assignment_rdoc.html" class="external">http://ruby-doc.org/core-2.2.2/doc/syntax/assignment_rdoc.html</a></p>