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

More refactorings #446

Merged

Conversation

jamesadarich
Copy link
Member

@jamesadarich jamesadarich commented Jan 24, 2018

Description

Make more improvements recommended by code climate

Checklist

  • I am an awesome developer and proud of my code
  • I added / updated / removed relevant unit or integration tests to prove my change works
  • I ran all tests using npm test to make sure everything else still works
  • I ran npm run review to ensure the code adheres to the repository standards

@@ -4,6 +4,10 @@ import { InvalidTimeoutValueError } from "./errors/invalid-timeout-value-error";
import { MissingArgumentValueError } from "./errors/missing-argument-value-error";
import { Unused } from "../core/unused";

function removeItemByIndex(array: Array<any>, index: number) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please put this in another file.

}

function outcomesContains(outcomes: Array<TestOutcome>, outcome: TestOutcome) {
return outcomes.some(o => o === outcome);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks as though indexOf is faster than some - why not use that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More readable I think unless you disagree?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • I've just benchmarked the function in question on node over a billion iterations ran 10 times shows only a 15% slowdown using some. Perhaps browsers are more affected?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For context the average time for execution is ~ 160ns (yep nano :) ) I'm not sure we'd manage to gain enough performance for the readability

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that arr.indexOf(x) !== -1 is quicker to glance at and see what's going on but that's probably only because it's syntax that I've used for years while arr.some(i => i === x) is fairly new.

Happy to keep some though

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd keep some for readability too. Even though indexOf(x) !== -1 has been used for years, I would favour a semantically nicer approach like list.contains(x) currently some is your best bet.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@7jpsan thanks for you input :) good to see you on here!!

@jamesadarich
Copy link
Member Author

Sorry @Jameskmonger forgot to put a note this is still in progress as trying to get feedback from code climate.

@jamesadarich
Copy link
Member Author

@Jameskmonger I think that should do for now - some more refactors available but nailed a lot of the bigger ones so everything should be mainly an "A" now :)

@jamesadarich
Copy link
Member Author

Happy with this one @Jameskmonger ?

@Jameskmonger
Copy link
Contributor

LGTM @jamesrichford. I can't merge due to codeclimate.

@jamesadarich jamesadarich merged commit c9dc815 into alsatian-test:master Jan 26, 2018
@jamesadarich jamesadarich deleted the refactor/code-climate-suggestions branch January 26, 2018 23:14
@jamesadarich
Copy link
Member Author

@Jameskmonger thanks - should all be automatic checks from now on :)

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

Successfully merging this pull request may close these issues.

None yet

3 participants