The Wayback Machine - https://web.archive.org/web/20201116180452/https://github.com/ryanmcdermott/clean-code-javascript/pull/127
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: iterator variable names #127

Open
wants to merge 1 commit into
base: master
from

Conversation

@cookiengineer
Copy link

@cookiengineer cookiengineer commented Jan 12, 2017

Pull request as discussed in issue #49

@vsemozhetbyt
Copy link
Contributor

@vsemozhetbyt vsemozhetbyt commented Jan 13, 2017

Something to be considered:

  1. Does not the length caching contradict the Don't over-optimize example?
  2. Some style features are not matched with the style of the other examples: space between array elements, two spaces for indentation, blocks are not padded with empty lines, const for not reassigned variables (k in the bad example; entry, object and o in the good one).
Copy link
Owner

@ryanmcdermott ryanmcdermott left a comment

This is looking like a great addition! I've left some comments.

@@ -146,6 +146,50 @@ locations.forEach((location) => {
```
**[ back to top](#table-of-contents)**

### Avoid Mental Mapping of iterator states

This comment has been minimized.

@ryanmcdermott

ryanmcdermott Jan 16, 2017
Owner

Can you call this "Avoid Mental Mapping (part 2)" and call the one before it "Avoid Mental Mapping (part 1)".

Nested high-performance loops can get confusing if you use incremental
letters for iterator variables. Mental mapping overhead can be reduced
when using the leading prefix letter (`d` for dataset) as the iterator
and the same name + l (`dl` for dataset) as the length or loop's

This comment has been minimized.

@ryanmcdermott

ryanmcdermott Jan 16, 2017
Owner

Can we remove the dl for dataset length. It does kind of go slightly against the don't over-optimize section.

```javascript
const dataset = [[{ foo: [1,2,3,4] }], [{ foo: [1,2,3,4] }]];
for (let d = 0, dl = dataset.length; d < dl; d++) {

This comment has been minimized.

```javascript
const dataset = [[{ foo: [1,2,3,4] }], [{ foo: [1,2,3,4] }]];
for (let i = 0, l = dataset.length; i < l; i++) {

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants
You can’t perform that action at this time.