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

worker: replace message types string by constants #21537

Closed
wants to merge 1 commit into from

Conversation

starkwang
Copy link
Contributor

@starkwang starkwang commented Jun 26, 2018

This change can prevent typos and redundant strings in code.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines

@nodejs-github-bot nodejs-github-bot added the worker Issues and PRs related to Worker support. label Jun 26, 2018
ERROR_MESSAGE: 'errorMessage',
STDIO_PAYLOAD: 'stdioPayload',
STDIO_WANTS_MORE_DATA: 'stdioWantsMoreData',
LOAD_SCRIPT: 'loadScript'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changing these strings into numbers may have better performance when comparing message.type. Is it worth to do that ?

Copy link
Member

Choose a reason for hiding this comment

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

What about our regular sort of constants kLoadScript kStdioWantsMoreData etc?

@@ -47,6 +47,15 @@ const kIncrementsPortRef = Symbol('kIncrementsPortRef');

const debug = util.debuglog('worker');

const messageTypes = {
UP_AND_RUNNING: 'upAndRunning',
COULD_NOT_SERIALIZEERROR: 'couldNotSerializeError',
Copy link
Member

Choose a reason for hiding this comment

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

I’d maybe add a _ between SERIALIZE and ERROR ;)

Copy link
Member

@benjamingr benjamingr left a comment

Choose a reason for hiding this comment

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

LGTM given the space between SERIALIZE_ERROR

@starkwang starkwang force-pushed the worker-message-types branch from 9f6c5d6 to 91307e5 Compare June 26, 2018 14:05
@@ -47,6 +47,15 @@ const kIncrementsPortRef = Symbol('kIncrementsPortRef');

const debug = util.debuglog('worker');

const messageTypes = {
UP_AND_RUNNING: 'kUpAndRunning',
COULD_NOT_SERIALIZ_EERROR: 'kCouldNotSerializeError',
Copy link
Member

Choose a reason for hiding this comment

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

I think the _ ended up in the wrong place? ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, my fault /w\

STDIO_PAYLOAD: 'kStdioPayload',
STDIO_WANTS_MORE_DATA: 'kStdioWantsMoreData',
LOAD_SCRIPT: 'kLoadScript'
};
Copy link
Member

Choose a reason for hiding this comment

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

What if we use variables instead of properties of an object? This way, mistakes/typos can be caught at linting time, and errors like the one above COULD_NOT_SERIALIZ_EERROR would be more difficult to make (one has to make it at least twice for it to pass linting).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using variables may not prevent typos like COULD_NOT_SERIALIZ_EERROR because most of developers are using auto complete when coding. Using properties of an object can make developer benefits from the auto complete (just type messageTypes. and these constants will be showed)

This change can prevent typos and redundant strings in code.
@starkwang starkwang force-pushed the worker-message-types branch from 91307e5 to c502795 Compare June 27, 2018 02:07
@starkwang
Copy link
Contributor Author

@starkwang
Copy link
Contributor Author

Landed in ebf5b58

@starkwang starkwang closed this Jun 29, 2018
starkwang added a commit that referenced this pull request Jun 29, 2018
This change can prevent typos and redundant strings in code.

PR-URL: #21537
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
targos pushed a commit that referenced this pull request Jun 29, 2018
This change can prevent typos and redundant strings in code.

PR-URL: #21537
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
@targos targos mentioned this pull request Jul 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
worker Issues and PRs related to Worker support.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants