Web devs

>web devs

Attached: web.png (900x495, 163K)

Other urls found in this thread:

ryanpcmcquen.org/javascript/2015/10/25/map-vs-foreach-vs-for.html
twitter.com/NSFWRedditGif

For ( i=0; i < 50 ; i++ ) {
// do shit
{


How does this look bad?
Its fucking perfect and its compact.

it's just "map" is even shorter
It's not
>web devs
It's
>fucking retards

The vast majority of web devs I know are working full-stack and are way more adequate than 99.9% of Jow Forums which is arguably isn't an achievement but still.

WEB DEVELOPERS

I'm a full-stack dev, I just prefer doing web these days because it's really coming into its own as a way to write applications. PWAs are quickly becoming something quite wonderful.

you dont think it looks bad because youre so used to seeing it
myList.forEach(thing -> thing.doStuff());

looks a lot better and it's more self explanatory than
for(int i = 0; i < myList.size(); i++) {
myList.get(i).doStuff();
}

I'd like to point out that the guy is wrong in OP's pic, at least for Node.js. Latest benchmarks show .forEach() has a slight speed increase over a traditional for loop.

> Latest benchmarks show .forEach() has a slight speed increase over a traditional for loop.
Bullshit.

_.times(50) {
// do shit
}

Even easier

>atleast for node.js
stopped reading there

Just in case anyone thinks this is cherry picking, I know more than one webdev that refuses to use for loops in JS because they have a huge boner for functional programming.

all those people with all their memery about haskell finally accomplished something: they made web devs even stupider than they a;ready were. Good show.

I just benchmarked in v8 a week ago and for loop was good bit faster.

>web devs

Attached: duh.png (1172x404, 19K)

those are distances by the way. someone sorted distances alphanumerically

for loops are ridiculous and have no place in modern programming
if you're doing hard real time things, sure
for soft real time or not real time at all, which is 99% of everything most people will ever program in their lives, map is a lot more readable, maintainable and it also states intent which makes that part of the code self documenting

"ugly" may be the wrong reason not to use for loops, but that doesn't mean map isn't superior in general

Attached: this poster is a skeleton.jpg (125x150, 9K)

>for loops are ridiculous and have no place in modern programming

Attached: 2185B3EB-58FE-4E46-85A9-5DFD6978C040.jpg (645x729, 51K)

>full-stack
no one who writes css for a living gets to use my boipucci

nodejs fags actually believe this

He/She is talking about the padding between values; too large.

>imperative brainlet's can't into functional maps
yes, i know that picture is an accurate representation of your brain

How is for faster than foreach? Isn't it all the same in bytecode?

obviously not, they are different things
for is the fastest but it's also the worst method from a code quality point of view
ryanpcmcquen.org/javascript/2015/10/25/map-vs-foreach-vs-for.html

like donal knuth said, don't pre-optimize
use a map first because it is the best method, and only change it into a for loop if you absolutely need the performance

in most cases, map being 20% slower in javascript means that it's still fast enough that users won't be able to tell the difference

Attached: perf.png (987x615, 27K)

t. webdev

Ideally the browser JS compiler should be smart enough to choose what is the best way to optimize a loop when compiling to bytecode. Premature optimization of silly things that people think is important is always a waste of time. If it's actually running slow, profile your code and see where the slowdown really is.

I compared for with foreach in C++ and it produced almost the exact same asm, why is it so different here? I'm not talking about map

Number.prototype.times = callback => {
for(var n = 0; n < this; n++) {
callback.invoke(n);
}
};

I hate that this works.
I hate that I know how to do this even though I'm not a web developer.
I hate Javascript.

C++ doesn't have a forEach method lmao
C++11 does have a ranged based for loop which is something entirely different from a forEach

do you want me to specify the exact version of the language every time? you have to specify which ecmascript version you're using then

anyway, i assumed std::for_each to be similar to forEach, but i don't know much about js

The js has this weird callback thing which I believe is what slows it down. The stl for_each is just a template that runs an unary function through a for loop

foreach is a function call that accepts a function as an argument. same with map, etc.
for is simply a set of labels and gotos to those labels, no overhead of function calls.
fukken webshits don't know shit

I see, thanks.

I was talking about for_each vs for in other languages because I don't know webdev

Are you retarded? Iterating over a collection using map/foreach is fine in some context, if you have *data parity over each item in the collection*. Shit doesn't always happen, and it's not always appropriate to dump it into one map or foreach callback.

It's like talking to children who only have a few years in the industry and haven't been battle tested.

for (vector::const_iterator it = myList.begin(); it != myList.end(); ++it) {
const Thing& thing = *it;
thing.doStuff();
}


>the absolute state of C++

for is cowardly, while (your shit) { clean_up_your_shit; }

but machine learning

>If it's actually running slow, profile your code and see where the slowdown really is.
Or I could just use a for loop the first time.

for (Thing const &t : myList) {
t.doStuff();
}

for (auto &t : list) {
t.do_stuff();
}

why the fuck do people never use
for (key in array)

fucking webdevs dont even bother researching better solutions

How does a map make more sense and look better than a for loop? Don't think I ever came across a problem and thought oh a map is the best solution for this instead of a goddamn for loop, or even a while loop. What bullshit goes on in webdev land?

the amount of misunderstanding here is funny
it's the same user providing details on the image

For each customer no-lock:
Display customer.
End.

I feel like using map, filter and reduce make logic easier to understand at a glance than using a for loop.
const authorNamesByCompany = (authors, company) =>
authors
.filter(author => author.company === company)
.map(({ name }) => name);

To me is more readable than this:
const authorNamesByCompany = (authors, company) => {
let result = [];
for(let i = 0; i < authors.length; i ++){
if(authors[i].company === company){
result.push(authors[i].name);
}
}
return result;
}

t. butthurt webdev

You guys are all faggots. for loops are better.

Because it also iterates over array parameters like length, for example.

anything that avoids curly braces is pretty
C-style syntax is a tumour that needs to die

and before you sperg at me about python I prefer this
do i=1,100
x = func(i)
end do

But for loops look fucking great

for index, data in ipairs(table) do
data.dothings(bar, foo)
end


who else here /lua/

It takes a special kind of stupid that only C/C++ programmers have to think that C-style for loops should still be used against loops that implicity iterate over arrays, this is why I stopped bothering to read through programming threads on Jow Forums anymore, I cant wait till the 'pajeets' send all these basement dweller NEETs to the 3rd world where they belong

want an example of how shit webdevs are? see how Jow Forums freezes for HOURS at a time? that's webdevs (either that or gookmoot is implementing new data mining/surveillance systems)

There's something very wrong with your setup.
I am on line most of the day (I'm an invalid), and Jow Forums just doesn't freeze for me.
Must be something you're doing.
Or gookmoot is fucking with you. Did you do something to annoy him?

Jow Forums uses cloudflare. if cloudflare fails to reach the main server (for whatever reason), Jow Forums will "freeze". it was like that for me for like 3+ hours today, until some 10+ minutes before I posted that comment.

It does not since length is not an enumerable.
It may iterate over some properties if you define them incorrectly, such as
Array.prototype.doSfuff = function(){
//doStuff
}

Instead of
Object.defineProperty(Array.prototype, 'doStuff', {
value: function(){
//doStuff
}
})


That said, for...in is much slower than a regular for, because it iterates over all attributes of an object. If you're going to iterate over a normal array or an array-like-object, use the for...of operaror instead.

unless you actually need the index, then traditional for loops have the perfect semantics.