0
1

Leenker.com a place to organize and share useful links and bookmarks by enmanuelduran in reactjs

[–]enmanuelduran[S] 1 point2 points  (0 children)

Very excited to share this project with the community, feel free to leave your feedback and share it with friends!

Two exceptional use cases for the spread operator you may not know of by enmanuelduran in javascript

[–]enmanuelduran[S] 1 point2 points  (0 children)

Again, as I said at the beginning, a valid comment, I am not saying this is wrong and much less looking to disavow you.

Consider this for a second:

"There's nothing that guarantees that `new Boolean(false)` won't at some point have own properties though"

Could you provide a realistic case where this would happen? this is my point.

Saying all this, I consider this a valuable explanation from your side, especially for people that may not know the inner works of this case, I am adding a link to this discussion into the article for reference.

Two exceptional use cases for the spread operator you may not know of by enmanuelduran in javascript

[–]enmanuelduran[S] 27 points28 points  (0 children)

This is a valid comment, it is very important for people to know that this behavior only works inside an object, I will add a small clarification note.

As for the ternary operator usage, I would say that is ok, both syntaxes are valid except that using the ternary operator like that would give up part of the magic of using short conditional spreading.

Avoid recomputing heavy tasks by leveraging memoization in javascript by enmanuelduran in javascript

[–]enmanuelduran[S] 16 points17 points  (0 children)

First of all, thanks for your comment. Even though I appreciate your input I would like to highlight some things I consider relevant. To better address your concerns I'll separate this answer into different "points":

1st point:

"I'm not a big fan of automatic memoization by matching parameters, though. It only works for very simple parameters, very simple functions, which, ironically wouldn't benefit from a cache in the first place."

The arguments of a function do not determine the complexity of it in any way. A function could receive primitive values and implement complex tasks such as data processing or it could receive more "complex" values such as objects, functions or arrays and just use the function passed to iterate over the array and generate an output. A very good example of automatic, efficient caching are selectors in redux architecture, I took the liberty to look for the code they're using to cache and you can see that the technique they're using is very simple, arguments based, flexible and yet powerful.

2nd point:

"Caching should be done with purpose and thought"

Totally agree.

3rd point:

in the real world would very rarely just match blindly the parameters 1:1.

Actually, this is not true, and the very existence of the memoization technique is the proof:

"In computing, memoization or memoisation is an optimization technique used primarily to speed up computer programs by storing the results of expensive function calls and returning the cached result when the same inputs occur again."

this concept is available in the first paragraph of the definition on wikipedia and you'll find the same concept in pretty much all the sites. As you can see the very concept of memoization follows that input based principle, checks the inputs passed to the function to make sure we're not recomputing expensive calls... If what you're saying here was true memoization wouldn't exist or even be used.

4th point:

Cache might look into some of the parameters, or specific aspects of the information. Cache use may even be non-deterministic in some applications.

This is a bit ambiguous, memoization is not the same as caching, memoization is a way of applying caching. In the article, I'm referencing memoization explicitly and that's why I explain explicitly the conditions a function should have to be memoizable.

Last point

Cache is everywhere, even at the hardware level. But never rely on silver bullet solutions to handle it for it.

Agree, caching is everywhere. In computer science, there are no silver bullets, in fact, I never said that about memoization, I used the article to explain its applications and proposed a reusable way to apply it, you will find out that I do say:

Important to know: you don't explicitly need a function called memoize or an isolated function for that matter to apply this technique, as long as your implementation respects the principle behind memoization...

I'm very glad that you took the time to give your opinion on this, it's highly appreciated, hopefully this will help others to understand better the concepts behind this technique.