Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Yeah, sure, if you declare every variable global, it makes adding new features feel quick and easy. There's a reason that global variables are considered harmful.


I completely agree with you! But we're talking about one of the few exceptions -- cross-cutting concerns.

I think just about everyone would scoff at the idea that every single method in your codebase should take an explicit `logger` parameter rather than just having a global logger object.

So now we're looking as a case where you have a bunch of services: dbs, caches, apis, storage that are used all over the app ("in every file") and you have to make a judgement call.

* Have hundreds (honestly thousands at current $dayjob) of methods that do a lot of work just to pass around the same connection handle.

* Declare a single object that manages all the connection pools.

I think it's really hard to escape the fact that connection pools are actually global and you either have to admit this or have your runtime hide it from you.

Another example of a cross-cutting concern that runtimes usually hide is event loops. Can you imagine if every function that wanted to use async had to be passed an event_loop variable?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: