From 9cb33f4039e5751bfd0e2bca565a37aa463fb477 Mon Sep 17 00:00:00 2001 From: Ilya Kantor Date: Sun, 9 Jun 2019 15:59:34 +0300 Subject: [PATCH] ninja --- 1-js/03-code-quality/04-ninja-code/article.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/1-js/03-code-quality/04-ninja-code/article.md b/1-js/03-code-quality/04-ninja-code/article.md index 9019242f..7846f6e2 100644 --- a/1-js/03-code-quality/04-ninja-code/article.md +++ b/1-js/03-code-quality/04-ninja-code/article.md @@ -137,7 +137,7 @@ Instead, reuse existing names. Just write new values into them. In a function try to use only variables passed as parameters. -That would make it really hard to identify what's exactly in the variable *now*. And also where it comes from. A person with weak intuition would have to analyze the code line-by-line and track the changes through every code branch. +That would make it really hard to identify what's exactly in the variable *now*. And also where it comes from. The purpose is to develop the intuition and memory of a person reading the code. A person with weak intuition would have to analyze the code line-by-line and track the changes through every code branch. **An advanced variant of the approach is to covertly (!) replace the value with something alike in the middle of a loop or a function.** @@ -155,7 +155,7 @@ function ninjaFunction(elem) { A fellow programmer who wants to work with `elem` in the second half of the function will be surprised... Only during the debugging, after examining the code they will find out that they're working with a clone! -Seen in code regularly. Deadly effective even against an experienced ninja. +Seen in code regularly. Deadly effective even against an experienced ninja. ## Underscores for fun @@ -169,8 +169,7 @@ A smart ninja puts underscores at one spot of code and evades them at other plac Let everyone see how magnificent your entities are! Names like `superElement`, `megaFrame` and `niceItem` will definitely enlighten a reader. -Indeed, from one hand, something is written: `super..`, `mega..`, `nice..` But from the other hand -- that brings no details. A reader may decide to look for a hidden meaning and meditate for an hour or two. - +Indeed, from one hand, something is written: `super..`, `mega..`, `nice..` But from the other hand -- that brings no details. A reader may decide to look for a hidden meaning and meditate for an hour or two of their paid working time. ## Overlap outer variables @@ -180,7 +179,7 @@ When in the light, can't see anything in the darkness.
When in the darkness, can see everything in the light. ``` -Use same names for variables inside and outside a function. As simple. No efforts required. +Use same names for variables inside and outside a function. As simple. No efforts to invent new names. ```js let *!*user*/!* = authenticateUser();