6 ms·
> Replacing commas with whitespace sounds to me like replacing a very minor irritant with a constant full-body rash Both vivid and accurate. In order to comba
by Normal_gaussian 10y ago
> Replacing commas with whitespace sounds to me like replacing a very minor irritant with a constant full-body rash
Both vivid and accurate.
In order to combat trailing commas I normally place the comma on the following line, e.g.
{ "time": "3 minutes past four"
, "age": 229
, "sex": "monoecious species"
, "appearance": "Tree-like. It's a tree."
}
uint8_t *data // Yada
, *buffer // Ya
;
var javascript
, variable = 6
, declarations = [ "This is taking too long", "Yep" ]
, mix = [ "Flour", "Sugar", "Water" ]
, types = { 'old' : (d) => { return d < new Date }
, 'new' : (d) => { return d > new Date }
, 'borrowed': (o) => { return false }
, 'blue' : (c) => { return true }
}
, regularly = new Date().toISOString()
;
With such a format there is only ever a problem deleting the first line, which I find is much much harder to do without also noticing what you've done to the larger statement.
- yepperino 10y ago> In order to combat trailing commas I normally place the comma on the following line Ah okay, so you're that guy whose code I have to reformat in every new job.
- Normal_gaussian 10y agoI highly recommend having a couple of reformatting scripts around - its a great way to find logical errors quickly. Of course don't commit reformats where it diverges from the codebase.
- ketralnis 10y agoIf you're having to do it on every job, maybe you're the unusual one
- philovivero 10y agoAh, so you're the guy whose code I have to re-reformat back to the proper format.
- yepperino 10y agoI use industry standard IOCCC formatting rules. Doesn't everyone? http://www.ioccc.org/2015/endoh1/prog.c http://www.ioccc.org/2015/endoh1/prog.c
- stevewilhelm 10y agoI have seen this approach also used when constructing complex SELECT FROM and WHERE clauses in MySQL
- truth_sentinell 10y agoThat is horrible from a human understanding perspective
- Normal_gaussian 10y agoIt makes perfect sense to me. Which to be honest is what matters. However I would imagine that a lot of the problem grokking it is due to not being used to it.
- paulddraper 10y agoWhy? It looks easier for me; I'm far more likely to notice a missing comma. But I'm sure you must have a valid point, if you would elucidate?
- majewsky 10y agoI came across this formatting pattern in Haskell, but I still prefer trailing commas for one reason: I can trivially apply line-wise operations (e.g. sort or align) on the key-value pairs without breaking the syntax. When I sort your first snippet line-by-line, it becomes , "age": 229 , "appearance": "Tree-like. It's a tree." , "sex": "monoecious species" { "time": "3 minutes past four" } and the syntax is broken. With trailing commas, the syntax always stays valid: { "age": 229, "appearance": "Tree-like. It's a tree.", "sex": "monoecious species", "time": "3 minutes past four", }
- tome 10y agoWith prefix commas it also always stays valid { , "age": 229 , "appearance": "Tree-like. It's a tree." , "sex": "monoecious species" , "time": "3 minutes past four" }
- saurik 10y agoYou are assuming that trailing commas are ignored as valid, which is true of JavaScript but not of JSON or of C (the other example).
- majewsky 10y agoYes, I'm aware of this being an error in JSON (which is precisely the point of the discussion). I wasn't aware that it's a problem in C. Maybe gcc is more lenient here.
- 10y ago