-
Notifications
You must be signed in to change notification settings - Fork 30.2k
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
crypto: fix duplicated switch-case return values #49030
Conversation
Review requested:
|
While it technically reduces the number of statements, I don't really see how this improves the code or its readability. |
I see the concern, but grouping returning values in a single case reduces redundancy and improves code efficiency, making it easier to maintain and read. Even though it's a minor repetition, this constitutes a code duplication and violates the DRY (Don't Repeat Yourself) principle. As a result, you can already observe instances of the same operation being performed in various parts of the project. Despite the small magnitude of the issue, I still strive to contribute to the project in any way possible. https://github.com/nodejs/node/blob/main/lib/internal/crypto/cfrg.js#L49 And more... |
If this is going to fallthrough would you mind moving the returns on newlines to actually help readability? |
Thank you for your response, I have rearranged the code as you suggested. |
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.
I don't think this improves much but it also doesn't stand to hurt anything.
Failed to start CI- Validating Jenkins credentials ✘ Jenkins credentials invalidhttps://github.com/nodejs/node/actions/runs/5775909236 |
Need to wait until https://nodejs.org/en/blog/vulnerability/august-2023-security-releases is through to start CI and let this progress. |
It is a cosmetic change. I'm approving only because there is another approval. With two approvals we can land it faster without waiting one week. |
I am not sure if it really improves code efficiency, and as @panva said, even if it does, efficiency really doesn't matter much here. I don't think this is an improvement because intuitively this is a one-to-one mapping from algorithms to block sizes. One line per algorithm, the name on the left and the corresponding value on the right. Easily readable and mathematically concise. Grouping algorithms like this makes no sense. The fact that SHA-1 and SHA-256 have the same internal block size is purely coincidental. The algorithms are vastly different. If we keep adding algorithms to the list, this change will effectively demand ordering algorithms by their block size. For example, the SHA-3 bitrates (i.e., block sizes) fall both below and above that of SHA-512, so I guess we'd have to mix SHA-2 and SHA-3 in this list? Anyway, I won't object, but I don't think these changes help. |
Same here. |
FWIW, the commit message still doesn't adhere to the commit message guidelines since it doesn't begin with an imperative verb after the prefix. |
Landed in 2b57e47 |
PR-URL: #49030 Reviewed-By: Filip Skokan <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
PR-URL: #49030 Reviewed-By: Filip Skokan <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
PR-URL: #49030 Reviewed-By: Filip Skokan <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
PR-URL: #49030 Reviewed-By: Filip Skokan <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
PR-URL: nodejs#49030 Reviewed-By: Filip Skokan <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
PR-URL: nodejs#49030 Reviewed-By: Filip Skokan <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
I defined the same returning values within a switch-case under a single case.