Re:Modern Javascript: Everything you missed over the last 10...
by Kiro on Saturday May 15, 2021 @04:39PM
(#27168789)
The only reason I'm using node.js is because I can do this:
What other languages can I do this in that are better? I simply want to have a variable I can access and mutate from inside closures and let it live in memory without the need for databases or file systems.
[ Parent
| on HN ]
Re:Modern Javascript: Everything you missed over the last 10...
by merb on Saturday May 15, 2021 @05:39PM
(#27169269)
every language?
Re:Modern Javascript: Everything you missed over the last 10...
by ptx on Saturday May 15, 2021 @06:52PM
(#27169706)
To be fair, threads complicate things.
Re:Modern Javascript: Everything you missed over the last 10...
by merb on Sunday May 16, 2021 @04:06AM
(#27172038)
yeah but most languages have stuff like Atomic integers or other things.
Re:Modern Javascript: Everything you missed over the last 10...
by Kiro on Sunday May 16, 2021 @04:14AM
(#27172079)
I want a language where it's as natural as my example above, and normally an object or array so the integer was just to simplify the example. Do you have any suggestions?
I want to declare a variable and then be able to access/modify the same variable through a closure in a callback for incoming requests, so I guess that requires it to be single-threaded.
(I'm using this for game state where it's very convenient to just declare a persistent data structure in code directly without without having to use any additional abstraction.)
Re:Modern Javascript: Everything you missed over the last 10...
by merb on Sunday May 16, 2021 @05:55AM
(#27172532)
well without atomic access your state would be wrong. there are languages that allow stuff like that, but if you do it you can still have the wrong number. i.e. in c# something like you wrote is possible but when getting multiple requests, the number might be wrong at the end.
you always have some tradeoffs because in your case when you would run it with a multi threaded js engine your variable would be as broken as the c# one. that's why java does not allow it by default to modify a variable inside a thread that is declared outside.