|
|
|
|
|
by tialaramex
1402 days ago
|
|
Before Swift 3 the language has the very stupid increment/ decrement operator pairs. In C these operators, paired with pointer arithmetic, allow you to write either incredibly terse yet correct implementations (e.g. strcpy as one liner) or more often in practice, conceal horrible defects where your code is hard enough to read that nobody spots the mistake. If it is the 1970s where you are, your CPU might have an increment instruction, and your compiler might not be smart enough to spot that x += 1; is also an increment. So when C was invented this isn't crazy at all. C++ inherited them from C, for whatever that excuse is worth in the 1980s. But in a modern language you should either abolish them entirely or, if you can't bear to do that, neuter them enough that most of your programmers won't manage to blow their whole foot off when they try to use them. Swift chose to abolish them. Go keeps an increment operator but you can't use it in expression context, so that way it doesn't have pre/post-increment. So, to me that's pretty obviously an improvement in Swift, even if it's incompatible. |
|