Project

General

Profile

Actions

Misc #15431

open

Hashes and arrays should not require commas to seperate values when using new lines

Added by nsuchy (Nathaniel Suchy) about 5 years ago. Updated about 5 years ago.

Status:
Open
Assignee:
-
[ruby-core:90597]

Description

Ruby should not require commas for hash and array values if using new lines. I think the syntax would look cleaner without.

Example

myHash = {
  :key => “value”,
  :anotherKey => “another value”
}

Could be

myHash = {
  :key => “value”
  :anotherKey => “another value”
}

And

myArray = [
  1,
  2,
  3
]

Could be:

myArray = [
  1
  2
  3
]

The syntax looks a bit cleaner, with the new lines is there a need to require a comma? I look forward to hearing the community’s thoughts on this idea :)


Related issues 1 (1 open0 closed)

Is duplicate of Ruby master - Feature #10528: Allow line breaks instead of commas in arrays, hashes, argument lists, etc.OpenActions
Actions #1

Updated by mame (Yusuke Endoh) about 5 years ago

  • Is duplicate of Feature #10528: Allow line breaks instead of commas in arrays, hashes, argument lists, etc. added

Updated by mame (Yusuke Endoh) about 5 years ago

It has been already proposed at #10528.

Updated by shevegen (Robert A. Heiler) about 5 years ago

I like the idea from one point of view - convenience. A bit
similar to changes such as require 'pp' being available by default;
of course it is not the same as the proposal here, since the
proposal here refers to a syntax change, whereas require 'pp'
was purely due to convenience. But from the point of view of
convenience, being able to omit "," would be nice - I actually
do sometimes forget this and then have to go to the editor
and add it, so from convenience, I like it.

Of course we can also use, at the least for Arrays, the shorthand
notations, such as %w() and so forth; then we don't need the ','.
For Hashes I believe we have no shorthand notiation, excluding
the : variant introduced some time ago; e. g. your example above
could be:

myHash = {
  key: “value”,
  anotherKey: “another value”
}

And it would be a bit shorter. Of course we still have to use
the ',' there.

However had I am not entirely sure if it can be so easily
added. Would this not introduce a backwards-incompatible
change? So I guess even if it were to be approved by matz
(and we don't know this as of yet), it may have to come
way past ruby 3.0.

I don't have a problem if this is not added either, though -
while it would be convenient, I don't necessarily need it
that much. We may also have to think about code that is
mixed, such as:

hash = {
abc: 'abc', def: 'def'
ghi: 'ghi',
jkl: 'jkl'
}

And perhaps other cases. (The ruby core team often needs
definitions/specifications for corner cases too, since
the implementation has to include these cases too.)

Since this is coming up every now and then, I would suggest
to mention it at some developer meeting - at the least to
hear matz' opinion about it. Because if matz does not like
the proposal then there is little point discussing it. :)

But as said, I am mostly neutral about this; only slightly
positive purely from a convenience point of view.

PS: The linked proposal is ~4 years old without much other
comments; perhaps after this may be discussed one day, we
could close down the older issues and refer to only one
of the issues, but I digress.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0