https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112015-04-29T12:38:45ZRuby Issue Tracking SystemRuby master - Feature #11105: ES6-like hash literalshttps://bugs.ruby-lang.org/issues/11105?journal_id=522712015-04-29T12:38:45Zhsbt (Hiroshi SHIBATA)hsbt@ruby-lang.org
<ul></ul><p>Hi Martin.</p>
<p>I fixed this issue. it is caused by latest version of redmine.<br>
Please try to report again.</p>
<p>Thanks.</p>
<p>On Wed, Apr 29, 2015 at 2:02 PM, "Martin J. Dürst"<br>
<a href="mailto:duerst@it.aoyama.ac.jp" class="email">duerst@it.aoyama.ac.jp</a> wrote:</p>
<blockquote>
<p>I tried to reply to Shugo on bugs.ruby-lang.org. However, I got the<br>
following validation message:</p>
<p>"% Done is not included in the list"</p>
<p>I do not know why I would have to indicate "% Done" on a feature that we<br>
only just started discussing. I also don't know where/how I would be<br>
indicating this (I could easily set the percentage to 0 if I knew where to<br>
do that).</p>
<p>Regards, Martin.</p>
</blockquote>
<p>--<br>
SHIBATA Hiroshi <a href="mailto:shibata.hiroshi@gmail.com" class="email">shibata.hiroshi@gmail.com</a><br>
<a href="http://www.hsbt.org/" class="external">http://www.hsbt.org/</a></p> Ruby master - Feature #11105: ES6-like hash literalshttps://bugs.ruby-lang.org/issues/11105?journal_id=522772015-04-29T13:06:44Zshugo (Shugo Maeda)
<ul></ul><p>2015-04-29 10:19 GMT+09:00 Matthew Kerwin <a href="mailto:matthew@kerwin.net.au" class="email">matthew@kerwin.net.au</a>:</p>
<blockquote>
<p>Shugo Maeda wrote:</p>
<blockquote>
<p>Why not support ECMAScript6-like hash literals?</p>
</blockquote>
<p>Does it make code easier to read, or just easier to write? Personally I find<br>
it a bit confusing/obfuscated.</p>
</blockquote>
<p>The proposed syntax contributes to readability because it reduces redundancy and<br>
tells us that a key has the same name as the corresponding variable.</p>
<p>For example, it is obvious that only name has a different name from<br>
the corresponding variable in the following code:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="n">h</span> <span class="o">=</span> <span class="p">{</span>
<span class="ss">name: </span><span class="n">username</span><span class="p">,</span>
<span class="n">password</span><span class="p">,</span>
<span class="n">e_mail</span>
<span class="p">}</span>
</code></pre> Ruby master - Feature #11105: ES6-like hash literalshttps://bugs.ruby-lang.org/issues/11105?journal_id=522792015-04-29T17:38:41Zbruka (besnik ruka)bruka@targetedvictory.com
<ul></ul><p>It does look easier to read but feels like it would be harder to write and<br>
debug.</p>
<p>What if you're typing in a hurry, or doing a lot of copy/paste and somehow<br>
you accidentally omit a key? Currently the interpreter would raise a syntax<br>
error immediately, but with this you would get cryptic logic bugs where the<br>
size of the hash is correct, but the key you want is missing.</p>
<p>Also this pretty much means you can't have an expression as the value i.e.</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="n">h</span> <span class="o">=</span> <span class="p">{</span>
<span class="nb">name</span><span class="p">.</span><span class="nf">upcase</span><span class="p">,</span>
<span class="n">email</span>
<span class="p">}</span>
</code></pre>
<p>Another issue might be that this basically ties your hash to the naming of<br>
your variables:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="k">def</span> <span class="nf">sanitize_name</span><span class="p">(</span><span class="nb">name</span><span class="p">,</span> <span class="n">email</span><span class="p">)</span>
<span class="nb">name</span> <span class="o">=</span> <span class="nb">name</span><span class="p">.</span><span class="nf">upcase</span>
<span class="k">return</span> <span class="p">{</span> <span class="nb">name</span><span class="p">,</span> <span class="n">email</span> <span class="p">}</span>
<span class="k">end</span>
</code></pre>
<p>Which looks fine, but if later on i decide to go back and rename my local<br>
variable, I'd have to go find everywhere i've used that hash and make sure<br>
the key is changed properly. Not sure I want that kind of coupling.</p> Ruby master - Feature #11105: ES6-like hash literalshttps://bugs.ruby-lang.org/issues/11105?journal_id=522802015-04-29T21:32:30Zrosenfeld (Rodrigo Rosenfeld Rosas)rr.rosas@gmail.com
<ul></ul><p>I use that a lot with CoffeeScript and would love to be able to do the same with Ruby. +1</p> Ruby master - Feature #11105: ES6-like hash literalshttps://bugs.ruby-lang.org/issues/11105?journal_id=522812015-04-30T01:36:37Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul></ul><p>-1.</p>
<p><code>{x, y}</code> is a conventional notation of a mathematical set.<br>
When I read it, I expect it to be equivalent to <code>{ x => true, y => true }</code>.</p>
<p>--<br>
Yusuke Endoh <a href="mailto:mame@ruby-lang.org" class="email">mame@ruby-lang.org</a></p> Ruby master - Feature #11105: ES6-like hash literalshttps://bugs.ruby-lang.org/issues/11105?journal_id=522822015-04-30T02:36:41Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul></ul><p>Question:</p>
<p>What if we have variables with same name and different prefixes? e.g.</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="n">a</span> <span class="o">=</span> <span class="mi">1</span>
<span class="vi">@a</span> <span class="o">=</span> <span class="mi">2</span>
<span class="vg">$a</span> <span class="o">=</span> <span class="mi">3</span>
</code></pre>
<p>Matz.</p> Ruby master - Feature #11105: ES6-like hash literalshttps://bugs.ruby-lang.org/issues/11105?journal_id=522832015-04-30T02:48:38Zabracu (Alfredo Bravo Cuero)yo@alfredobravocuero.co
<ul></ul><p>Hola matz</p>
<p>Alfredo Bravo Cuero (<a class="user active user-mention" href="https://bugs.ruby-lang.org/users/9408">@abracu (Alfredo Bravo Cuero)</a>)<br>
Open Source culture advocate and Ruby on Rails Developer<br>
| Skype: <a href="mailto:yo@alfredobravocuero.co" class="email">yo@alfredobravocuero.co</a> | Cel +573192837240</p>
<p>Enviado desde mi iPad</p> Ruby master - Feature #11105: ES6-like hash literalshttps://bugs.ruby-lang.org/issues/11105?journal_id=522842015-04-30T02:50:41Zshugo (Shugo Maeda)
<ul></ul><p>Yukihiro Matsumoto wrote:</p>
<blockquote>
<p>What if we have variables with same name and different prefixes? e.g.</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="n">a</span> <span class="o">=</span> <span class="mi">1</span>
<span class="vi">@a</span> <span class="o">=</span> <span class="mi">2</span>
<span class="vg">$a</span> <span class="o">=</span> <span class="mi">3</span>
</code></pre>
</blockquote>
<p>The last one is used with warnings:</p>
<pre><code>lexington:ruby$ cat x.rb
a = 1
@a = 2
$a = 3
p({a, @a, $a})
lexington:ruby$ ./ruby x.rb
x.rb:4: warning: duplicated key at line 4 ignored: :a
x.rb:4: warning: duplicated key at line 4 ignored: :a
{:a=>3}
</code></pre> Ruby master - Feature #11105: ES6-like hash literalshttps://bugs.ruby-lang.org/issues/11105?journal_id=522852015-04-30T02:55:31Zshugo (Shugo Maeda)
<ul></ul><p>Yusuke Endoh wrote:</p>
<blockquote>
<p><code>{x, y}</code> is a conventional notation of a mathematical set.<br>
When I read it, I expect it to be equivalent to <code>{ x => true, y => true }</code>.</p>
</blockquote>
<p><code>{x, y}</code> looks like a set of variable bindings, so it's reasonable that each key is a variable name and each value is its value.</p> Ruby master - Feature #11105: ES6-like hash literalshttps://bugs.ruby-lang.org/issues/11105?journal_id=522912015-04-30T13:38:51Zagarie (Carlos Agarie)carlos.agarie@gmail.com
<ul></ul><p>As Yusuke Endoh said, I'd expect this notation to create a Set, not a Hash...</p>
<hr>
<p>Carlos Agarie<br>
+55 11 97320-3878 | @carlos_agarie</p> Ruby master - Feature #11105: ES6-like hash literalshttps://bugs.ruby-lang.org/issues/11105?journal_id=523252015-05-05T12:36:33Zrosenfeld (Rodrigo Rosenfeld Rosas)rr.rosas@gmail.com
<ul></ul><p>Yukihiro Matsumoto wrote:</p>
<blockquote>
<p>Question:</p>
<p>What if we have variables with same name and different prefixes? e.g.</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="n">a</span> <span class="o">=</span> <span class="mi">1</span>
<span class="vi">@a</span> <span class="o">=</span> <span class="mi">2</span>
<span class="vg">$a</span> <span class="o">=</span> <span class="mi">3</span>
</code></pre>
</blockquote>
<p>CoffeeScript would compile to this:</p>
<pre><code>@a=1; a=2; {@a, a} => {a: this.a, a: a}
</code></pre>
<p>If the same happens in Ruby, this is what I get in IRB:</p>
<pre><code>> {a: 1, a: 2}
(irb):2: warning: duplicated key at line 2 ignored: :a
=> {:a=>2}
</code></pre>
<p>Sounds good to me.</p> Ruby master - Feature #11105: ES6-like hash literalshttps://bugs.ruby-lang.org/issues/11105?journal_id=523512015-05-08T07:02:52Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p>Shugo Maeda wrote:</p>
<blockquote>
<pre><code>lexington:ruby$ cat x.rb
a = 1
@a = 2
$a = 3
p({a, @a, $a})
lexington:ruby$ ./ruby x.rb
x.rb:4: warning: duplicated key at line 4 ignored: :a
x.rb:4: warning: duplicated key at line 4 ignored: :a
{:a=>3}
</code></pre>
</blockquote>
<p>Why they make the same symbol?<br>
<code>a</code>, <code>@a</code> and <code>$a</code> are irrelevant, separate variables.<br>
I'd expect <code>{:a=>1, :@a=>2, :$a=>3}</code> without any warnings.</p> Ruby master - Feature #11105: ES6-like hash literalshttps://bugs.ruby-lang.org/issues/11105?journal_id=524472015-05-14T09:15:56Zshugo (Shugo Maeda)
<ul></ul><p>Nobuyoshi Nakada wrote:</p>
<blockquote>
<blockquote>
<p>lexington:ruby$ ./ruby x.rb<br>
x.rb:4: warning: duplicated key at line 4 ignored: :a<br>
x.rb:4: warning: duplicated key at line 4 ignored: :a<br>
{:a=>3}</p>
<pre><code></code></pre>
</blockquote>
<p>Why they make the same symbol?<br>
<code>a</code>, <code>@a</code> and <code>$a</code> are irrelevant, separate variables.<br>
I'd expect <code>{:a=>1, :@a=>2, :$a=>3}</code> without any warnings.</p>
</blockquote>
<p>Because I don't come up with any use case of such ugly key names.<br>
I believe code like {a, <a class="user active user-mention" href="https://bugs.ruby-lang.org/users/52980">@A (A A)</a>} should not be used in real world applications.</p> Ruby master - Feature #11105: ES6-like hash literalshttps://bugs.ruby-lang.org/issues/11105?journal_id=524482015-05-14T09:30:22Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Rejected</i></li></ul><p>I am not positive about this syntax mostly because it appears to be set syntax, or old style hash in 1.8.<br>
Once ES6 syntax become more popular, there will be chance for this change in the future.</p>
<p>Matz.</p> Ruby master - Feature #11105: ES6-like hash literalshttps://bugs.ruby-lang.org/issues/11105?journal_id=625882017-01-20T00:49:42Zznz (Kazuhiro NISHIYAMA)
<ul><li><strong>Related to</strong> <i><a class="issue tracker-2 status-6 priority-4 priority-default closed" href="/issues/13137">Feature #13137</a>: Hash Shorthand</i> added</li></ul> Ruby master - Feature #11105: ES6-like hash literalshttps://bugs.ruby-lang.org/issues/11105?journal_id=625892017-01-20T00:50:53Zznz (Kazuhiro NISHIYAMA)
<ul><li><strong>Related to</strong> <i><a class="issue tracker-2 status-6 priority-4 priority-default closed" href="/issues/11104">Feature #11104</a>: ES6-like hash literals</i> added</li></ul> Ruby master - Feature #11105: ES6-like hash literalshttps://bugs.ruby-lang.org/issues/11105?journal_id=654272017-06-19T22:32:22Ztleish (Tony Fenleish)
<ul></ul><p>+1</p>
<p>While it might be odd or new for some, using this in ES6 has been very nice. I am often wishing this was supported in Ruby. The cognitive load is so much nicer and less redundant.</p>
<p>I wish it could be reconsidered.</p> Ruby master - Feature #11105: ES6-like hash literalshttps://bugs.ruby-lang.org/issues/11105?journal_id=662682017-08-24T03:55:01Zknu (Akinori MUSHA)knu@ruby-lang.org
<ul></ul><p>This syntax is now widely known and popular in the JavaScript/ES world. It is frequently used in everyday code and we've grown used to it.</p> Ruby master - Feature #11105: ES6-like hash literalshttps://bugs.ruby-lang.org/issues/11105?journal_id=662702017-08-24T22:26:24Zkernigh (George Koehler)xkernigh@netscape.net
<ul></ul><p>This ES6 syntax for hash literals looks strange to me. I have never seen it before today, but I have not written JavaScript for a few years, and I am not using Ruby for web development.</p>
<p>Two things puzzle me:</p>
<ol>
<li>What is the key in <code>{@a}</code>? I want <code>:@a</code> as the key, others want <code>:a</code>. I don't expect Ruby to change <code>a</code> into <code>@a</code>. For example, <code>object.instance_variable_get :a</code> raises NameError, but <code>object.instance_variable_get :@a</code> works.</li>
<li>Should <code>{print}</code> call the method <code>print</code> if there's no local variable? That's what <code>{print: print}</code> would do.</li>
</ol> Ruby master - Feature #11105: ES6-like hash literalshttps://bugs.ruby-lang.org/issues/11105?journal_id=662762017-08-25T01:55:55Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p>It makes many conflicts with the current syntax.<br>
I don't think it is easy to resolve.</p> Ruby master - Feature #11105: ES6-like hash literalshttps://bugs.ruby-lang.org/issues/11105?journal_id=708112018-03-06T13:50:55Zshugo (Shugo Maeda)
<ul><li><strong>Related to</strong> <i><a class="issue tracker-2 status-5 priority-4 priority-default closed" href="/issues/14579">Feature #14579</a>: Hash value omission</i> added</li></ul> Ruby master - Feature #11105: ES6-like hash literalshttps://bugs.ruby-lang.org/issues/11105?journal_id=745152018-10-19T14:04:46Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Has duplicate</strong> <i><a class="issue tracker-2 status-6 priority-4 priority-default closed" href="/issues/15236">Feature #15236</a>: add support for hash shorthand</i> added</li></ul> Ruby master - Feature #11105: ES6-like hash literalshttps://bugs.ruby-lang.org/issues/11105?journal_id=805792019-08-11T00:16:51Zznz (Kazuhiro NISHIYAMA)
<ul><li><strong>Related to</strong> <i><a class="issue tracker-2 status-6 priority-4 priority-default closed" href="/issues/16095">Feature #16095</a>: 2 Features: remove (simplify) 'new' keyword and Property Shorthand</i> added</li></ul>