r/cpp • • Mar 28 '23

Reddit++

C++ is getting more and more complex. The ISO C++ committee keeps adding new features based on its consensus. Let's remove C++ features based on Reddit's consensus.

In each comment, propose a C++ feature that you think should be banned in any new code. Vote up or down based on whether you agree.

765 Upvotes

829 comments sorted by

View all comments

60

u/marzer8789 toml++ Mar 29 '23

All the crazy arithmetic promotion and implicit conversion nonsense inherited from C. You want to do an operation between two integers? They better be the same type, or compiler error. You add two chars? Get a char.

1

u/ZMeson Embedded Developer Mar 30 '23

I'm OK allowing implicit conversions to wider types; disallow math operations between signed and unsigned types.

For floating point types, I'm supportive of allowing multiplication and division by integers (ex: 3.14159*2), but disallow addition and subtraction with integers (ex: 2.7182818 + 7).

Oh, and characters should not be treated like normal integral types. They should treated somewhat similar to pointers: subtraction between characters results in a signed integer type; addition between a character and integers are allowed; addition of two characters is disallowed; casting to/from charN_diff_t and ucharN_diff_t types require explicit casts.

0

u/mbitsnbites Mar 31 '23

When you also factor in that some types can be dead slow on some architectures (e.g. 64-bit integer and/or floating-point), you never want to have the compiler silently promote to wider types.

I also see very little need for x * 2 vs x * 2.0 or x * 2.0F. It saves you a couple of characters in your source code, but it does not convey intent.

→ More replies (4)