5 ms·
I get why removing global state is a good thing in general, but here you are replacing it with a whole lot of complexity for not a particularly clear reason. Is
by orf 8y ago
I get why removing global state is a good thing in general, but here you are replacing it with a whole lot of complexity for not a particularly clear reason. Is tracking the user count with an integer dangerous in this case (Have you run into problems with it)? Is your solution not using global state anyway, just wrapped in a library?
All in all, are the abstractions (a bunch of new concepts plus a new library) worth it to just replace an integer?
function timerFunc() {
if (connectionCounter) get results();
}
socket.on('connect', function() { connectCounter++; });
socket.on('disconnect', function() { connectCounter--; });
The real problem is you want to start and stop the timer when someone connects. Just keep it simple and keep it going, but not doing anything if there is nobody connected, like above.
- s-shellfish 8y agoThat always depends on whether whatever is contained within the abstraction is something that might change. Sigh, humor. Leaving it as a primitive basically says 'you may have to hack the programming language or framework in order to modify code that depends on this piece of the logic'. Global state is something you can manage in terms of modular components. Allows for dynamic orchestration of components. It's more the long term issue that keeps repeating (more humor) than it is just replacing an integer. Being able to decide 'is this component something that needs to be reasoned about in it's own independent logical layer from the rest of the system or is it not' or 'does this component relate to other components in a well defined way'. Connect is an action, an observable action has occurred. An abstraction can trigger a behavior to other abstractions through that predefined relation. That's the point.