ninja
This commit is contained in:
parent
bef98f7087
commit
9cb33f4039
1 changed files with 4 additions and 5 deletions
|
@ -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.
|
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.**
|
**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!
|
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
|
## 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.
|
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
|
## Overlap outer variables
|
||||||
|
@ -180,7 +179,7 @@ When in the light, can't see anything in the darkness.<br>
|
||||||
When in the darkness, can see everything in the light.
|
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
|
```js
|
||||||
let *!*user*/!* = authenticateUser();
|
let *!*user*/!* = authenticateUser();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue