minor
This commit is contained in:
parent
51aff82819
commit
6e4427dcf0
2 changed files with 10 additions and 8 deletions
|
@ -45,7 +45,7 @@ The Dao hides in wordlessness. Only the Dao is well begun and well
|
||||||
completed.
|
completed.
|
||||||
```
|
```
|
||||||
|
|
||||||
Another way to code faster (and much worse!) is to use single-letter variable names everywhere. Like `a`, `b` or `c`.
|
Another way to code faster is to use single-letter variable names everywhere. Like `a`, `b` or `c`.
|
||||||
|
|
||||||
A short variable disappears in the code like a real ninja in the forest. No one will be able to find it using "search" of the editor. And even if someone does, he won't be able to "decipher" what the name `a` or `b` means.
|
A short variable disappears in the code like a real ninja in the forest. No one will be able to find it using "search" of the editor. And even if someone does, he won't be able to "decipher" what the name `a` or `b` means.
|
||||||
|
|
||||||
|
@ -83,17 +83,19 @@ While choosing a name try to use the most abstract word. Like `obj`, `data`, `va
|
||||||
|
|
||||||
- **Name a variable by its type: `str`, `num`...**
|
- **Name a variable by its type: `str`, `num`...**
|
||||||
|
|
||||||
Give them a try. A young ninja may wonder -- do such names make the code worse? Actually, yes!
|
Give them a try. A young initiate may wonder -- are such names really useful for a ninja? Indeed, they are!
|
||||||
|
|
||||||
Sure, the variable name still means something. It says what's inside the variable: a string, a number or something else. But when an outsider tries to understand the code, he'll be surprised to see that there's actually no information at all!
|
Sure, the variable name still means something. It says what's inside the variable: a string, a number or something else. But when an outsider tries to understand the code, he'll be surprised to see that there's actually no information at all! And will ultimately fail to alter your well-thought code.
|
||||||
|
|
||||||
Indeed, the value type is easy to find out by debugging. But what's the meaning of the variable? Which string/number does it store? There's just no way to figure out without a good meditation!
|
The value type is easy to find out by debugging. But what's the meaning of the variable? Which string/number does it store?
|
||||||
|
|
||||||
|
There's just no way to figure out without a good meditation!
|
||||||
|
|
||||||
- **...But what if there are no more such names?** Just add a number: `data1, item2, elem5`...
|
- **...But what if there are no more such names?** Just add a number: `data1, item2, elem5`...
|
||||||
|
|
||||||
## Attention test
|
## Attention test
|
||||||
|
|
||||||
Only a truly attentive programmer should be able to understand the code. But how to check that?
|
Only a truly attentive programmer should be able to understand your code. But how to check that?
|
||||||
|
|
||||||
**One of the ways -- use similar variable names, like `date` and `data`.**
|
**One of the ways -- use similar variable names, like `date` and `data`.**
|
||||||
|
|
||||||
|
|
|
@ -411,8 +411,8 @@ So, "49" is an integer property name, because when it's transformed to an intege
|
||||||
```js run
|
```js run
|
||||||
// Math.trunc is a built-in function that removes the decimal part
|
// Math.trunc is a built-in function that removes the decimal part
|
||||||
alert( String(Math.trunc(Number("49"))) ); // "49", same, integer property
|
alert( String(Math.trunc(Number("49"))) ); // "49", same, integer property
|
||||||
alert( String(Math.trunc(Number("+49"))) ); // "49", not same ⇒ not integer property
|
alert( String(Math.trunc(Number("+49"))) ); // "49", not same "+49" ⇒ not integer property
|
||||||
alert( String(Math.trunc(Number("1.2"))) ); // "1", not same ⇒ not integer property
|
alert( String(Math.trunc(Number("1.2"))) ); // "1", not same "1.2" ⇒ not integer property
|
||||||
```
|
```
|
||||||
````
|
````
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue