Skip to content

Commit 47f7e5a

Browse files
committed
Don't overoptimize
1 parent c713bc2 commit 47f7e5a

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

README.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,6 @@ createMenu(menuConfig);
325325
**[⬆ back to top](#table-of-contents)**
326326

327327

328-
329328
### Don't use flags as function parameters
330329
Flags tell your user that this function does more than one thing. Functions should do one thing. Split out your functions if they are following different code paths based on a boolean.
331330

@@ -379,7 +378,6 @@ function splitIntoFirstAndLastName() {
379378
}
380379

381380
console.log(name); // ['Ryan', 'McDermott'];
382-
383381
```
384382

385383
**Good**:
@@ -622,6 +620,32 @@ function combine(val1, val2) {
622620
```
623621
**[⬆ back to top](#table-of-contents)**
624622

623+
### Don't over-optimize
624+
Modern browsers do a lot of optimization under-the-hood at runtime. A lot of
625+
times, if you are optimizing then you are just wasting your time. [There are good
626+
resources](https://github.com/petkaantonov/bluebird/wiki/Optimization-killers)
627+
for seeing where optimization is lacking. Target those in the meantime, until
628+
they are fixed if they can be.
629+
630+
**Bad:**
631+
```javascript
632+
633+
// On old browsers, each iteration would be costly because `len` would be
634+
// recomputed. In modern browsers, this is optimized.
635+
for (var i = 0, len = list.length; i < len; i++) {
636+
// ...
637+
}
638+
```
639+
640+
**Good**:
641+
```javascript
642+
for (var i = 0; i < list.length; i++) {
643+
// ...
644+
}
645+
```
646+
**[⬆ back to top](#table-of-contents)**
647+
648+
625649
## **Objects and Data Structures**
626650
### Use getters and setters
627651
JavaScript doesn't have interfaces or types so it is very hard to enforce this

0 commit comments

Comments
 (0)