Civet icon indicating copy to clipboard operation
Civet copied to clipboard

`var` declaration shorthand

Open STRd6 opened this issue 2 years ago • 6 comments
trafficstars

There's been requests for a shorthand var to go alongside let and const.

Here are some ideas:

..= ,= ;=

Any others we should consider?

STRd6 avatar Sep 07 '23 15:09 STRd6

var is closer to let than const so I'd suggest nixing ;=.

,= seems superior to ..= because it's shorter...

I'm not sure that any of them communicate "function scope". Ah, maybe ..= does because it could mean "some levels up". Maybe the comma in ,= is pointing to the function — though that should probably be up not down. In some ways ^= or `= or '= would make sense, pointing to where the declaration hoists, but these already have meaning. \= seems too weird.

I think I'm currently leaning ,=. Anyone else have thoughts?

edemaine avatar Sep 07 '23 18:09 edemaine

My preference is ..= since it is the same as .= for let but with expanded scope. And typing two of the same character twice isn't much slower than typing it once.

I'd prefer not to use ;= since it has the upper dot which I like to think of as a "read only" bit. We could also theoretically add a .:= for a var scoped const (only enforced by compiler warning, still transpiles to var)

STRd6 avatar Sep 08 '23 02:09 STRd6

@edemaine @STRd6 Why not just =? Whereby if not previously declared, it defaults to var, like CoffeeScript…

danielbayley avatar Feb 01 '24 17:02 danielbayley

@danielbayley We already have that as an option, but you have to enable it, via "civet autoVar" or "civet coffeeCompat". See the documentation.

edemaine avatar Feb 01 '24 17:02 edemaine

@danielbayley We already have that as an option, but you have to enable it, via "civet autoVar" or "civet coffeeCompat". See the documentation.

A yeah I had seen that thanks, just wondered why it wasn’t the default behaviour… Then again I thought maybe let should be the default… which I didn’t realise was also an existing option.

Speaking of prologue directives, I would much prefer to put these settings in the config instead… Is that in the pipeline? @edemaine

danielbayley avatar Feb 01 '24 18:02 danielbayley

Speaking of prologue directives, I would much prefer to put these settings in the config instead…

@danielbayley Better to take that discussion elsewhere (new discussion or Discord), but there is already limited (but undocumented) config support.

edemaine avatar Feb 01 '24 18:02 edemaine