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

path: replace "magic" numbers by readable constants #18654

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/internal/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

module.exports = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it make sense to group the constants a little more? This module looks like it's a place where more constants could be added so maybe it makes sense to create to group them in a character or char object?

Copy link
Member

Choose a reason for hiding this comment

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

In general I agree but I personally think we should do that when it is time to do so instead of adding something before we need it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kfarnung I agree with @BridgeAR. Besides, I want to refactor similar places in the codebase, so I think I'll do it next time.

Copy link
Contributor

@kfarnung kfarnung Feb 9, 2018

Choose a reason for hiding this comment

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

If we're planning to add more in the future, it makes the scope of any future change smaller and less risky. I don't have a strong feeling either way, mostly just an observation since the new file is simply internal/constants.js and in my experience those sorts of files get out of control before you know it.

// Alphabet chars.
CHAR_UPPERCASE_A: 65, /*A*/
Copy link
Member

Choose a reason for hiding this comment

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

nit: for readability it might help to change these comments to // style

Copy link
Contributor Author

@daynin daynin Feb 9, 2018

Choose a reason for hiding this comment

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

@devdazed what about comment like this: // /? Now it's /*/*/

Copy link
Member

Choose a reason for hiding this comment

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

this is probably more subjective than i realized, i'll leave it up to your judgement 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

I would at least put spaces and quotes around them like /* 'A' */ which also makes the original suggestion less crazy since it would be // '/' which is at least a little clearer.

CHAR_LOWERCASE_A: 97, /*a*/
CHAR_UPPERCASE_Z: 90, /*Z*/
CHAR_LOWERCASE_Z: 122, /*z*/

// Non-alphabetic chars.
CHAR_DOT: 46, /*.*/
CHAR_FORWARD_SLASH: 47, /*/*/
CHAR_BACKWARD_SLASH: 92, /*\*/
CHAR_COLON: 58, /*:*/
CHAR_QUESTION_MARK: 63, /*?*/
};
Loading