Giter VIP home page Giter VIP logo

pfsh's People

Contributors

catenate avatar catenate-seedcx avatar yetanotherminion avatar

Stargazers

 avatar  avatar

Watchers

 avatar

pfsh's Issues

A case against the for loop.

Write a paper or post on why writing for loops should be considered harmful, and why a composition of map, reduce, filter, etc. is better.

The scope of a for loop has access to too much of the surrounding context, so it's difficult to understand and extract, and it's difficult to make sure that variables set in the for loop remain in the for loop (unless the language has variables scoped to the inside of the for loop, but even then you must remember to define them there.

Explicit name and parameters clearly define the interface and summarize a purpose of the for loop body, summarizes the purpose in the body of each argument taken from the context of the call, and checks that the right number and type of parameters are available (this can be done within the for loop, but most programming languages define functions in a way that makes this more explicit and does checks for you).

Separating a for loop body into a function makes it much easier to reuse, and capturing slight differences in the function body is better than copy and tweak since the rest of the body is not duplicated, and the slight differences may be a code smell.

Finally, the body of a for loop may mix and reimplement many patterns of operation over the collection (eg, map, reduce, filter), which would be better expressed by composing them explicitly.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.