Hacker News new | ask | show | jobs
by Cushman 5418 days ago
Summary: No.

Long version: There are a number of ways which are lexically shorter, do the same thing only assuming that v is already either 0 or 1, are not self-documenting, and perform worse or marginally better at best. Only a very tortured definition would call any of these things "better".

Although v = v ? 0 : 1 isn't that bad.

1 comments

Actually the "v = (v + 1) % 2" approach has merit -- in the past I've had to write MHEG textual notation, which is a declarative language where the syntax for conditionals is phenomenally ugly and ludicrously verbose, and this method is vastly more concise (2 lines versus about 10)