From f6ab827ed7394f8661669a5b6de86aac825193d6 Mon Sep 17 00:00:00 2001 From: Franz Knipp Date: Fri, 23 Feb 2018 12:33:13 +0100 Subject: [PATCH 1/2] Changing order in example of *Functions should only be one level of abstraction* Like said in https://github.com/ryanmcdermott/clean-code-javascript#function-callers-and-callees-should-be-close, the code is read from top to bottom, so I'd prefer the definition of the *function parseBetterJSAlternative* above the functions called within. --- README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index a401258c..47305f60 100644 --- a/README.md +++ b/README.md @@ -113,7 +113,7 @@ saveCityZipCode(city, zipCode); ``` **[⬆ back to top](#table-of-contents)** -### Avoid Mental Mapping +### Avoid Mental Mappingf Explicit is better than implicit. **Bad:** @@ -343,6 +343,14 @@ function parseBetterJSAlternative(code) { **Good:** ```javascript +function parseBetterJSAlternative(code) { + const tokens = tokenize(code); + const ast = lexer(tokens); + ast.forEach((node) => { + // parse... + }); +} + function tokenize(code) { const REGEXES = [ // ... @@ -367,14 +375,6 @@ function lexer(tokens) { return ast; } - -function parseBetterJSAlternative(code) { - const tokens = tokenize(code); - const ast = lexer(tokens); - ast.forEach((node) => { - // parse... - }); -} ``` **[⬆ back to top](#table-of-contents)** From 3ada14239ba970aa3ccf832334b2e9205468f3fc Mon Sep 17 00:00:00 2001 From: Franz Knipp Date: Fri, 23 Feb 2018 12:39:12 +0100 Subject: [PATCH 2/2] Fixing typo introduced by previous patch --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 47305f60..db12e609 100644 --- a/README.md +++ b/README.md @@ -113,7 +113,7 @@ saveCityZipCode(city, zipCode); ``` **[⬆ back to top](#table-of-contents)** -### Avoid Mental Mappingf +### Avoid Mental Mapping Explicit is better than implicit. **Bad:**