2/ this means that you have to choose to mutate a binding in order to mutate it: "let x = 1; x = 2"
-
-
-
3/ if you already had to choose to mutate the binding, what value did you get from *also* having to change const to let?
-
4/ as for static analysis or optimizations, compilers should be able to easily treat single-assignment lets as const; it's purely lexical
-
5/ with the exception of globals, which is not the situation I'm talking about (global consts seem fine)
-
@wycats okay, if global const seems fine then I don't think we have an issue. :) consts defined at the top of a file seems best practice -
@keithwhor cool. I was mostly reacting to a pattern of using const for all bindings in a program. -
@wycats@keithwhor I dunno, I can understand it. The whole point is to be able to use as close to equational reasoning as possible, right? -
@wycats@keithwhor with const-by-default you can find the decl, and know you aren't going to find any reassignments. - 1 more reply
New conversation -
-
-
@wycats "const everywhere" imo leads to less cognitive load. with let, you need to scroll down to find what might be mutating its state -
@wycats it has also saved me a couple times with typos and during refactoring like this: https://babeljs.io/repl/#?experimental=true&evaluate=true&loose=false&spec=false&playground=false&code=function%20foo()%20%7B%0A%20%20const%20something%20%3D%202%0A%20%20%0A%20%20function%20inner()%20%7B%0A%20%20%20%20%2F%2F%20this%20code%20gets%20moved%20in%20a%20refactor%0A%20%20%20%20%2F%2F%20let%20something%20%3D%200%0A%20%20%20%20%0A%20%20%20%20%2F%2F%20outer%20%22const%22%20saves%20us%0A%20%20%20%20something%20%2B%3D%205%0A%20%20%7D%0A%7D …
End of conversation
New conversation -
-
-
@wycats redeclaration* ;)Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
@wycats that's not reassignment. that's rebinding.Thanks. Twitter will use this to make your timeline better. UndoUndo
-
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.