Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upPlease standardize the long conditions must be extract to a variable, before the if statement, and the minimum length of the variable names #714
Comments
dcousens
closed this
Dec 8, 2016
dcousens
reopened this
Dec 8, 2016
dcousens
added
enhancement
feature request
and removed
enhancement
feature request
labels
Dec 8, 2016
This comment has been minimized.
This comment has been minimized.
|
You're right that the As for the line The readme does say: "Clever short-hands are discouraged, in favor of clear and readable expressions, whenever possible." I don't think we should go so far as to ban one-letter variables, because that would warn on |
feross
closed this
in
2b9afb6
Dec 9, 2016
This comment has been minimized.
This comment has been minimized.
|
Fixed by linking to |
This comment has been minimized.
This comment has been minimized.
|
Okay, the body parser is better example :)
So, I don't know how to write my feeling. Sorry if it doesn't sound
meaningful.
I belive a code beauty, and good only when it readable, and it says what it
doing. The short snippets above are just opposite this idea.
I accept one length variables in loops. It's okay, this is very old "rule".
But I can't accept "i" outside from loops.
X, y, z sound good shorthand for xCoordinate, yCoordinate, zCoordinate, but
it makes harder to the code, and the variables says what are they doing.
I have a legacy code, which contains variable "P_SAL". De you know what is
this? I think no. And what about "parameterSalary"? Have you more
information about the function of this variable?
By the same reason, "x" is coordinate as you
2016. dec. 9. de. 10:11 ezt írta ("Feross Aboukhadijeh" <
notifications@github.com>):
… You're right that the bittorrent-dht package probably isn't the best
example to link from the readme anymore. Since the last refactor it's
gotten quite terse and dense. We can find a better example.
As for the line if (equals(sha1(r.salt ? Buffer.concat([r.salt, r.k]) :
r.k), key)) {, I agree that it would be better if split into more lines.
The readme does say: "Clever short-hands are discouraged, in favor of
clear and readable expressions, whenever possible."
I don't think we should go so far as to ban one-letter variables, because
that would warn on x, y, and z in graphics programs, or even i and j in
for-loops. Line length is also impractical. Sometimes lines need to be long.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#714 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AMfmNhzINQBjSXkvHZYupuwZOgFsnvRbks5rGRs2gaJpZM4LINcs>
.
|
This comment has been minimized.
This comment has been minimized.
|
Sorry, I send accidental :(
So, x is a coordinate, or the missing peremeter from an equation? Or http x
prefixed header? Or force of x-ray? Etc...
2016. dec. 9. du. 7:09 ezt írta ("sarkiroka" <sarki_roka@freemail.hu>):
… Okay, the body parser is better example :)
So, I don't know how to write my feeling. Sorry if it doesn't sound
meaningful.
I belive a code beauty, and good only when it readable, and it says what
it doing. The short snippets above are just opposite this idea.
I accept one length variables in loops. It's okay, this is very old
"rule". But I can't accept "i" outside from loops.
X, y, z sound good shorthand for xCoordinate, yCoordinate, zCoordinate,
but it makes harder to the code, and the variables says what are they
doing.
I have a legacy code, which contains variable "P_SAL". De you know what is
this? I think no. And what about "parameterSalary"? Have you more
information about the function of this variable?
By the same reason, "x" is coordinate as you
2016. dec. 9. de. 10:11 ezt írta ("Feross Aboukhadijeh" <
***@***.***>):
> You're right that the bittorrent-dht package probably isn't the best
> example to link from the readme anymore. Since the last refactor it's
> gotten quite terse and dense. We can find a better example.
>
> As for the line if (equals(sha1(r.salt ? Buffer.concat([r.salt, r.k]) :
> r.k), key)) {, I agree that it would be better if split into more lines.
>
> The readme does say: "Clever short-hands are discouraged, in favor of
> clear and readable expressions, whenever possible."
>
> I don't think we should go so far as to ban one-letter variables, because
> that would warn on x, y, and z in graphics programs, or even i and j in
> for-loops. Line length is also impractical. Sometimes lines need to be long.
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <#714 (comment)>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AMfmNhzINQBjSXkvHZYupuwZOgFsnvRbks5rGRs2gaJpZM4LINcs>
> .
>
|
This comment has been minimized.
This comment has been minimized.
|
@sarkiroka Point taken. Feel free to avoid single letter variables in your code. But I think a rule that bans |
This comment has been minimized.
This comment has been minimized.
That is obviously going to be dependent on your context. E.g let { x, y } = myPosition
// ...Clearly provides context as to let { x: myX, y: myY } = myPosition
// ...But, no one is going to rename This is the same for things like You don't need to be overly verbose This is not something easily resolved with a blanket rule I'm afraid. |
This comment has been minimized.
This comment has been minimized.
|
I see I think. But I think one character length variables obfuscate the code (outside from a loop - as I wrote before) And in an arrow function the hello-world level I accept this is not an easy rule. But I sad if you ignore this important thing. But I can accept this too. |
This comment has been minimized.
This comment has been minimized.
I suppose I don't disagree with this, as
It is a Overall, the problem is that you are attempting to predict the total set of possible contexts and use cases... I don't think we can do anything here. We might as well be throwing warnings on spelling errors. |
sarkiroka commentedDec 8, 2016
I would be sad if this style became the javascript standard code style
some line from sample file
if (equals(sha1(r.salt ? Buffer.concat([r.salt, r.k]) : r.k), key)) {In my opinion this more readable in this format:
or
if (!pong.r || !pong.r.id || !Buffer.isBuffer(pong.r.id) || pong.r.id.length !== 20) {and who understood this snippet?
what mean the
r,r.v,r.korr.sig?Please standardize the minimum length of a variable name - except in for cycle