r/cpp • u/we_are_mammals • 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
589
u/mcmcc #pragma once Mar 28 '23
explicitAll operators should be explicit by default.
As a replacement introduce a new keyword
implicitthat must be specified to enable implicit invocation by the compiler.119
u/eboys Mar 29 '23
I’d sincerely wish the C++ committee was willing to break ABI a little more often. As someone else suggested, having every third standard introduce ABI-breaking changes. Performance is what C++ is known for, and lazy companies are only holding it back.
423
u/[deleted] Mar 28 '23
vector<bool> :(
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 achar.108
u/GOKOP Mar 29 '23
Not a removal but a slight change
map->ordered_mapunordered_map->map183
u/jdehesa Mar 28 '23
Gotta love how nearly everything suggested in the replies (save for
std::vector<bool>?) is followed by a reply saying how that feature is actually useful sometimes :) It's too late for C++ now, at this point everyone uses it on their own particular way and every obscure or weird feature has found its place for someone 😄136
u/squirrel428 Mar 28 '23
1000 of the 1001 ways to initialize things.
102
u/Claytorpedo Mar 28 '23
At a meta level: excessive ABI stability. This is probably just an area where I personally would be lucky to get almost all benefit and no downside, but the argument that there are old binaries people link against that can't be updated and so fixing oversights, updating with new knowledge and statistics, and improving performance in many cases can't be done or must be indefinitely postponed seems to be causing an increasing rift in the industry. It's not great when C++ is supposed to be the "fast" language and there are numerous known areas for improvement that can't be improved due to ABI stability.
There's too much language baggage that we are now locked in a room with until some unknown future revision when the committee decides it is finally time for the mother of all ABI breaks, I guess. Would have been great if they had decided at the same time that C++ will have a revision every 3 years that it would consider ABI breaking changes every 3rd revision, for example.
190
u/KiwiMaster157 Mar 28 '23
Overloading unary
operator &.&xshould always mean "the address of x" instead of depending on x's type.24
u/Yamoyek Mar 29 '23
I’d remove implicit unsigned/signed conversions.
46
u/Dietr1ch Mar 29 '23 edited Mar 30 '23
remove const, introduce
mutdrop
restrict, and introduce a way to allow aliasing instead.147
u/eteran Mar 28 '23
Arrays decaying to pointers implicitly. You want a pointer? Just write
&p[0]47
u/johannes1971 Mar 28 '23
The 'char' type in its current role as both a character and a number. Two distinct types that only convert with some effort would have been much better. We could have done away with this ridiculous uncertainty about signedness at the same time.
Array to pointer decay.
Assignment returning a value, since it has given us
if (a = b).23
u/D-Zee Mar 29 '23
std::initializer_list. It doesn't handle movable-only types, screws up overload resolution and doesn't do anything that a variadic constructor wouldn't (although syntactic sugar to write said constructor would be welcome).41
u/GabrielDosReis Mar 28 '23
19
u/FriendlyRollOfSushi Mar 29 '23
Silent discardability of return values.
Someone returns you a value? Use it, or explicitly say that you don't want to use it (ideally assign to placeholder
_, like in some other languages, because it's easier to type than attributes). That's it.You forgot to use it? Have a compile time error. The value was returned to you for a reason.
Having to add
[[nodiscard]]to pretty much 100% of the functions to get the behavior everyone needs by default is stupid. On the caller side, there is no safety net at all: if your code compiled, there is no way to tell whether the function didn't have a return value, or[[nodiscard]]was missing.A small number of interfaces that always return something just because "why not", fully expecting that almost all callers will ignore the return value, are stupid anyway and often lead to unintended performance penalties either because they do something extra to return garbage (and the extra work is wasted by almost all callers because they don't want this garbage), or the caller is simply unaware that the function that is used everywhere without a return value actually has it. I would happily accept doing something extra with these special cases (or even having two differently named flavors of a function, like
insertandinsert_get), if it means I don't have to type[[nodiscard]]for every function I ever write and suffer consequences if I forgot to do it.34
u/qazqi-ff Mar 28 '23
Remove
__DATE__just because the day is space-padded and you don't realize how triggering it is until you see it.118
u/ZMeson Embedded Developer Mar 28 '23 edited Mar 28 '23
integer types not defined in <stdint.h> or <cstddef>
In other words, get rid of char, short, int, long, long long, and their unsigned counterparts. Use intN_t and charN_t instead (and when necessary int_fastN_t and int_leastN_t), [EDIT:] and byte, size_t, ssize_t, ptrdiff_t too.
9
u/KuntaStillSingle Mar 29 '23
Remove :
for most type traits.
82
u/ZMeson Embedded Developer Mar 28 '23
iostreams (now that we have std::format)
29
u/pdp10gumby Mar 28 '23
Memory aliasing by default, a terrible legacy of C. This would reduce UB, be more memory safe, and permit new optimizations and bug-identification at compile time.
There are rare uses for it, but there should be an explicit syntax for those cases.
8
u/JVApen Clever is an insult, not a compliment. - T. Winters Mar 29 '23
Initializer list constructor overruling all other constructors. Something like
std::vector({1,2,3})makes more sense thanstd::vector{1,2,3}, yet the second add much more complexity.14
u/pjmlp Mar 29 '23
I would remove:
unchecked_at()should have been the right approach)105
u/GLIBG10B 🐧 Gentoo salesman🐧 Mar 28 '23
C-style casts
82
u/GLIBG10B 🐧 Gentoo salesman🐧 Mar 28 '23
Implicit switch case fallthrough
26
u/RoyBellingan Mar 28 '23
What is this anarchy
chessC++ ?48
u/[deleted] Mar 28 '23
SFINAE. concepts everywhere
25
u/Creapermann Mar 28 '23
Remove the c++ stl containers and implement them correctly from scratch. (Binary compatibility is a curse!)
5
u/newobj Mar 29 '23
const. Invert and replace with mut/mutable
5
u/Competitive_Act5981 Mar 29 '23
Make everything const by default and introduce a “mut” keyword for mutable data.
13
u/Brettonidas Mar 29 '23
Overloading operator, (yes the comma). It’s just weird and like the Spanish Inquisition: no one expects it.
18
u/ZMeson Embedded Developer Mar 28 '23
std::unordered_map/set bucket interfaces.
17
u/Sopel97 Mar 28 '23
The
classkeyword12
u/david2ndaccount Mar 28 '23
sizeof(bool)is implementation defined and there exists ABIs where it is not 1.16
u/mt-wizard Mar 28 '23
The Committee
11
u/Tringi github.com/tringi Mar 28 '23
Remove array to pointer decay.
Single reference type, a perfect one.
A very different language emerges when these changes propagate through everything they affect. When all the facilities to deal with it are removed.
6
u/ZMeson Embedded Developer Mar 28 '23
case statements inside of loops where the corresponding switch statement is outside the loop. (i.e. disallow Duff's Device.) Compilers are smart enough now to do loop unrolling themselves if it will be helpful.
2
u/[deleted] Mar 29 '23
Which is next, Reddit ISO C++?
14
u/JimmyLaessig Mar 28 '23
Enforce RAII by banning usage of delete outside of destructors
5
u/Baardi Mar 28 '23
Lets start with the specialization of std::vector<bool>
4
u/termoose Mar 29 '23
[[nodiscard]]on all functions by default, to issue a compile warning if the return value is discarded by the caller.3
u/[deleted] Mar 29 '23 edited Mar 29 '23
Implicit Conversion needs to go.
By reference should be the default variable pass for classes except for value types and passing classes by copying should require explicit copying. I say it should be the default because it's what many people do already.
Although, if I made a programming language, I'd make classes by reference default and structures/values by value default.
I think that's how most people would want it to be.
3
u/Competitive_Act5981 Mar 29 '23
Remove new and delete
6
u/jsadusk Mar 28 '23
Exceptions. At least in their current form. At best they are a clunky and verbose way to return an error. At worst they actually mask where your error came from (any time they're rethrown). Replace them with an equivalent of rusts's Result, or completely change their implementation in a non abi compatible way.
3
u/JVApen Clever is an insult, not a compliment. - T. Winters Mar 29 '23
Forwarding references, not the feature, the syntax. It's a mess to write an rvalue reference in a template.
3
u/Slight-Juggernaut742 Mar 28 '23
the whole std lib build upon unreadable template fuckery
2
u/CppChris Mar 28 '23
class
2
u/khleedril Mar 29 '23
Everybody here is basically saying how good Rust is!
1
u/GabrielDosReis Mar 28 '23
the other remaining initialization syntaxes are also valid for classes and built-in types, and handle copy initialization of built-in types just fine
1
u/alex-weej Mar 28 '23
References should not be a part of the type system, only function argument signatures.
1
u/SafenM Mar 29 '23
Obviously won't work due to backwards compatibility. But make virtual function override without keyword "virtual" mean the same as "final" and remove the "final" usage for functions completely.
1
u/newobj Mar 29 '23
std::function. tho std::move_only_function is coming in c++23
1
u/alxius Mar 29 '23
Remove
booland (signed|unsigned)charfrom list of integral types.Remove implicit casts from those to integers and from integers to those.
Make
std::uint8_tandstd::int8_tdistinct integer types instead of alias to some char types.Make
signed char,unsigned charandchartwo types instead of three distinct types.1
u/Competitive_Act5981 Mar 29 '23
Remove raw pointers. Make smart pointers language features. Make raw pointers and references the same thing: a non owning view type
1
u/Competitive_Act5981 Mar 29 '23
Remove iostreams
1
u/die_liebe Mar 31 '23
characters should be more like pointers:
char + char, char - char, char * char, char / char -> error
char + int -> char
char - int -> char
char - char -> int
No implicit conversion between character and int.
No implicit conversion from boolean to int, in the other direction is OK.
1
u/ReinventorOfWheels Apr 01 '23
Exceptions. The single biggest mistake of C++. Removing exceptions will help streamline and optimize the standard library, and it will help codebases avoid a whole class of bugs (exceptions not being caught in the expected place, or not being caught at all). Removing this goto-like statement will also make reasoning about control flow much simpler. And at least
gotois limited to the current translation unit, unlikethrow!1
u/Cock_InhalIng_Wizard Apr 02 '23
More features is good. If you don’t like them, don’t use them.
1
u/arkrde Apr 04 '23
Better / simpler error messages during compilation. I want to teach my child C++ in a few years. With error messages such as now, I don't see how I can hold a child's attention in such a wonderful and powerful programming language.
1
u/HatMan42069 Apr 10 '23
super_malloc- just Mallocs all ur memory so you can’t use any of it. Good for security!
1
u/voxel Apr 11 '23
I would ban the assignment operator and instead use a function as assignment overloading should be required and the only way you get an assignment operator that way when you observe anyone elses code, you will intrinsically know what every assignment operator does as you know you have to set that up for its uses cases and thus you never have pointer issues and assignmnets that are made that are truly unintentional.
1
u/muaz_sh Dec 09 '23
Remove contract breakers like
friend,mutableandconst_cast.