The main issue with overusing const is that you lose the user intent of "this ought not be mutated" as in const fs = require('fs')
-
-
I’ve spent the last few months working on partial evaluating React code via Prepack. So I probably see JS in a different way to most haha
-
It's very easy for prepack to apply the "un-mutated let binding" optimization and I really hope you do.
-
It’s not that easy. Nothing is safe from side effects it seems. The only somewhat safe thing is strict type annotations
-
What exactly is not easy. Are you referring to use of direct eval? Or something else?
-
Global side effects, eval, getters/setters, proxies etc.
-
How can global side effects, getters/setters or proxies affect the analysis of whether a let-bound variable in a module is ever mutated?
-
I wasn’t talking about mutating the binding, rather the object the binding referenced.
-
Right. I'm saying you can easily apply an optimization that treats un-mutated let bindings as const and should.
- 1 more reply
New conversation -
-
-
If the advice is "if you want to mutate, go ahead and change it to let", it makes it much easier to mutate something you shouldn't have.
-
I use const to mean "if you're mutating this binding, you're doing something wrong" rather than "it happened to not be mutated"
End of conversation
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.