Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34.2k
lib: refactor internal/util#11404
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: refactor internal/util #11404
Uh oh!
There was an error while loading. Please reload this page.
Conversation
37282b0 to ece8161Comparemscdex commented Feb 15, 2017 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
One thing to keep in mind when inlining functions inside |
jasnell commented Feb 15, 2017
Yeah i was thinking about that. Just in general it would be good to move the function bodies out of the object. |
sam-github commented Feb 16, 2017
I'm not sure the refactor makes it better, just stylistically different. What is more efficient? There are benchmarks for this? |
sam-github commented Feb 16, 2017
modules that do I don't think this kind of sweeping stylistic change is worth doing unless its really compellingly better style or has some compelling functional difference and I'm not sure the "more efficient" style will be noticeable. If we didn't have to backport, I'd have no particular opinion, but sweeping stylistic changes that make backports hard worries me. In contrast, breaking up the absolutely enormous lib/crypto.js is, I think, compellingly better style, easier to read, maintain, etc., so despite the backport cost, I was +1 for that. Here, its not so clear to me. |
vsemozhetbyt commented Feb 16, 2017
@sam-github FWIW: #11430 |
ece8161 to 7ba5f4cComparejasnell commented Feb 17, 2017
@mscdex@sam-github ... so this one we will definitely want to investigate further and hold off on landing. Unlike the other similar changes I've done moving to the |
jasnell commented Feb 17, 2017
I've added the |
3acfcb3 to 1fe0ac8Compare
fhalde left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what is the general practice followed in the node code base. But looks like you've been missing out on semicolons after end of the function block. Looking at the history of the file, function blocks were ended with semicolons.
jasnell commented Feb 21, 2017
semicolons are not required to closing function blocks for regular functions with our linting rules. They are only required on assignments. |
* Use the more efficient module.exports ={} approach * Eliminate some uses of arguments1fe0ac8 to bf29544Comparejasnell commented Apr 20, 2017
@mscdex@sam-github ... I've updated this PR. The perf diff with master compared to 7.9 is negligible. The following is the benchmark comparison results for the normalize encoding method in internal/util: Master to 7.9This PR to 7.9PTAL |
jasnell commented Apr 20, 2017
mscdex commented Apr 20, 2017
You can actually remove |
lib/internal/util.js Outdated
| thrownewError('Unknown signal: '+signal); | ||
| } | ||
| module.exports={ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assigning to exports = as well is more future proof, it allows util functions to refer to each other more easily.
Of the 3 common export styles, at-top, at-definition (what util used to do), and at-bottom,at-bottom remains my least favorite. It lacks the visibility and readability of export at top, and lacks the cohesion of export at time of definition. But if at-bottom is how node.js goes, I'll follow along.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoiding the need to refer to exports.{whatever} is important and is why the various exported functions are all named top level functions (they can refer to each other without the exports. bit). That said, it's harmless to add.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One problem with having it at the top is that you can run into variable definition issues, where you're exporting something that gets defined/set later on in the file. Sometimes you might be able to just pull the definition to the top, but other times the assignment may not be a simple one-liner. So putting it at the bottom means you never have to worry about such issues and doing it the same everywhere is good for consistency.
| functionisError(e){ | ||
| returnobjectToString(e)==='[object Error]'||einstanceofError; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sometimes there is two lines beween definitions, sometimes one, should probably be consisten
sam-github left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAICT from the diff, this is adding new APIs to util, toInteger() and toLength(). Am I misreading?
jasnell commented Apr 20, 2017
The |
jasnell commented Apr 20, 2017
PR Updated to remove the |
sam-github commented Apr 20, 2017
I would prefer for both exports and module.exports to be reassigned, to keep a consistent idiom (and I think it costs nothing). Other than that, LGTM |
lib/internal/util.js Outdated
| returnObject.prototype.toString.call(o); | ||
| } | ||
| // Mark that a method should not be used. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These comments shouldn't be indented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whoops! good catch :-)
jasnell commented Apr 20, 2017
Updated! |
mscdex commented Apr 20, 2017
LGTM if CI is ok with it: https://ci.nodejs.org/job/node-test-pull-request/7560/ |
jasnell commented Apr 20, 2017
Fedora on CI has been a bit challenged today in terms of speed, but everything else looks good. Will get this landed tomorrow assuming there are no issues. |
* Use the more efficient module.exports ={} approach * Eliminate some uses of arguments PR-URL: #11404 Reviewed-By: Sam Roberts <[email protected]> Reviewed-By: Brian White <[email protected]jasnell commented Apr 21, 2017
Landed in 9077b48 |
gibfahn commented Jun 18, 2017
@jasnell is this something we want on v6.x? |
jasnell commented Jun 19, 2017
Only if there's no negative perf hit. |
gibfahn commented Jun 19, 2017
Okay, I'm marking this as don't land, but if anyone is willing to backport (and test the perf) on this then go for it. |
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesAffected core subsystem(s)
internal/util