These are chat archives for jdubray/sam

29th
Nov 2017
Victor Noël
@victornoel
Nov 29 2017 08:01
you can always have a singleton that you give to each modules…
Fred Daoud
@foxdonut
Nov 29 2017 12:07
How do you mean @victornoel ? It will still need to be a global variable.
Victor Noël
@victornoel
Nov 29 2017 12:46
I haven't looked at the code, but usually, when you have a problem with a global variable, you can replace it by creating a singleton that you pass to everyone that needs it instead of referencing via a global variable. It doesn't fix the fact that you have a singleton, but at least you a better visibility on what is using it and your code is easier to test (since you can mock this singleton when testing one module)
Fred Daoud
@foxdonut
Nov 29 2017 13:54
@victornoel that won't work though. We are talking about onclick="doSomething(...)" in raw HTML. doSomething has to be a global variable. Even if you put actions in an object, say onclick="actions.doSomething(...)", you still need actions to be a global variable.
Victor Noël
@victornoel
Nov 29 2017 15:28
ah yes, sorry :)
Paolo Furini
@pfurini
Nov 29 2017 16:56
@foxdonut there should be a singleton pre-processor that translate plain calls like doSomething(..) to segregated calls into a global singleton
for example doSomething in a registered module named module1 could become __actions_dispatcher.invoke('module1', 'doSomething', ...parms here)
it is the approach taken by some frameworks... ops, sorry, maybe that's a banned word here nowadays.. :D
Fred Daoud
@foxdonut
Nov 29 2017 17:19
@pfurini that's just covering up the dirt with a carpet though..
Paolo Furini
@pfurini
Nov 29 2017 17:22
@foxdonut that's true, but it's the only elegant solution I can come up to reduce the global pollution
BTW I don't like using global vars, but sometimes JS + Browser === the dirt
Fred Daoud
@foxdonut
Nov 29 2017 17:25
@pfurini why not instead make it clean by using onclick="${doSomething(...)}"
Paolo Furini
@pfurini
Nov 29 2017 17:26
it was only a workaround for the approach @jdubray was using, not something I use or plan to use in my code..
Fred Daoud
@foxdonut
Nov 29 2017 17:27
@pfurini ah ok gotcha.
it might not look like a big deal in toy examples or small projects, but I've worked on large JS projects that used global variables, it is not an acceptable approach.
Paolo Furini
@pfurini
Nov 29 2017 17:28
regarding globals in the browser, there are so many big web sites/apps out there relying on globals, that's not something that will disappear any soon
Fred Daoud
@foxdonut
Nov 29 2017 17:29
you open yourself up to a ton of bugs, and situations where you fix a doorknob in the basement and somehow that makes the lightbulbs in the bedrooms upstairs to stop working.
Paolo Furini
@pfurini
Nov 29 2017 17:29
sometimes you include a dependency, or a 3rd party script, and voilà, magic globals appear.. ;)
I never had globals in my OWN code, but sometimes they just "appear" by means of another dependency, and sometimes you need that dependency for a load of factors (read a company that wants you to add a remote logging/tracing script, or whatever)
Fred Daoud
@foxdonut
Nov 29 2017 17:31
yeah I agree, and you could namespace your globals to MY_APP or whatever, but that approach takes us back to 10 years ago
Paolo Furini
@pfurini
Nov 29 2017 17:33
the reality is that browsers are yet tied to 20 years ago.. now we want to develop APPS in browsers, but then we should rethink the entire platform from the ground up, not just adding patches to patches
the entire "silverlight" story was a flop, but it wasn't a bad idea, only a bad execution... browsers should contain two distinct engines/standards, one for browsing (from 20 years ago), and another for apps
Fred Daoud
@foxdonut
Nov 29 2017 17:36
java applets, flex apps..
Paolo Furini
@pfurini
Nov 29 2017 17:39
the flop was because they tried to execute plugins in browsers.. now we need a standard, just declare in your bootstrap page (index) what's your intent, say site or app, and the browser will switch to the appropriate engine
that's pretty much the direction with the new runtimes being added to modern browsers, but my impression is that they miss a "global" vision
Paolo Furini
@pfurini
Nov 29 2017 17:48
(PWAs and the enabling technologies are that direction, but I'd like to see the UX story being addressed too, like a better way of styling UI components beside CSS)
Fred Daoud
@foxdonut
Nov 29 2017 18:25
completely agree, @pfurini
Jean-Jacques Dubray
@jdubray
Nov 29 2017 19:43
@pfurini I'll start charging $1 each time someone talks about a framework in this forum :-)
Fred Daoud
@foxdonut
Nov 29 2017 19:49
lol
:moneybag: :money_with_wings: