158 points · by signa11 · 3y ago · 274 comments
My feeling during the read, and my definite conclusion afterwards, is that I didn't read a collection of new nice additions to the language, but a list of minefields and new fancy ways to crash your program. That there is no chapter which doesn't end up being a list of gotchas. Seemingly every new feature was added as an extension of the language's reputation of being a shotgun that loves your feet. "Oh, now we have lambdas! here are the 32 ways you can fail while using them, and the language will do nothing to help you prevent".
Effective Modern C++ is a very well written book and very instructive. Its flaws are none of the book or writer, but of the language itself.
C++ is a large, intricate language with features that interact in complex and subtle ways, and I no longer trust myself to keep all the relevant facts in mind. As a result, all I can do is thank you for your bug report, because I no longer plan to update my books to incorporate technical corrections. Lacking the ability to fairly evaluate whether a bug report is valid, I think this is the only responsible course of action.
https://scottmeyers.blogspot.com/2018/09/the-errata-evaluati...
That's a wildly exaggerated take. Working on something to improve user experience and simplify it is not nor it ever was the same as something getting out of hand. This take is even more absurd when we notice that the main goal of cppfront is to serve as a testing ground ti explore backwards incompatible changes to understand if they actually improve the language. Cppfront is the answer to "why not" questions when ignoring constraints deriving from backwards compatibility.
How usable is it ? Is it closer to a a Proof of concept or a finished tool ?
That being said I feel Rust has a lot of paper cuts that slow people down too. Perhaps the silver lining is that they are more like barricades than minefields.
Beginners, count your blessings. You don't need to unlearn other languages before learning Rust.
I sincerely believe the only keywords common to Rust and C are a few control flow keywords (for, if, while; but not switch, goto, or do-while) and "bool"---the latter only because of C99 and stdbool.h
https://doc.rust-lang.org/reference/keywords.html https://en.cppreference.com/w/cpp/keyword
And they're even both provided in (mostly) alphabetical order, which makes this easier for humans
Rust doesn't reserve type names as keywords, which seems like an eccentric choice in C++ (e.g. wchar_t is a keyword!) although perhaps given how fraught parsing is in C++ they had no choice.
The common keywords are: break, const, continue, else, enum, extern, false, for, if, return, static, struct, true, union and while.
true and false are just boolean values, although given C++ like many languages considers "false" to be true, and 0 to be false, I guess it's a surprise they bothered making these keywords.
const, enum, union, static, and struct are about types and values. The choice to have "const" mean "immutable" not "constant" in C++ is hilarious, yeah that's going to cause wider issues in how your programmers understand software. I think C++ enum is rather sad, here's a whole kind of type and it's basically abandoned, it's not allowed to have features the other types have, for no discernible reason. Rust's enum really shows how much opportunity was wasted there.
break, continue, else, for, if, return and while are indeed control flow keywords, although what they do in Rust varies quite a lot from C++. Rust's for is a for-each, it consumes an Iterator (literally, it's a syntax sugar for a loop which uses IntoInterator::into_iter and breaks when the iterator is exhausted) and Rust's break can break-label-value, which is a violently different thing than the C++ break even though the obvious beginner syntax looks identical.
try, do and virtual are reserved in Rust but are not currently used (in stable Rust) to mean anything, we can expect that try is likely to some day be used for a related but different purpose to its cousin in C++.
I think readability is a major part why java was hugely successful: C programmers could read java code and immediately understand what the code did and able to make minor modifications to the code.
This is very difficult with Rust code. Rust "learned" too much from Perl in this regard.
You just are exposed to different languages than what was used as the base.
As a Rust newby I think they are more like achievements that unlock new capabilities.
This is a nice one ;)
I also agree that the new features seem to embrace and extend the "footgun-ness" of C++, rather than attempt to fix it.
That's much easier to do when the tasks that the language is suitable for are bounded in some way.
There are not many common idioms that are going to be shared (beyong libstdc++) between a realtime audio processing application and a data visualization backend for the web and an embedded system control app and a payroll processing backend.
An example of a language with a smaller domain which makes its idioms obvious through its design is Ruby.
An example of a high-performance language that can be used for all those things that makes its idioms obvious through its design is Rust. Another would be, imo, C.
> There are not many common idioms that are going to be shared (beyong libstdc++) between a realtime audio processing application and a data visualization backend for the web and an embedded system control app and a payroll processing backend.
I also just generally have to disagree with it, but you seem to be using a different definition of idiom to me. From what you said here, you seem to take idiom to be synonymous with "design decision". For me, an idiom is a specific semantic construct, possibly associated with specific syntax, that achieves a specific basic programming task. For example, the idiomatic way to loop with an index in Python is to use enumerate.
It's merely the way that most people do the basic things, in a way that is actually good to do. C++ is infamous for a huge number of people using the language dangerously, to the point where there are effectively no idioms outside of specialist communities, and to find them out you need to read books. A significant amount of the basic design of the language needs to be ignored for most purposes.
I don't think that's a reasonable take on both the book and C++11/c++14. `Effective Modern C++` is not an intro tutorial, but a book dedicated to trivial and nontrivial gotchas, none of which leads your program to crash. Worst case scenario you just get a compiler error of your own doing, and that's it. I mean, the book covers stuff like the importance of using nullptr instead of NULL, why braced initialization is nice, why and how smart pointers should be used to implement a pimpl, etc. This is hardly mine field territory, and it makes absolutely no sense at all to use these tidbits of all things to justify switching to an entirely new programming language.
My understanding at the time of publication was that there was no shipping compiler that could deal with his implementation library for the book, "Loki".
My impression of C++ changes since then has not been that they were adding new capabilities, but rather trying to add proper ways to achieve the desired compile time/runtime/memory behavior without resorting to (at least as much) arcane template metaprogramming.
No you don't. A tuple needs to be declared once. Then everything else is sugared.
#include <string>
#include <tuple>
using Foo = std::tuple<int, std::string, float>;
Foo foo(int a, const char* b, double c)
{
return {a,b,c};
}
Foo bar(long);
double baz(long x) {
const auto [a, b, c] = bar(x);
return c;
}
godbolt: https://godbolt.org/z/exdsb4hqbNote that the return part of this (foo()) worked as far back as C++11. Only the structured bindings on the receiving side (baz) requires C++17.
auto get_multiple_values(const bool condition)
-> std::tuple<bool, int>
{
if (condition) {
return {true, 5};
}
return {false, 0};
}
void foo()
{
auto [status, value] = get_multiple_values(true);
}For this reason, some prefer a “auto almost everywhere” style, in which you preferentially use trailing return types.
it is known as sticky syntax in relation to auto (but specifically when the type on the rhs is explicitly declared and not abstracted away with a function signature)
it removes narrowing, inference, while keeping benefits of auto related to inits etc.
it's a way of telling the compiler we want this type moving forward and adheres to the convention of right-to-left reading w.r.t. resource allocation semantics C++ programmers are often accustomed to.
Then once that was opened some folks felt it would be better to write their regular code that way too.
Ehh... not putting a return type in at all is a bridge to far IMO. Be friendly to the casual reader of the code, and help them understand what the function returns. (Yes I know IDE's can do this for you, but not everyone uses an IDE, and not everyone is reading the code in the context of an IDE... for instance code review, etc.)
auto foo() {
struct Result { int a; int b; int c; };
return {1,2,3};
}
//....
auto [a,b,c] = foo();I love the language overall. Seems like standard & easier management of dependencies and compiler flags would help it thrive again.
The example I always use: you want to use libfftw ("Fastest Fourier Transform in the West"). But the library can be compiled with (at least) two options: use floats or doubles, use threads or not. That creates (at least) four possible variants of the final library.
The only way to address this (and IIUC, Cargo for Rust does this) is to somehow have the pkg manager be a part of your build system, so that you end up with a local copy of the library, built as required.
Meson did that. You can use system packages, define your own dependency, use sub-projects (custom build option a, you mentioned) or readily available from WrapDB.
Kind of an uphill struggle this one, because there's no standard implementation of the language, nor is there a standard build system. You have to deal with multiple vendors, one of whom is Microsoft and many of whom are unwilling to change rapidly.
The dependency declaration and auto-detection is nice. But the hidden extra is WrapDB, built-in package management (if wanted):
https://mesonbuild.com/Wrap-dependency-system-manual.html
https://mesonbuild.com/Wrapdb-projects.html1. The build in step-by-step rather than end-to-end. Meaning that you first build Boost completely, then Qt, and then your application. With an end-to-end build you would build everything with a single build system invocation with the build system "seeing" the entire build graph. In particular, this would allow you to build only what's necessary and faster.
2. If something goes wrong in one of these dependencies, you better be prepare to become an expert in whatever build system it uses.
If you want a true Cargo-like experience in C++, a better option would be build2, which replaces rather than wrapps the build system (and, yes, it has Boost and Qt packages): https://build2.org
For more details on what an end-to-end build can give you, see: https://build2.org/faq.xhtml#why-package-managers
Probably my top footgun for C++ is implicit copy construction by default. Every class gets a copy constructor by default unless it opts out. When a copy constructor exists, it can be used implicitly and silently for casting and other contexts. Implicitly copying big objects like std::string or std::vector can be a huge, silent waste of time - whereas in Rust you must explicitly call `.clone()`.
> const is not the default
Agreed with this footgun. The old C and C++ ways are to be permissive by default, to be strict after adding more words.
As another example, top-level variables and functions are exported by default unless prefixed with `static`. Whereas in Java, Rust, etc., you need `public`/`pub` to export, nothing to keep private.
Another huge footgun is the collection of all the undefined behaviors from integer overflow to null dereferencing to creating out-of-bounds pointers to buffer overflows.
between figuring out CMake scripts, std::optional being basically useless. I never feel done writing code because I don't feel like I have:
1. Checked all the exceptions
2. Checked all the places where my std::optional instance is null (the checks doesn't propagate their information)
3. Checked that I am not doing any implicit conversion.
4. Really understand what happens at overflow?
5. Really understand if my code is even UB free?
6. Debugging is a mess, I can't step through code because the smartass compiler removes an entire segment of code even in debug mode.
7. I wish this garbage is written in C instead. At least its honest that its primitive and sinful, unlike this LARPING high level language.
Only 2 things need to be true for this language to be permanently horrible: Hyrum's Law and backward compability. If it is possible to write bad code, then there will be bad code. Simple as. Doesn't matter how many guidelines you write or how many times you need to "teach" programmers or how many times you said people just need to be "better mkayyy?"
Congratulations! That is the correct answer. Welcome to the language.
If you don't need to use C++, don't.
You need C++ for stuff like computer graphics, computational geometry, plausibly scientific computing, games and so on.
"6. Debugging is a mess, I can't step through code because the smartass compiler removes an entire segment of code even in debug mode."
Visual Studio is brilliant compared to anything else. If you really need to use C++, I would warmly suggest it.
I have to because everything else is in C++ and I don't want to be the jackass that uses their favorite language that only they know in the company.
That's a bold statement. Clion and vs code are pretty great too, and last time i did a comparaison better than visual studio proper.
Computer graphics, though, is one of the few sane reasons left to learn C++.
There are warnings for this that you should activate.
The rest is pretty much incurable.
I know, the post is about C++ and Rust, but I'm tired of this "C++ is abandonware, just switch to a modern language" narrative.
I think this narrative is still valid. For the love of god, if you don't need to use C++ for a greenfield project, don't. I say this as a person who needs to write C++ daily.
Otoh, if you do need to use C++, it's likely there are no good alternatives, so unless you are Microsoft, Google or Facebook ready to invest few billions to a new language ecosystem, the most pragmatic approach is to, indeed, just use C++.
Chances are if there's a problem to be solved, someone has solved it in C or C++ and the code is out there already.
It also has a lot of great support in terms of toolchains. Almost everything everywhere supports it out of the box, and you have your pick of any tools you want.
It also works on fairly simple principles, so anyone with experience in programming can work in it without learning a completely new way of thinking. [Even if their code won't be amazing at first]
In general I agree with Mark Russinovich. Use a garbage colleted language, and if you really want a non-gc language choose Rust (which I really should learn).
https://twitter.com/markrussinovich/status/15719951172335042...
There are cases when one should choose C++, but those are the exceptions. Graphics, computational geometry and so on are strong reasons to use C++ still. But not everyone needs that stuff.
For moving strings and numbers around in a stereotypical business domain there are much better languages. C#. Python. Etc.
"an enormous pile of easily-usable existing C and C++ code that you can hook in easily into any project."
A lot of it is to help with the fact that the standard library in C++ is anemic.
This is one of the reasons though why one would want to use C++. Some libraries exist only in C++, and yes, it's a good reason to use the language.
"It also has a lot of great support in terms of toolchains."
CMake? VCPKG? Conan? MSBuild? Meson? Scons? Bazel? Make? Xcode? The-android-thingy? How do you mix and match those?
All of those are bloody horrible. And their combinations to the second power so. The only good thing in modern times is that most open source projects have picked up CMake with a fairly standard way of project configuration, which enables actually to reuse other's people code with surprising ease.
The toolchains make a horrible language a doubly terrible.
"It also works on fairly simple principles, so anyone with experience in programming can work in it without learning a completely new way of thinking. [Even if their code won't be amazing at first]"
Calling C++ simple is a new one to me. It's an industrial language that is not a total failure. Yes, people can write programs with it. The problem is there are much safer and better languages to write general programs, thus selecting C++ is giving yourself an intentional handicap in term of value created.
As an example of the complexity choosing C++ over something like C# gives you -
To what extent is a C++ codebase cross compilable and runnable in say MacOS after you develop it in Visual Studio on Windows? That's right, you can't tell, the only way to verify your standard C++ has the same runtime behaviour is to run it on the said platform. And fix all the bugs. So to actually write cross platform code, you need to have some proficiency in all of the platforms to have any level of guarantee that the code actually works in it's intended runtime.
Thus, a C++ codebase needs to come with a warning label telling every OS and processor it has been tested in. Most popular libraries are tested and run in all of the relevant platforms so this is not an issue for users. But I'm pretty sure the number of platform specific fixes per codebase is not trivial to make something work even remotely similarly.
If one cares about language design beyond the ideas explored in Oberon and Limbo, not so much.
Probably it's mostly about runtime/libraries than language itself.
Aside of embedded applications and hardcore number crunching (core part of it) I can't find a single use for C++ in 2023.
Reference parameters are awful; the reader has no idea whether the argument will be modified or not without reading the header file.
With const pointers you never have this problem.
Also the “problem” you describe is not solved by your proposed “solution”. A const pointer can point to something that can be modified.
You can declare a pointer to a const object, or, you know, declare a const ref.
_Success_(return) //out parameters should be set if this returns true
bool tryGetValue(
_In_ Map const* map, //pointer is for input only and cannot be null
_In_ char const* name,
_Out_opt_ Data* value //pointer is for output and can be null
);
If you pass null for _In_ params, the compiler will warn or error. You return true without setting the _out_opt_ parameters, the compiler will warn or error. You can pass null to _out_opt_, and the compiler will warn or error if the function body doesn't properly check if the parameter is null> A pointer can be nullptr while a reference cannot so that would be a step backwards.
Backwards from what? A reference can't be null, but it can still be invalid, which is a more common problem than forgetting to check for null-ness.
> You can declare a pointer to a const object,
Yes. I should have said that instead.
> , or, you know, declare a const ref.
That doesn't solve the original problem with references, though. I hate reading `foo (bar, baz)` and having to dig into the header to find out that bar or baz or both might be modified after the call to foo.
When reading code, I want to be able to skip over anything that does not modify the state of variables in the current scope.
Using references means that I have to know what every single call does. Using pointers exclusively, I can simply skip calls to functions with arguments that aren't pointers.
no, a reference cannot be invalid. If you are given an invalid reference (such as referring to an object after its lifetime ended, or referring to something that is not an object of the reference's type), then the fault lies on the caller. The callee cannot check the reference's validity, nor it is its responsibility to do so.
This is *very* different from the case of a pointer, where the caller is not at fault, typesystem wise, for giving a nullptr to a function accepting a pointer.
Increasing the probability of runtime errors to gain a little bit of readability at the caller's site is not a good tradeoff.
With const references you never have this problem.
Const references are less offensive, but I'm not going to pass non-const by pointer and const by reference, that's just inconsistent for no reason.
If null is not a valid value, throw an assert at the beginning of the function. It's not like references can't be in a broken state, they're just syntax sugar for pointers (that also happens to wildly complicate the language's type system)
Why use pointers at all? Just use const references for immutable stuff, regular references when you want mutation, normal values when you want copy semantics, and smart pointers for other cases (unique_ptr for move semantics, shared_ptr for lack of clear ownership, etc.) If you want to represent nullability, std::optional is a good choice.
> If null is not a valid value, throw an assert at the beginning of the function
Yikes. This means the compiler will not catch it for you. Why make this a runtime issue? Use the type system to your advantage.
I find this all a bit rich anyway. In languages like C#, everything is a bloody reference and this lame concept of "reference types" corrupts developer minds.
When I'm navigating code, the references aren't a problem, because I am using an IDE of some sort, usually.
The complaint I made was about reading, not navigating, for example when reviewing a PR.
It is true that C# has value types that are by default passed by copy, though.
Class types are effectively pointers that are passed by the value of the pointer.
You cannot implement swap in Java without eg wrapping the params in one element arrays.
While I would certainly prefer the reference to be visible at the call site (a mistake Rust did not repeat), if I have to choose, I prefer the inconvenience of having to use an IDE like qtcreator that will display references in a different style, to introducing an invalid value that needs to be handled (and will be mishandled).
So yeah, as a senior dev, it checks out.
Hardly any different from "var" parameters in plenty of languages since the 1960's.
I found that to be a rare circumstance in any complicated code base. And once you lose that capacity, oh boy does this language become terrible fast.
So yeah, difficult-to-parse codebases are not an exclusive feature of C++.
Visual Studio works fine for millions of lines but I am sure the difference in experience can vary wildly.
It sounds like the problem is not using an IDE.
Use references whenever posssible. Then you don't need to do a null pointer check. C++ is a footgun. And like with all guns, security first. With guns - put the safety on. With C++ - check the pointers are not null.
OFC one can argue that with proper instrumentation invalid pointers are captured sooner than later, but the fact is it's much easier to represent invalid program state using pointer than references.
#define $
And add the $ in front of all non-const pass by reference parameters in the callThere is no perfect solution. Avoid out parameters if possible, otherwise make the semantics clear via function naming or at least parameter naming conventions.
Actually, I'm curious if somebody is working on a flavor of the modern C++ that abandons backward compatibility ?
The Carbon project feels like a completely new language. What I'd expect instead is something that adopts best features and practices from modern C++, so that an average C++ project would require just minor changes to migrate, in spirit of Python 2 -> 3 migration.
This is just Rust. You can't really deprecate bare pointers in C++ without completely wrecking the language.
(I could be wrong though! I follow the committee more than you may guess, but not as much as to think I know everything about what's going on.)
And all their header files. That's a real Year Zero moment: you've just cut yourself off from the standard library, as well as most of the code you might want to link to. I don't think there's any "simpler" about it.
Carbon is a completely new language, and that's the point. Part of the language design is making compilation a lot faster, for example, as well as features that C++ can't realistically implement, while retaining C++ interop. It's an exciting way forward if they manage to achieve their goals, and it would be a way to gradually migrate C++ projects.
I think the best practice is for people to stick to a subset of safe patterns in mature languages. For C++, that's probably the C++ Core Guidelines:
I reject the notion that C++‘s “maturity” is a substantial advantage given its unsafety.
I feel the same whenever I have to go to other languages after using TypeScript. I want to model all of my data using the limited algebraic data type operations that many newer languages have (usually sum and product types).
Recently I've been writing some Go for a project that is a tiny bit beyond a plaything. I am surprised how much I actually like Go and I am very glad to have come to the language to use for real after they added generics. But several times I wanted to do a union `SomeType | AnotherType` and the fact it is missing from Go is like an itch that can't be scratched.
I would also add that discriminated unions alongside type narrowing (usually based on branching or escape analysis) just seems like something I want everywhere. Add in a powerful `match` statement and some kind of destructuring and I start to get very interested.
If there is some future where Go picks up sum types, adds some kind of support for discriminated unions and type narrowing based on branching - then it might just be the best general purpose language (although unlikely to be a contender for best low-level systems level language).
While I agree to a point, I also understand the argument against this. In programs, a lot of state needs to be changing. Which means you're going to type mut a LOT over the course of a 100k line program. And frankly, that gets tedious really quickly.
If you miss a const in C++, no big deal. The program still works. It's mostly a safety net. [with notable exceptions] But if you forget a mut in Rust, the program is not going to work.
That's an advantage (you can't write something incorrectly) but it's also tedious, imo.
When working on the C++ codebase daily, I occasionally find myself going "Hmm, that could be const/I need const here to use something" and swap it over. But it's fairly rare, and overall less time investment on my end.
Frankly, this explains most differences in Rust and C++. Rust is OK with the developer having to do more boilerplate, more verbose code, etc. for the sake of ensuring correctness. C++ assumes the best and goes with it to save some time in the short run. That's neither good nor bad, just preference.
It may not be as large a proportion as you think. Doing a quick grep on the rustc compiler source (483k SLoC), there are 5431 matches for "let mut [\w\d_]+ =", and 29520 for "let [\w\d_]+ =". This is, of course, is only simple bindings and misses out on more complex patterns along with if-let and match expressions, but even so, about 84% aren't mut bindings.
One of my own codebases (including all its Rust dependencies is about 1.5m SLoC) comes to about 80% not being mut. Ripgrep + dependencies (718k SLoC) is about 77% not mut.
I just can't take your argument seriously. One of your arguments is "the program will still work, with notable exceptions". I'm not persuaded.
You say it's a matter of preference, fair enough. I say let's make companies financially liable for the consequences of their preferences and see how this shakes out.
I can't think of anything significant off-hand, it was just more to stave off this part from the post:
>If you take a parameter by non-const reference, the caller can only use lvalues to call your function. But if you take a parameter by const reference, the caller can use lvalues or rvalues. So some functions, in order to be used in natural ways, must take their parameters by const reference.
>I say let's make companies financially liable for the consequences of their preferences and see how this shakes out.
This is completely unrelated. It's also a bit of a dangerous road to go down and I'd suggest thinking about it a lot more.
I would argue that one of them giving you a better chance at producing reliable software should go above and beyond the notion of preference.
[0] The compiler will gladly pass a non-const pointer to a non-const object to a function that expects a const pointer to a const object; it all "makes sense". However, a compiler will explode when you're trying to pass a non-const vector of non-const objects to a function that expects a const vector of const objects.
The elements of std::vector cannot be const.
I suspect a certain laziness in not tackling some of the harder problems in the compiler, for example: type inference, improving the grammar to disambiguate new keywords from variables (for example co_yield). Many features could have been improved with more effort and willingness to tackle hard problems.
Perhaps if Sean Baxter's Circle (C++ language extensions) gains traction, there will be hope to modernize C++ syntax and features.
* You can just write = default for those methods often enough, and having to implement these is extremely rare
* use [[nodiscard]] for your silly bool get_message return
* C++ does in fact support multiple return types via structured bindings, or just use a struct
None of this is really what is wrong with C++, the real issues are that everyone uses a different build system and a different way of sharing code.
And for tuples, you still need to use std::tie or std::make_tuple on the other end.
None of this however precludes me for writing well behaved software using subset of modern C++ that I actually need. The good thing is that when I need some esoteric feature that will help me to to this and that - it is always there and is quickly searchable thanks the the Internet.
I prefer wide array of C++ choices especially when it comes to supporting various paradigms and techniques to a stricter set in Rust for example.
I do see that real C++ experts (I am not the one) can get frustrated with the language but I think we have different goals in general. Being a programmer I do run my own business and I believe ROI wise C++ is more beneficial for my situation (I do use multiple languages when needed / requested by clients).
> It is unergonomic to return multiple values by tuple in C++. It can be done, but the calls to std::tie and std::make_tuple are long-winded and distracting, not to mention that you’ll be writing unidiomatically, which is always bad for people who are reading and debugging your code.
C++14 allows you to move capture in lambdas. C++17 has structured bindings that help with returning multiple values.
If you are claiming to an expert in C++ talking about paper cuts, at least be aware of things that have happened in C++ in the last decade.
"Lambda capture" sounds like "my favourite way to juggle chainsaws".
The correct answer to "I don't like lambda syntax..." is not "learn lambda syntax" but "do not use lambdas unless you really need them, and then think twice".
Honestly, C++ is a massive footgun. Write the most simple, inelegant C++ you possibly can. The coming generations who need to maintain your code for the next 200 years will be thankfull for it.
Don't pretend C++ is something more elegant like Ocaml that the compiler sugars you into believing. It's not! It's a horrible pile of ... things ... piled .. on top of .. things .. on top of ...(etc).
And when something goes sideways at any point in that pile of templated tower of abstractions, the compiler will gift you with an outpout that is closer to a mix of toenail clippings and dog poo than an output from an industrial level programming tool. After which you need a heavy drink and wish there was a better language out there. And then you realize there isn't, for the specific task, and you adjust by reducing the complexity of the abstractions you use and prefer to have a codebase that has more lines of code and fever chances of irritating the compiler.
It’s not about the syntax, it’s about understanding the resource management model lambdas add on top of the existing mess.
There is no good reason to use lambdas except parametrization of stl algorithms.
Don’t use them as part of api design. The only thing you gain is one more level of complexity on reasoning resource management.
Yes, to be specific, one should know how they work, and then not use them.
This is in the context of C++ being a minefield of practically infinite complexity, in which the only way to survive is to pick the language subset you know you are able to handle, and stick with it.
Of course, every party picks their own subset :)
And I have now addressed structured bindings in the article itself for what they are: a halfway solution, unacceptable to anyone used to real tuples.
Your quote says cpp11 and youre arguing with 14? Wtf?
Source: Someone who was, until recently, limited to C++03. Luckily we're up to 17 now, but occasionally 11 limitations creep in.
Stopped reading here. std::variant and std::tuple.
Edit: It's really important to read criticisms of your favorite language. Often, it can help you find a better language for the task you're trying to accomplish.
When people talk about first-class support for tuples, std::tuple does not fit that bill.
ETA: std::variant is one of the least ergonomic user interfaces I've ever seen. std::tuple seems great until you realize that most PLs that support tuples just do "(,)"s for them, in creating, binding, and naming the type. C++'s versions are just unacceptable, and structured bindings only help on the binding side.
First-class support for these is important. There's no reason they should be in the standard library rather than built into the language itself, besides historical mistakes.
This C++ code compiles and does what a casual reader would expect it to do:
#include <string>
#include <tuple>
using Foo = std::tuple<int, std::string, float>;
Foo foo(int a, const char* b, double c)
{
return {a,b,c};
}
godbolt: https://godbolt.org/z/Koa4zYT99I gotta be honest, this interface is exactly what I would like a tuple API to look like. I want to declare my tuple as a `tuple`, I want to give it a friendly name, and I want to explicitly declare the types in the tuple, and I want to all of that at compile time. This API is exactly the verbosity that I want; I would be unhappy with either more or less boilerplate than this.
> First-class support for these is important.
Agree to disagree.
How do you know correct? Very few pieces of software are subject to full theorem-prover correctness, and very few pieces of C++ are completely free from ever invoking "undefined behavior" at runtime. Because that's extremely hard to do when even "x = x + 1" can be UB.
Don't hold C++ programs up to a standard that programs in other languages also can't pass.
Think you have the wrong person? I have no idea what this refers to.
Each probablility of a mistake may be low on its own, but they compound with every avenue to make mistakes.
"Rust makes a few classes of bugs impossible to write by construction" is a very nice feature of the language. But I'm really turned off by how insufferable the Rust community is (which shines through in the OP's blog post and several comments elsewhere in the responses): it's never the quote at the start of this paragraph; it's always "writing software in anything but Rust is fundamentally irresponsible!" or "if a Rust program compiles, it must be correct!" No, not even close.
This is very well put and mirrors my sentiment as a long-term C++ swe.
I also think that the following quote is rather misrepresentative:
> C++ is a great programming language. The complaints are just from people who aren’t up to it. If they were better programmers, they’d appreciate the C++ way of doing things, and they wouldn’t need their hand-held. Languages like Rust are not helpful for such true professionals.
C++ is a great language and a lot of complaints do come from people who aren't up to learn it properly. This isn't elitism, and this state of things has been true for every skill-based discipline in history. I am not saying that I am better than people who refuse to learn C++, or that C++ is a better language than others - I don't think there are many C++ programmers at all who do, it would be a very ridiculous stance.
C++ is a great language, it is also a somewhat dangerous language. It is not a language for everyone and every purpose. And that is fine. Just like knives are great instruments even if they are a bit dangerous and unsafe to those who do not wish to learn it properly and where it makes sense.
At the end of the day, it doesn't matter how many people who just don't see a problem with C++ one calls "elitist" or other things, not everyone is obsessed with micro-improving a language that clearly works very well.