Comment

Comment by slooonz

Trailing commas actually have an important role.

Let’s say you have some code :

  const foo = {
    x: 1,
    y: 2,
  };
and you want to add a field :

  const foo = {
    x: 1,
    y: 2,
    z: 3,
  };
Without trailing commas, the diff is

  - y: 2
  + y: 2,
  + z: 3
With trailing commas :

  + z: 3,
The second diff is actually much clearer at what’s happening.

This is why it irritates me when people forget the trailing comma. It’s not a problem in the moment. But I know it will be a small but avoidable cognitive burden on the next PR (wait, why did "y" changed ? Oh, right, it didn’t).

parent slooonz 1 year ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton