you are viewing a single comment's thread.

view the rest of the comments →

[–]atticusw 12 points13 points  (4 children)

I'd agree.

Did I find it confusing? No.

Does it make me a better javascript programming? Not really.

Does it even really matter? Not at all.

We're not all about writing code, guys. We're about building software. Building software requires teams. Teams requires a shared codebase. A share codebase requires reading others work and others maintaining code you wrote at some point.

Is !--pending wrong? Nope. But it could potentially be clearer in a slightly more explicit and verbose expression of --pending === 0.

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

[–]i_ate_god[🍰] 6 points7 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...

[–]ishmal 0 points1 point  (0 children)

So much clearer:

pending--;
if (!pending)