Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
juliankrispel opened this issue Sep 27, 2016 · 6 comments

Comments

@juliankrispel
Copy link

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
Copy link
Contributor

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

@KimberleyCook
Copy link
Contributor

@juliankrispel Are you still interested in updating our tutorials?

@juliankrispel
Copy link
Author

Absolutely. Will have a look next Tuesdayat codebar

Julian Krispel-Samsel
rainforestqa.com
goodafternoon.co

On Nov 3, 2016, at 2:05 PM, Kimberley [email protected] 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
Copy link
Contributor

@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
Copy link
Author

@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
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants