I prefer pre because if I ever intend to use an increment in an expression, usually I want the operation to be performed before the expression is evaluated. I believe prefix operators avoid mistakes more.
Also in C++ land:
Because a temporary copy of the object is constructed during post-increment and post-decrement, pre-increment or pre-decrement operators are usually more efficient in contexts where the returned value is not used.
notepad–, which is a multi-platform clone of notepad++ made by a chinese developer for this exact reason
there’s also notepadqq but afaik it’s linux-only
Missed opportunity to call it ++notepad
I believe pre-incrementation is superior to post-incrementation.
you wouldn’t write 2 += notepad would you? i prefer post because it matches the way i’d write all the other stuff like that.
I prefer pre because if I ever intend to use an increment in an expression, usually I want the operation to be performed before the expression is evaluated. I believe prefix operators avoid mistakes more.
Also in C++ land:
https://en.cppreference.com/cpp/language/operator_incdec
fair.
shouldn’t the compiler make that kind of optimization?
https://godbolt.org/z/3dTbzfn68
It does, and i’d assume all production-grade C++ compilers do. I guess it’s just a technicality in the C++ specification
Based on my limited research, it sounds like some optimizations may occur for built-in types, but may not occur for user-defined types.
https://softwareengineering.stackexchange.com/questions/358725/pre-increment-vs-post-increment
https://cplusplus.com/forum/general/102639/
https://stackoverflow.com/questions/38947790/efficiency-of-postincrement-v-s-preincrement-in-c
https://stackoverflow.com/questions/24901/is-there-a-performance-difference-between-i-and-i-in-c
Interesting, thank you!
Wow, incredible stuff.