3 ms·
Another, less serious issue in the memoization example for JS: (cache[key] = cache[key] || fn(...args)); Will not memoize results that equal 0 or an empty s
by thefj 5y ago
Another, less serious issue in the memoization example for JS:
(cache[key] = cache[key] || fn(...args));
Will not memoize results that equal 0 or an empty string.
I guess it goes to show that copying answers from stack overflow might not be the best idea, whether it's done manually or using ML.
- k__ 5y agoHaha, I have to remind myself constantly of the now existing ?? operator.
- deergomoo 5y agoI think really you'd want to use `key in cache`, because ?? wouldn't let you memoize null or undefined. Although `in` possibly opens you up to prototype issues. JavaScript is a bundle of fun.
- jaffathecake 5y agoYeah, Map (or WeakMap if keys are objects and you don't need iteration) is much better at this kind of thing.
- k__ 5y agoGood point. Collection types are prevalent in languages like Java, but JS devs had to use plain objects for years.
- saurik 5y agoWhich is why you needed to build an actual data structure to do this kind of work based off checking for against the prototype chain instead of assuming you can use tiny bits of direct JavaScript operators.
- ViViDboarder 5y agoTo be fair, they did market it as paired programming with an AI. When pairing, your partner can make mistakes like this as well.
- hndc 5y agoThe entire selling point of pair programming is that your copilot would point out errors like this, not introduce them. Pairing works when you either pair two strong programmers or pair a strong programmer with a weak one. In the latter case, the main advantage is that it's also a mentoring opportunity. Copilot has invented a pair programming situation in which your partner constantly introduces dubious code you must painstakingly verify, but is itself incapable of being mentored.
- meling 5y agoOf course it can be “mentored”, it’s machine learning… I expect this will eventually learn from its users.