Skip to content

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

Open

Description

@juliankrispel

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?

Activity

  1. KimberleyCook commented on Sep 27, 2016

    @KimberleyCook
    Contributor

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

  2. KimberleyCook commented on Nov 3, 2016

    @KimberleyCook
    Contributor

    @juliankrispel Are you still interested in updating our tutorials?

  3. juliankrispel commented on Nov 3, 2016

    @juliankrispel
    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 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.

  4. matyikriszta commented on Nov 7, 2016

    @matyikriszta
    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?

  5. juliankrispel commented on Nov 7, 2016

    @juliankrispel
    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.

  6. richardwestenra commented on Jan 19, 2017

    @richardwestenra
    Contributor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions