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

lib: remove unnecessary symbols #22455

Closed
wants to merge 1 commit into from
Closed

lib: remove unnecessary symbols #22455

wants to merge 1 commit into from

Conversation

ghost
Copy link

@ghost ghost commented Aug 22, 2018

Remove (...), because this is a simple,sensitive expression.

  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows [commit guidelines]

@nodejs-github-bot nodejs-github-bot added the stream Issues and PRs related to the stream subsystem. label Aug 22, 2018
@@ -325,7 +325,7 @@ Readable.prototype.setEncoding = function(enc) {
// Don't raise the hwm > 8MB
const MAX_HWM = 0x800000;
function computeNewHighWaterMark(n) {
if (n >= MAX_HWM) {
if (n > MAX_HWM) {
Copy link
Member

@Trott Trott Aug 22, 2018

Choose a reason for hiding this comment

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

This change causes the else branch to be taken when n is equal to MAX_HWM. That seems less efficient then the if branch. and possibly a bug?

Copy link
Author

Choose a reason for hiding this comment

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

OK, Thanks I've removed that modification.

Remove `(...)`, because this is a simple,sensitive expression.
@richardlau
Copy link
Member

This appears to be the sort of stylistic changes being discussed in #22351.

@ghost
Copy link
Author

ghost commented Aug 22, 2018

@richardlau:But you have to admit that this (……) is useless here.
And this makes your style not in union :)

Please compare with them:

  1. isDuplex = stream instanceof Stream.Duplex;

  2. const isDuplex = (this instanceof Stream.Duplex);

So sometimes for those useless styles or styles aren't necessary (But not change to a style that will make bad effects on what the codes were). I think it worth changing to make tiny (but not much) refactors.

Hope you can understand what I mean here.

@BridgeAR
Copy link
Member

BridgeAR commented Aug 22, 2018

I am -0.5 on this. There might be a eslint rule for this and it would be fine for me with a rule if that does not result in to much churn.

@mscdex
Copy link
Contributor

mscdex commented Aug 22, 2018

FWIW I generally prefer including conditional statements like this in parentheses when being assigned as a value as it makes it easier to read and that's why these parentheses currently exist there.

@ghost
Copy link
Author

ghost commented Aug 23, 2018

I think it's time to have a disscussion on when to refactor(IMO):

First, as what I said above, refactoring codes cannot make bad effects on what the codes were (including making performance lower than before, making hard to read / understand, or making unit tests too complicated to complete……ect). Anyway, any bad effects resulted by refactoring will be abandoned. And what @richardlau's closed example just belongs to this (because using IndexOf's performance isn't better, even lower than three if's. So this refactor isn't necessary).

Second, to make codes in style union. I mostly agree with what @BridgeAR said, but I have to say that even if when we all pass the eslint's checks, sometimes the stylish still will have useless or unnecessary things to be removed (Just like this fixture above). And the reason why we will do refactoring is that we should clean up codes to make them in union and look better, and obviously our Nodejs project belongs to the developers all over the world. Since we cannot control different people's options of code style, why don't we make them in union for obviously stylish problems? :)

As for @mscdex's suggestions, this is still in discussion. If most of you think for a condition wrapped by (……) —— I mean if the style looks better (though I disagree with that), I'll still make a change according to what you said (Maybe

isDuplex = stream instanceof Stream.Duplex;
should be changed by wrapping it with (……)).

Copy link
Member

@addaleax addaleax left a comment

Choose a reason for hiding this comment

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

I think larger patches are much more relevant when talking about “churn”. A +1/-1 change is not getting in the way of anything – if it can be backported, great, if it can’t, it doesn’t make anything worse either in terms of merge conflicts.

@ghost
Copy link
Author

ghost commented Aug 23, 2018

@addaleax:Yes I agree with you.

And I think for those rules we should refactor codes:

  1. Code styles that makes us feel puzzled, hard to understand.

  2. Codes with useless things or symbols.

  3. Codes with unused parameters, varaiables,……ect.

  4. A function with the same logic but written everywhere when needed, we should take this into a global locaion.

  5. Code styles that makes a huge performance improved (benchmark test can prove this, but what is the defination of a huge performace? 10% or 20%? This needs discussion).

Any other better ideas in details? It's interesting to share ideas and experience with all of you here :D

@addaleax addaleax added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Aug 27, 2018
@addaleax
Copy link
Member

CI: https://ci.nodejs.org/job/node-test-pull-request/16804/

I’d prefer to land this in the next few days rather than having it hang in limbo, given that there are 8 approving reviews at this point.

@Trott
Copy link
Member

Trott commented Sep 1, 2018

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

LGTM

@Trott
Copy link
Member

Trott commented Sep 3, 2018

@ghost
Copy link
Author

ghost commented Sep 11, 2018

Maybe this can be merged?

@Trott
Copy link
Member

Trott commented Sep 11, 2018

@addaleax
Copy link
Member

@tniessen
Copy link
Member

CI was stopped, resuming again... https://ci.nodejs.org/job/node-test-pull-request/17149/

@Trott
Copy link
Member

Trott commented Sep 13, 2018

Only red CI was arm-fanned. Re-run: https://ci.nodejs.org/job/node-test-commit-arm-fanned/3457/

@addaleax
Copy link
Member

Landed in 9c6f59e 😄

@addaleax addaleax closed this Sep 13, 2018
addaleax pushed a commit that referenced this pull request Sep 13, 2018
Remove `(...)`, because this is a simple,sensitive expression.

PR-URL: #22455
Reviewed-By: Weijia Wang <starkwang@126.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@ghost
Copy link
Author

ghost commented Sep 13, 2018

Thanks all for your help!

@ghost ghost deleted the FixTypos branch September 13, 2018 09:37
targos pushed a commit that referenced this pull request Sep 14, 2018
Remove `(...)`, because this is a simple,sensitive expression.

PR-URL: #22455
Reviewed-By: Weijia Wang <starkwang@126.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
targos pushed a commit that referenced this pull request Sep 19, 2018
Remove `(...)`, because this is a simple,sensitive expression.

PR-URL: #22455
Reviewed-By: Weijia Wang <starkwang@126.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
targos pushed a commit that referenced this pull request Sep 20, 2018
Remove `(...)`, because this is a simple,sensitive expression.

PR-URL: #22455
Reviewed-By: Weijia Wang <starkwang@126.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. stream Issues and PRs related to the stream subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.