Feature #17292
closedHash Shorthand / Punning
Description
Set Literal vs Javascript Object Punning¶
There was a proposal for a Set literal here: https://bugs.ruby-lang.org/issues/16989
...but it was brought up that this is similar to the Javascript Object punning, or Object shorthand syntax:
Proposition: I believe we should use brackets ({}) for a shorthand Hash syntax similar to Javascript.
Hash Punning¶
My first proposal in this feature request is Hash punning, or Hash shorthand:
This syntax avoids the ambiguous syntax of empty block ({}) versus empty set ({}), and with the presence of Symbols it introduces a distinct syntax that would be easier to parse against.
One potential issue would be mixed syntax:
Method Punning¶
This syntax can also be used for keyword argument and method call punning:
I believe this existing syntax for required keywords gives credence to the idea of introducing punning to Ruby, as it's very similar to existing syntax, and therefor feels "Ruby-like".
Pattern Matching¶
This syntax is also already present and used in pattern matching, making it already part of the language:
I believe this further justifies the case for punning syntax.
Updated by mame (Yusuke Endoh) over 5 years ago
- Is duplicate of Feature #14579: Hash value omission added
Updated by baweaver (Brandon Weaver) over 5 years ago
I would agree this is a duplicate, but in the last year we have had the introduction of the pattern matching syntax which makes this less of a syntactical oddity than it may have been in the past.
Updated by mame (Yusuke Endoh) almost 5 years ago
- Related to Feature #18124: Hash shorthands (matching constructors functionality in JS) added
Updated by shugo (Shugo Maeda) almost 5 years ago
- Status changed from Open to Closed
Thank you.
Committed in c60dbcd1c55cd77a24c41d5e1a9555622be8b2b8.