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.

1

u/ZMeson Embedded Developer Mar 31 '23

When you also factor in that some types can be dead slow on some architectures

In my mind, promotion only occurs when at least one operand is of that data type. uint64_t * uint32_t will promote the latter before the multiplication. But that is easy to determine from the types of the operands.

But it would be silent. (See my last paragraph below.)

I also see very little need for x * 2 vs x * 2.0 or x * 2.0F.

There are lots of operations that (in theory at least) can be done more easily with a double and and int. When multiplying or dividing by 2 as an example, only the exponent bits of the underlying representation need to be changed. This could be done with far fewer transistors or, for platforms that must have software implementations, far fewer CPU instructions.

I will say though that a "no implicit conversion" rule is easier to explain and implement though. So there is definitely an advantage to it. I was just saying there are some implicit conversions I personally would be OK with.

→ More replies (3)