6 ms·
I had to let go of doing it The Right Way from the get-go, and allow myself to fumble through using suboptimal or just plain amateur setups just to get comforta
by Animats 10y ago
I had to let go of doing it The Right Way from the get-go, and allow myself to fumble through using suboptimal or just plain amateur setups just to get comfortable with individual tools.
Javascript started as a language for small programs. While it's possible to write well-structured large programs in Javascript, the language does not compel modularity. By default, everything is global. Modules and objects have to be built out of closures. There are many ways to do this, and if you have several libraries, each probably does it differently. Hence the pain level.
- z3t4 10y agoFor front-end, just start every .js file with: (function() {"use strict"; and end with })(); and write all global variables in ALL_CAPS, or with Big First Letter if it's a constructor function / Class. If you want global functions, give them name-spaces, like UTIL.handyFunction = function handyFunction() {}
- Animats 10y agoThat's how to fix code that you write. It doesn't help with code that you import or copy from elsewhere.
- z3t4 10y agoSometime it feels like people intentionally make their code hard to copy/reuse ... While the code might do awesome stuff, it will however not live long due to manageability problems. When the author reads his own code six moth later, he's unable to fix that bug or add that feature, because he has forgot about the hundreds of global variables, functions and couplings he had in his head when writing the program.