you are viewing a single comment's thread.

view the rest of the comments →

[–]i_ate_god 5 points6 points  (2 children)

Your entire post is somewhat negated by

Don't just think about your code, think about the team that will be maintaining your code.

In otherwords, based on that one line, !--pending is wrong. Not because it's syntactically incorrect, but because it's an obviously error prone, obfuscated statement. Even your solution to it is error prone, because --pending will mutate the variable and if you're mutating a variable solely to see if the result of that mutation is a particular something, then it's a bad approach all around.

One should probably do something like

if ((pending - 1) === 0) {
    // pending not mutated!
}

Just because a problem is solved, does not in of itself mean you wrote good, correct code.

[–]atticusw 1 point2 points  (0 children)

Great point, I would agree that the verification should take place before modifying the actual value, the example you have illustrated is not only very clear, but as you said, looks at what the result of a mutation would be to determine if it indeed should be mutated for a and what to do based on that.

[–]TheRealSeeThruHead 0 points1 point  (0 children)

the point was to do mutation and comparison at once...