sketchpunk / FunWithWebGL2

Fun with WebGL 2.0 Youtube Tutorial Series
666 stars 141 forks source link

replaced arguments with spread operator #18

Closed chris-kruining closed 4 years ago

chris-kruining commented 4 years ago

argumants is an old mechanism and I wouldn't be suprised if it were to be removed.

sketchpunk commented 4 years ago

I dont believe arguments would be removed, the spread operator in this context wouldn't work without it.

Side note, forEach is just syntax sugar that is less efficient when used in this context. For each does a for loop anyway, now instead of calling the add function, you introduced an inline closure that then does the call to add function. So your proposed solution goes from one Loop that does a single function call per iteration, to a Function call that generates a for loop, that then calls a function who's whole purpose is to call another function for each iteration. Syntax wise it looks nice, but performance wise, its less efficient.

Now, I'm not against forEach or closures, they have their purpose. Like an array sort function is a good example why a ForEach and Closure makes more sense, this way you can make the compare function that it uses be programmer defined, any other way it would probably complicate things.

chris-kruining commented 4 years ago

I agree on the foreach discussion, just a habit of mine to prefer readable oneliners.