2 ms·
I prefer the "hash rocket" (I call it the fat comma), because it looks nicer when you have a hash with keys of varying length. Compare: { foo: 'ba
by jrockway 16y ago
I prefer the "hash rocket" (I call it the fat comma), because it looks nicer when you have a hash with keys of varying length. Compare:
{
foo: 'bar',
hello_world: 'OH HAI',
}
to
{
foo => 'bar',
hello_world => 'OH HAI',
}
If you try to do that with colons, it goes all wonky:
{
foo : 'bar',
hello_world : 'OH HAI',
}
- kleiba 16y agoIt's debatable whether aligning the mapping operator - be it a colon or a hash rocket - is a good idea to begin with. The point has been made in the past that if you edit the map so that the longest key changes, you'd have to realign all other entries too. For code versioning, e.g., in shared development, this creates unnecessarily large diff's. For instances, patches become more difficult to read, because they include lines that haven't actually changed content-wise, just layout-wise.
- jrockway 16y agoFor code versioning, e.g., in shared development, this creates unnecessarily large diff's. For instances, patches become more difficult to read, because they include lines that haven't actually changed content-wise, just layout-wise. Well, no. Here's an example. File a: { foo => 'bar', hello_world => 'OH HAI', } File a with a long key added, let's call it b: { foo => 'bar', hello_world => 'OH HAI', longlonglonglong => 1, } Then we do a diff: $ diff -uw a b --- a 2011-01-06 08:51:55.725595229 -0600 +++ b 2011-01-06 08:51:52.285595452 -0600 @@ -1,4 +1,5 @@ { foo => 'bar', hello_world => 'OH HAI', + longlonglonglong => 1, } So see, that's not a problem.