by JacksonGariety · 12y ago · 0 comments
The single var pattern makes it hard to tell when you miss a comma. But rather than write 'var' over and over again, why not use comma first?
var foo = 0 // local
, bar = 1 // local
, wat = 2 // local
It becomes very easy to see when a comma is missed, because the indentation is visually misaligned: var foo = 0 // local
bar = 1 // global
, wat = 2 // global
As for the debugger, I break my 'single var' blocks into logical separation: // modules
var async = require('async')
, _ = require('lodash')
// constants
var IS_SERVER = !process.browser
There are more ways to address these issues than just var var var var var var var.I have always used one var per line out of habit (I think probably from C dangers with one var being a pointer and the following not if you put the asterisk by the typename rather than by the varname). However, I find it more visually pleasing too and I think there is something nice about a line of code being "atomic" so you can easily cut it and paste it in somewhere else instead.
As I said at the end of the post though, I find the comma-first thing to look pretty weird. Is it really so tiring to write `var`? Having to introduce the comma-first solution seems almost like a further argument for why the single var pattern isn't as great as it first seems, to me.