After reading Hidden Features and Dark Corners of C++/STL on comp.lang.c++.moderated, I was completely surprised that the following snippet compiled and worked in both Visual Studio 2008 and G++ 4.4.
Honestly, I’m not sure which I think is worse. Having an explicit down-to operator or being able to combine operators in a way that confuses experienced programmers.
I’d argue the problem here is more the unary (in/de)crement operator. It isn’t really necessary and most of the time it doesn’t make stuff more readable.
It wouldn’t have surprised me at all, if they did (they love their keywords), but that one actually isn’t a keyword. It’s an extension method implemented for the various number types, so you can also write 5.downTo(1).
Honestly, I’m not sure which I think is worse. Having an explicit down-to operator or being able to combine operators in a way that confuses experienced programmers.
This kind of combined operators are quite common in the competitive programming world, where the speed of coding is more important than readable.
Yeah, still horrid for real-world programming, though, where readability is ten times as important as how quickly you can type it out.
I’d argue the problem here is more the unary (in/de)crement operator. It isn’t really necessary and most of the time it doesn’t make stuff more readable.
It is readable.
Thanks.
Kotlin has one (well, more like keyword, but aren’t operators just keywords written in non-alphabetic)
downTo
It wouldn’t have surprised me at all, if they did (they love their keywords), but that one actually isn’t a keyword. It’s an extension method implemented for the various number types, so you can also write
5.downTo(1)
.