It does look easier to read but feels like it would be harder to write and
debug.

What if you're typing in a hurry, or doing a lot of copy/paste and somehow
you accidentally omit a key? Currently the interpreter would raise a syntax
error immediately, but with this you would get cryptic logic bugs where the
size of the hash is correct, but the key you want is missing.

Also this pretty much means you can't have an expression as the value i.e.
  h = {
    name.upcase,
    email
  }

Another issue might be that this basically ties your hash to the naming of
your variables:

  def sanitize_name(name, email)
    name = name.upcase
    return { name, email }
  end

Which looks fine, but if later on i decide to go back and rename my local
variable, I'd have to go find everywhere i've used that hash and make sure
the key is changed properly. Not sure I want that kind of coupling.

None of these are deal breakers, but things to consider.

On Wed, Apr 29, 2015 at 9:06 AM, <shugo / ruby-lang.org> wrote:

> Issue #11105 has been updated by Shugo Maeda.
>
>
> 2015-04-29 10:19 GMT+09:00 Matthew Kerwin <matthew / kerwin.net.au>:
> > Shugo Maeda wrote:
> >> Why not support ECMAScript6-like hash literals?
> >>
> >
> > Does it make code easier to read, or just easier to write? Personally I
> find
> > it a bit confusing/obfuscated.
>
> The proposed syntax contributes to readability because it reduces
> redundancy and
> tells us that a key has the same name as the corresponding variable.
>
> For example, it is obvious that only name has a different name from
> the corresponding variable in the following code:
>
>     h = {
>       name: username,
>       password,
>       e_mail
>     }
>
>
> ----------------------------------------
> Feature #11105: ES6-like hash literals
> https://bugs.ruby-lang.org/issues/11105#change-52277
>
> * Author: Shugo Maeda
> * Status: Open
> * Priority: Normal
> * Assignee:
> ----------------------------------------
> Why not support ECMAScript6-like hash literals?
>
> For example,
>
>     {x, y}
>
> is equivalent to:
>
>     {x: x, y: y}
>
> For convenience, the prefix of global, instance, and class variables
> should be removed from the key name as follows:
>
>     a = 1
>     B = 2
>     $c = 3
>     @d = 4
>     @@e = 5
>     p({a, B, $c, @d, @@e, f: 6})
>     #=> {:a=>1, :B=>2, :c=>3, :d=>4, :e=>5, :f=>6}
>
>
> ---Files--------------------------------
> 0001-support-ES6-like-hash-literals.patch (3.88 KB)
>
>
> --
> https://bugs.ruby-lang.org/
>