codebar / tutorials

šŸ—’ codebar's tutorials
http://tutorials.codebar.io/
258 stars 242 forks source link

for and while loops aren't common practice anymore and difficult to grok #312

Open juliankrispel opened 7 years ago

juliankrispel commented 7 years ago

I'm coaching somebody and we're going through the first few javascript tutorials.

And in those tutorials you have quite a few for and while loops.

In reality you don't really need for and while loops anymore, also they are much harder to grok than their functional counterparts. I'd recommend and would be happy to help creating tutorials to use array methods like forEach and map.

Whaddayathink?

KimberleyCook commented 7 years ago

We would very much welcome this update, it's something we've been meaning to do "for" a "while" LOL šŸ˜‚

KimberleyCook commented 7 years ago

@juliankrispel Are you still interested in updating our tutorials?

juliankrispel commented 7 years ago

Absolutely. Will have a look next Tuesdayat codebar

Julian Krispel-Samsel rainforestqa.com goodafternoon.co

On Nov 3, 2016, at 2:05 PM, Kimberley notifications@github.com wrote:

@juliankrispel Are you still interested in updating our tutorials?

ā€” You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

matyikriszta commented 7 years ago

@juliankrispel I think we should keep the for loop at least as that is still a common construct one might see in code from time to time. I'd introduce a section on other ways of achieving the same effect such as forEach and map.

@KimberleyCook what do you think?

juliankrispel commented 7 years ago

@matyikriszta I disagree. It's not a very common construct. In my experience if you look at any sane/modern codebases for and while loops get rarely used. I don't think it's appropriate as one of the first tutorials because forEach and map are easier to wrap your head round. JavaScript has changed a fair bit and I think it'd be good to update the tutorials to reflect common practices and discourage bad practices.

richardwestenra commented 7 years ago

Hi @juliankrispel, thanks for submitting an issue! I've just been chatting with @oliverturner about this. You're right that JS has changed a lot, and Iā€™d like to see forEach and map taught earlier. However my instinct is that for (and while?) loops are still common enough and have enough valid use cases to be worth teaching.

Oliver's Hot Take:

We should teach both styles because they're both in the wild and need to be understood. Additionally, we should add the caveat that for loops are mutative (and what that means / why it's considered better not to).

Also Iā€™m not so sure that forEach/map are easier to learn first. It's true that for loops have complicated syntax and introduce bad/imperative habits, but forEach/map require you to introduce array methods and get your head around things like functors. Iā€™d be surprised if forEach were easier to understand right away.

I'd be interested to see how codecademy etc handle the topic in their beginner JS tutorials.