Adding terminology for magic literals

This commit is contained in:
Ioannis Brant-Ioannidis 2023-01-24 08:40:48 +04:00
parent bae1b8dec0
commit 36d14bf048

View file

@ -117,9 +117,9 @@ function getUser(): User;
**[ back to top](#table-of-contents)**
### Use searchable names
### Use searchable names / Avoid Magic Literals
We will read more code than we will ever write. It's important that the code we do write must be readable and searchable. By *not* naming variables that end up being meaningful for understanding our program, we hurt our readers. Make your names searchable. Tools like [ESLint](https://typescript-eslint.io/) can help identify unnamed constants.
We will read more code than we will ever write. It's important that the code we do write must be readable and searchable. By *not* naming variables that end up being meaningful for understanding our program, we hurt our readers. Make your names searchable. Tools like [ESLint](https://typescript-eslint.io/) can help identify magic literals.
**Bad:**
@ -131,7 +131,7 @@ setTimeout(restart, 86400000);
**Good:**
```ts
// Declare them as capitalized named constants.
// Declare them as capitalized symbolic constants.
const MILLISECONDS_PER_DAY = 24 * 60 * 60 * 1000; // 86400000
setTimeout(restart, MILLISECONDS_PER_DAY);