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

replace wierd syntax with clear expression #4814

Merged

Conversation

thst71
Copy link
Contributor

@thst71 thst71 commented Feb 6, 2022

The use of !~ hides the completely understandable apiKeys.indexOf(key) < 0 or if(!apiKeys.includes(key)).
Since this is example code, this should be crisp and clean.
I don't see any advantage or improvement in the use of a "bitwise negation of -1 is 0 and thus falsy, so I can use a boolean not on it for my if statement" to replace a straight "result is less than 0". I even would consider it is slower than a simple compare, since it's two operations. The newer API (includes) is even more literate in coding style.
I suggest this is fixed.

Copy link
Contributor

@dougwilson dougwilson left a comment

Choose a reason for hiding this comment

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

Thank you. The examples are typically in the style of who contributed them. I suggest though using a different API than .includes so we can merge into the 4.x branch (see CI failures).

@dougwilson
Copy link
Contributor

FYI, you can ignore the CI failures; a transient dependency just published a version that broke it; I'll get that addressed when I get home and otherwise your PR I think is good to go.

Copy link
Member

@LinusU LinusU left a comment

Choose a reason for hiding this comment

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

Neat 👍

@dougwilson dougwilson force-pushed the thst71-removes-use-arcane-syntax branch from 9bb1a59 to bb26325 Compare February 7, 2022 23:39
Copy link
Contributor

@dougwilson dougwilson left a comment

Choose a reason for hiding this comment

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

Thank you for taking the time to help improve our examples!

@dougwilson dougwilson closed this in bb26325 Feb 8, 2022
@dougwilson dougwilson merged commit bb26325 into expressjs:master Feb 8, 2022
dougwilson pushed a commit that referenced this pull request Feb 8, 2022
himanshiLt pushed a commit to himanshiLt/express that referenced this pull request Jun 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants