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

Charles: compareFunc is vague in naming and implementation #26

Open
eric-do opened this issue Nov 12, 2021 · 0 comments
Open

Charles: compareFunc is vague in naming and implementation #26

eric-do opened this issue Nov 12, 2021 · 0 comments

Comments

@eric-do
Copy link

eric-do commented Nov 12, 2021

Couple things:

  • Try to make your functions pure as possible
  • Avoid making the reader jump through mental hoops

When looking at your code, I don't know what compareFunc compares, and it was a surprise to me when I saw its use as compareFunc().map(). It's surprising that it returns an array, since its name implies it'd be used as a callback. E.g. someone would expect something like, compareFunc(a, b) => return a > b

Something like compareAndReturnFeatures, getUniqueFeatures, etc. would be more clear.

Avoid having 'magic numbers'. I have no idea what arr[0] and arr[1] are - set variables instead so the reader doesn't have to guess.

Try to use array methods like .forEach, .map, .filter, etc. as much as you can. Imperative for-loops are difficult to read and can be error prone in implementation. Even for

for (let i = 0; i < currentProductFeatures.length; i++) {
  setFeatures[currentProductFeatures[i].feature] = [currentProductFeatures[i].value];
}

It's just easier to read

currentProductFeatures.forEach(feature => setFeatures[feature.feature] = [feature.value]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant