4 ms·
Modules avoid the variable issue because ‘use strict’ is applied by default for them. IMO JS as a language is in a much better place than Python currently. I e
by Bahamut 7y ago
Modules avoid the variable issue because ‘use strict’ is applied by default for them.
IMO JS as a language is in a much better place than Python currently. I end up frustrated a fair amount by arcane errors in Python due to less expressive constructs or some wtf issues like unexpected variable scoping within Python modules.
- BiteCode_dev 7y agoThis is most probably because you are trying to code in Python like you code in JS: this always leads to frustration. I started to have fun coding in JS the day I accepted it was not Python and that I had to structure and style my code differently. E.G: in Python you will use iteration a lot. A lot of a lot. But not so many callbacks. The reverse is true in JS.
- CallocRoast 7y agoIterators and callbacks aren’t comparable. You don’t use them for the same thing.
- BiteCode_dev 7y agoWhat do you think each(), map() and filter() do ? But even without that, I'm not saying they are comparable. I'm saying the same API will use explicit anonymous callbacks in JS and something else in Python (decorators, subclassing, protocols, generators...). I'm saying that the same API will use __iter__ in Python and something else in JS (type conversion, proxy object, explicit method call...). E.G, this is a Python pattern you'll find in contextlib or in pytest fixtures: @somekindofregistration def foo(): print('code that runs before') try: yield except Stuff: print('Error handling') print('code that runs after') This uses Python iteration mechanism to run code at 3 different times in a life cycle. While in JS, you would pass 3 callbacks.
- WoodTree 7y agoMap, filter, and fold are higher order functions, functions which take functions as parameters. You are misusing the word callback. A callback is a function passed to another thread that will maybe be invoked later as a response (like it calls you back).
- BiteCode_dev 7y agohttps://en.m.wikipedia.org/wiki/Callback_(computer_programming) https://en.m.wikipedia.org/wiki/Callback_(computer_programmi...
- zbentley 7y agoThat's not what a callback is. A callback is just a function passed to an outer function that the outer function may call. Even MDN uses the term callback to describe e.g. the argument to 'map': https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... In contrast, Lodash goes out of its way not to use the term "callback", presumably to avoid confusion since it's a place where many functions-that-take-a-function-argument do not call the provided function, e.g. https://lodash.com/docs/#curry https://lodash.com/docs/#curry