Created
January 23, 2017 23:51
-
-
Save dashmug/98616a2a145be27ef6578feee9575a48 to your computer and use it in GitHub Desktop.
Which is better inner or outer functions?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const oneBigFunction = () => { | |
const add = (x, y) => x + y | |
const subtract = (x, y) => x - y | |
const multiply = (x, y) => x * y | |
const divide = (x, y) => x / y | |
return divide(add(multiply(8, 1), 2), subtract(3, 1)) | |
} | |
// or | |
const add = (x, y) => x + y | |
const subtract = (x, y) => x - y | |
const multiply = (x, y) => x * y | |
const divide = (x, y) => x / y | |
const smallFunction = () => divide(add(multiply(8, 1), 2), subtract(3, 1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Obviously, if those inner functions are used somewhere else, I would put them outside the function.
So this question is only about inner functions that are NOT going to be used anywhere else.
Which style is the better one? I'm partial with the small, external functions as I can easily unit-test each function and also easily reuse them. Is there an advantage for the first one?