DEV Community

Discussion on: Using a single for each loop or map to go over multiple arrays

Collapse
 
deathshadow60 profile image
deathshadow60

I still find arrow functions painfully cryptic, and given how piss poor foreach is in terms of performance, I still don't entirely get why people are favoring it over conventional for loops. It feels to me like making it painfully and agonizingly cryptic simply because "wah wah, eye dunz wunna type".

I don't understand why anyone would do this:

arr1.forEach( (a, i) => console.log(a + arr2[i]) );

Instead of this:

for (var i = 0, iLen = length(arr1); i < iLen; i++)
    console.log(arr[1] + arr[2]);

Given the slowdowns the callback nature of foreach adds to the process and how it utterly destroys code clarity.

But there's a LOT of new stuff in JS that as someone who cut their teeth on Wirth family languages, I find painfully cryptic and obtuse, to the point much of it feels only one step removed from brainf*** and as if people looked at the code in the IOCCC and went "this is way too clear and easy to understand".

By choice.

Collapse
 
bfuller123 profile image
Brett Fuller

Great point! Arrow functions are important to JS because of scope related to this keyword and how an arrow function does not have its own this. A common pattern in old JS was that = this but you can forgo that now in favor of an arrow function, and it will actually just use this of the method that called/created it. So when a person gets stuck with using a callback, an arrow function can be their best friend.

Collapse
 
deathshadow60 profile image
deathshadow60

"stuck using a callback" to me just sounds like crappy coding practices -- admittedly that happens a lot with these derpy frameworks created by people unqualified to write a single blasted line of HTML, CSS, or JS... but that's why I don't use or advocate the use of frameworks.

... and the "this" scoping thing has rarely ever been a problem for me, but that stems from understanding it and using different approaches to problem solving than the hot and trendy crap that so many know-nothings blindly copy from those derpy frameworks or web-rot filled hives of scum and villainy like DynamicDrive.

I'd probably be ok with arrow functions if they weren't the "arrow" part and used, I don't know... a WORD. C syntax is painfully and agonizingly cryptic enough without pissing on it further.

But again, I come from a Pascal/Modula/Ada background. C is not my favorite programming language, and with JavaScript using C's painfully obtuse and cryptic syntax...