3 ms·
What kind of monster writes i += 1?
by alayne 12y ago
What kind of monster writes i += 1?
- psuter 12y agoAmong others, people who have learned to take JSLint a little too seriously [1]. [1] http://stackoverflow.com/questions/971312/why-avoid-increment-and-decrement-operators-in-javascript http://stackoverflow.com/questions/971312/why-avoid-incremen...
- agildehaus 12y agoPython devs :)
- Igglyboo 12y agoAnyone who writes python
- neurobro 12y agoI do, only because I've never seen a convincing case where unary increment/decrement improves the code in any way (and I've searched).
- nkeets 12y agoSo, what convincing cases have you find of i += 1 over i = i + 1?
- neurobro 12y agoIt reduces code redundancy, especially when 'i' is something more descriptive. Though if someone were to claim that the redundancy of i=i+1 is a trivial price for settling on one consistent multipurpose construct, I wouldn't put up a fight. :)
- exogen 12y agoConsider a more descriptive variable name and hopefully it becomes obvious: sheepCounted += 1 vs. sheepCounted = sheepCounted + 1
- Someone 12y agoIt can easily get way worse once you consider classes and their properties: pInterface->m_someField[currentItem] += 1;