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

child_process: name anonymous functions #9880

Closed
wants to merge 1 commit into
base: master
from

Conversation

Projects
None yet
8 participants
@brad-decker
Contributor

brad-decker commented Dec 1, 2016

Checklist
  • make -j8 test (UNIX), or vcbuild test nosign (Windows) passes
  • commit message follows commit guidelines
Affected core subsystem(s)

child_process

Description of change

Per #8913 i've named anonymous callback handlers.

I have some mixed styling in here because i'm still going over the message log from #8913 and trying to determine best practices. Is the correct implementation of current anonymous functions just to apply a name to those functions without lifting them out of the function call and using arrow functions?

In particular this file has no arrow functions in it yet, so i would assume we'd want to stick to using:

setTimeout(function name() {}, options.timeout);

over

const name = () => {};
setTimeout(name, options.timeout);

if that's the case is there a preferred naming schema for things like setTimeout? The names on some of these seem to be moving towards the verbose, ex:

child.stderr.addListener('data', function stderrAddListenerCallback(){});

Definitely ready to make changes to this to make it compliant.

Show outdated Hide outdated lib/child_process.js Outdated
@@ -247,17 +247,18 @@ exports.execFile = function(file /*, args, options, callback*/) {
}
if (options.timeout > 0) {
timeoutId = setTimeout(function() {

This comment has been minimized.

@mscdex

mscdex Dec 1, 2016

Contributor

Same here, this could be:

timeoutId = setTimeout(function delayedKill() {
@mscdex

mscdex Dec 1, 2016

Contributor

Same here, this could be:

timeoutId = setTimeout(function delayedKill() {

This comment has been minimized.

@brad-decker

brad-decker Dec 1, 2016

Contributor

👍

@brad-decker

brad-decker Dec 1, 2016

Contributor

👍

Show outdated Hide outdated lib/child_process.js Outdated
@mscdex

This comment has been minimized.

Show comment
Hide comment
@mscdex

mscdex Dec 1, 2016

Contributor

I think arrow functions are fine for the most part, but if they result in the addition of new lines of code, I don't think it's really worth it at that point. Since the purpose is to give better stack traces, just adding a name to the anonymous functions is easiest and requires less change.

Contributor

mscdex commented Dec 1, 2016

I think arrow functions are fine for the most part, but if they result in the addition of new lines of code, I don't think it's really worth it at that point. Since the purpose is to give better stack traces, just adding a name to the anonymous functions is easiest and requires less change.

@brad-decker

This comment has been minimized.

Show comment
Hide comment
@brad-decker

brad-decker Dec 1, 2016

Contributor

@mscdex Thanks for the feedback, working on making those changes now. One question,

var _deprecatedCustomFds = internalUtil.deprecate(function deprecateCustomFds(options) {
  options.stdio = options.customFds.map(function(fd) {
    return fd === -1 ? 'pipe' : fd;
  });
}, 'child_process: options.customFds option is deprecated. ' +
   'Use options.stdio instead.');

this first line is way too long. Do you happen to have a recommendation on function name for this particular callback? Or should I just break to a new line to follow linting and leave a verbose function name?

Contributor

brad-decker commented Dec 1, 2016

@mscdex Thanks for the feedback, working on making those changes now. One question,

var _deprecatedCustomFds = internalUtil.deprecate(function deprecateCustomFds(options) {
  options.stdio = options.customFds.map(function(fd) {
    return fd === -1 ? 'pipe' : fd;
  });
}, 'child_process: options.customFds option is deprecated. ' +
   'Use options.stdio instead.');

this first line is way too long. Do you happen to have a recommendation on function name for this particular callback? Or should I just break to a new line to follow linting and leave a verbose function name?

@mscdex

This comment has been minimized.

Show comment
Hide comment
@mscdex

mscdex Dec 1, 2016

Contributor

Without checking with the linter, I'd be fine with something like:

const _deprecatedCustomFds =
  internalUtil.deprecate(function deprecateCustomFds(options) {

or

const _deprecatedCustomFds = internalUtil.deprecate(
  function deprecateCustomFds(options) {
Contributor

mscdex commented Dec 1, 2016

Without checking with the linter, I'd be fine with something like:

const _deprecatedCustomFds =
  internalUtil.deprecate(function deprecateCustomFds(options) {

or

const _deprecatedCustomFds = internalUtil.deprecate(
  function deprecateCustomFds(options) {
@brad-decker

This comment has been minimized.

Show comment
Hide comment
@brad-decker

brad-decker Dec 1, 2016

Contributor

@mscdex suggested changes implemented. Thanks for your feedback.

Contributor

brad-decker commented Dec 1, 2016

@mscdex suggested changes implemented. Thanks for your feedback.

@mscdex

This comment has been minimized.

Show comment
Hide comment
@mscdex

mscdex Dec 1, 2016

Contributor

LGTM

Contributor

mscdex commented Dec 1, 2016

LGTM

@Trott

This comment has been minimized.

Show comment
Hide comment
Member

Trott commented Dec 1, 2016

@brad-decker

This comment has been minimized.

Show comment
Hide comment
@brad-decker

brad-decker Dec 2, 2016

Contributor

Looks like 3 checks failed. Having a little confusion with navigating the CI results to find the issues/logs to aid in correcting these failures. @mscdex @Trott

Contributor

brad-decker commented Dec 2, 2016

Looks like 3 checks failed. Having a little confusion with navigating the CI results to find the issues/logs to aid in correcting these failures. @mscdex @Trott

@Trott

This comment has been minimized.

Show comment
Hide comment
@Trott

Trott Dec 2, 2016

Member

@brad-decker Looks like somebody thought there was something wrong with CI and terminated a whole bunch of jobs, including this one. (I had started a lot of them because: Code & Learn.) Bummer. Oh well. Here's another one: https://ci.nodejs.org/job/node-test-pull-request/5096/

Member

Trott commented Dec 2, 2016

@brad-decker Looks like somebody thought there was something wrong with CI and terminated a whole bunch of jobs, including this one. (I had started a lot of them because: Code & Learn.) Bummer. Oh well. Here's another one: https://ci.nodejs.org/job/node-test-pull-request/5096/

Show outdated Hide outdated lib/child_process.js Outdated
@lpinca

lpinca approved these changes Dec 2, 2016

Show outdated Hide outdated lib/child_process.js Outdated
child_process: name anonymous functions
Per #8913 i've named anonymous callback handlers,
This commit is just a first stab at this looking
for community feedback on style/naming conventions
@cjihrig

cjihrig approved these changes Dec 3, 2016

@Trott Trott added the code-and-learn label Dec 5, 2016

@Trott

This comment has been minimized.

Show comment
Hide comment
Member

Trott commented Dec 5, 2016

@jasnell

jasnell approved these changes Dec 5, 2016

LGTM! Thank you for the PR and for participating in the code-and-learn!

@brad-decker

This comment has been minimized.

Show comment
Hide comment
@brad-decker

brad-decker Dec 5, 2016

Contributor

Thanks @jasnell

Contributor

brad-decker commented Dec 5, 2016

Thanks @jasnell

jasnell added a commit that referenced this pull request Dec 5, 2016

child_process: name anonymous functions
Refs: #8913
PR-URL: #9880
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
@jasnell

This comment has been minimized.

Show comment
Hide comment
@jasnell

jasnell Dec 5, 2016

Member

Landed in bbed075. Thank you!

Member

jasnell commented Dec 5, 2016

Landed in bbed075. Thank you!

@jasnell jasnell closed this Dec 5, 2016

Fishrock123 added a commit that referenced this pull request Dec 6, 2016

child_process: name anonymous functions
Refs: #8913
PR-URL: #9880
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>

jmdarling added a commit to jmdarling/node that referenced this pull request Dec 8, 2016

child_process: name anonymous functions
Refs: nodejs#8913
PR-URL: nodejs#9880
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment