首页
25 条评论
notacoward超过 7 年前
The bullet list near the end closely matches my own experience with C++. There's an inordinate number of features creating an even worse profusion of edge cases where they interact. Then the "solutions" for those edge cases usually add even more complexity. Worse, they force programmers to coddle their compilers. The ratio between what a C++ compiler will accept and what it will produce sane code for is <i>huge</i>. That's why every C++ codebase I've ever seen is full of code to do things that shouldn't be necessary, and goes through all sorts of contortions to avoid doing things that should be OK, lest the compiler spew out an un-debuggable mess.<p>I'm perfectly happy managing my own complexity in C, or avoiding it entirely in Python. C++, on the other hand, seems to have been designed by compiler writers for their own enjoyment and/or job security. Every other "systems programming language" from D to Objective-C to Go to Rust to Nim presents a more coherent face to the programmer.
评论 #16271973 未加载
评论 #16271553 未加载
评论 #16272777 未加载
评论 #16272890 未加载
评论 #16272207 未加载
评论 #16272854 未加载
评论 #16271686 未加载
评论 #16271776 未加载
评论 #16274620 未加载
评论 #16272709 未加载
评论 #16272366 未加载
评论 #16272167 未加载
bjorn2k超过 7 年前
I agree that c++ is complex, but remember that while trying to update the language the standard committee is trying not to do breaking changes.
If you can do a greenfield implementation like rust, you don't have the baggage of an installed base, yet.
If you compare c++ to a language that is also around for more that 25 years it starts to make more sense why it is complex. Add to that, that it started as an extension to c, which is the reason why it became popular in the beginning.
Also, zero-cost run-time abstractions.<p>It is whatever you give priority design-wise, and if you look at what is important in c++ (zero-cost runtime abstractions, control of the resulting code), then ending up with something as complex as the c++ language is hard to prevent.
评论 #16272626 未加载
ndh2超过 7 年前
Lots of posts here frame it like "Yes, it's a bit of a complex language, but the C++ committee has the difficult job of keeping everything backwards compatible, so it's understandable." But that's not the reality. The reality is that they (or Stroustroup) made that decision, and that decision was a mistake.<p>The correct way to deal with backwards compatibility issues is the way Go does it, namely to write tools to automatically upgrade code to a newer API [1]. And as that smug Google guy explained here [2], they have something like this for C++, too. They just don't bother sharing it with us peasants.<p>The fundamental mistake of C++ is to religiously keep backwards-compatibility with everything for all eternity. It's so easy to say that backwards-compatibility is a good thing. It's obvious! But ultimately that decision is the reason for all the problems that C++ has.<p>[1] <a href="https://golang.org/cmd/fix/" rel="nofollow">https://golang.org/cmd/fix/</a><p>[2] <a href="https://www.youtube.com/watch?v=tISy7EJQPzI" rel="nofollow">https://www.youtube.com/watch?v=tISy7EJQPzI</a>
评论 #16274050 未加载
评论 #16273558 未加载
评论 #16275600 未加载
yason超过 7 年前
While my pet peeves might be different than the author's I agree that C++
makes you work very hard to keep things simple and produce something that is beautiful. Just "avoid the complexity you don't absolutely need" doesn't really work: some basic things are so fundamentally convoluted that I rather just write idiomatic C because it's simple and doesn't get in my way. I want the language to originate from simple axioms so that I can concentrate on the complexity of the problem I'm solving instead of wasting brain cycles on battling the complexity of the language. I would like to like C++ but its benefits barely zero out the extra hoops.
评论 #16272614 未加载
评论 #16276036 未加载
pjmlp超过 7 年前
Well, most of his points regarding complexity are not C++ specific.<p>The thing with equals applies to most languages that allow to redefine operators.<p>Even Java has gotten quite complex, I bet he would have quite an hard time succeeding at one of those quiz questions certifications (SCJP and friends).<p>And simplicity can also turn into more complexity, manual memory management in C vs C++, "templates/generics" in Go, libraries to work around language limitations in JavaScript (npm, yeoman, gulp, grunt, webpacker all at the same time).
ajeet_dhaliwal超过 7 年前
In my experience this disease afflicts more than just some C++ programmers, the immaturity is boundless. I’ve noticed some colleagues even think there must be something wrong if code looks simple.
ioquatix超过 7 年前
Yes, C++ is a complex language. Yes, it has a ton of warts if you know where to look. But, you can write beautiful software with it, and it can even look beautiful too.<p>Yes, there are alternatives, but when it comes to performance, expressiveness and actual deployability, C++ is pretty awesome.
评论 #16271101 未加载
评论 #16271254 未加载
KayEss超过 7 年前
Part of the problem here is that OO sits nicely with references, but C++ (like C) is a value based language. This can be seen clearly in most of the design of the standard library -- it's all value semantics, and as such relatively simple and obvious to use (so long as you're not trying to cram OO into it).<p>A line like<p><pre><code> if ( a == b )
</code></pre>
In C++ is pretty obvious what it does. It'll always be a value comparison, and if a and b are pointers to objects you are comparing the object identities and not their values. The meaning is exactly the same in Java of course, but the fact you're dealing with pointers is hidden so you generate a lot of confusion about the correct use of `==` and `.equals`.<p>The author certainly isn't wrong about a culture of complexity in certain elements, but, to be hones, I see that everywhere else too and it needs to be fought wherever it occurs.
评论 #16272184 未加载
评论 #16272737 未加载
tines超过 7 年前
It seems like this article is essentially complaining about the language giving you too much control (e.g. in his copy assignment operator example), when that's exactly what its goal is.
pfultz2超过 7 年前
> What does that do? It makes the variable x refer to the object that y is referring to<p>In Java/C#, it doesn't always:<p>int x = 1;
int y = 2;
x = y;<p>The variable `x` does not refer to the object that `y` is referring to(as there is no reference involved at all).<p>Assignment is a procedure that makes `x` equal to `y` without modifying `y`. However, if `x` refers to `y`, then we can modify `y` after assignment to `x`. This destroys the ability to reason locally about the code, because each object essentially becomes as good as a global variable.<p>Even though C++ has areas where things gets complicated, this is the one thing that C++ keeps very simple and consistent. There is only one definition of copy, assignment, and equality, whereas in java there is multiple definitions(deep copy vs shallow copy, `==` vs `.equals`).<p>> That’s called value semantics, although I would prefer the term state semantics: objects do not have a value, they have state, and that’s what’s being transferred here.<p>No. Its value semantics, as these objects represent some entity. The interpretation of the state(or datum to be more precise) is the known as the object's value. For example, when copying a `std::vector` the internal state of the vector will be different on copy, as it will point to new piece of memory, however, its value will still be the same.<p>> But experience shows that making a copy of an object is hard.<p>The compiler already generates a copy constructor and assignment for you. Its only necessary to write one, when one is dealing with low-level pointers. Using the standard built-in types and containers, writing a copy constructor is never needed.
NTDF9超过 7 年前
There are two kinds of developments:<p>1. Application level: Typically manipulating lots of strings and data massaging. I prefer Java or python for this. The IDEs and eco-system just is so much faster to start with<p>2. Systems level: Typically a high-performance system like a DB manager or a fast processing library like a message producer etc. These things are time critical and need performance.<p>I used to really love C++ but I agree, it takes far too long just to start making things run. Sigh!
sevensor超过 7 年前
When I was young, I thought I understood C++, because I had been taught it in school. I did not. Having interviewed several recent graduates who thought they knew C++, I believe this is fairly common, particularly among people with advanced degrees in engineering and the sciences. It's very easy, in C++, not to know the scope of one's ignorance.
评论 #16275893 未加载
neo2006超过 7 年前
The author is relating a personal experience
As a former C++ dev I saw some wonderful code base written in Ç++ and some horrible code base, as any other language. The only specifity Ç++ have in my opinion is that some features have a high learning curve and are not necessary shared with other languages. Once you mastered Ç++ it's easy to move to other languages but it's hard to do the reverse path.
airstrike超过 7 年前
It takes balls to imply that one may use Java in lieu of C++ so as to reduce complexity.
评论 #16271315 未加载
jokoon超过 7 年前
C++ is the only language that is compiled to binary, compatible with many compilers and OS, and can do both low and high level constructs.<p>It is true that it is a complex language, but this is true for every tool that allows you to do so many different things.<p>The complexity is not a goal in itself, it's just that it can do all of those things if you need them.<p>Simple tools are great and will save you a lot of time, but the truth is that you won't always be able to do everything with them. C++ allows you to do everything, and it is true that the cost can be very high and requires a lot of thorough knowledge and expert learning of what happens, but there are projects and cases where you just need to use C++ because that's the only choice you have left.<p>I agree that an alternatives like rust or D would be great as replacements, but the problem remains: if compilers are not mature on most platform, and if you don't have a large programmer base because the basics of the language are not simple enough, the language won't grow.
评论 #16282186 未加载
bogomipz超过 7 年前
The author states:<p>>Neither the performance issue that move semantics address nor the perfect forwarding problem exist in classic OO languages that use reference semantics and garbage collection for user-defined types."<p>I understand reference semantics but what are move semantics?<p>Also what is the "perfect forwarding problem"?
评论 #16272056 未加载
Animats超过 7 年前
One word: Boost.<p>C++ went off into template la-la land some years back. C++ templates were not supposed to be a programming language. But they turned into one, and not a good one.<p>Look up the implementation of "max" and "min" in C++ templates.<p>Now there's a push for "move semantics", to keep up with Rust and the cool kids. But not with language support and a borrow checker. With templates and cute tricks with the type system.
andrepd超过 7 年前
>Rvalue references provide move semantics, and they solve the perfect forwarding problem. Neither the performance issue that move semantics address nor the perfect forwarding problem exist in classic OO languages that use reference semantics and garbage collection for user-defined types.<p>I don't get this. The performance issue move semantics solve doesn't exist if you just use automatic garbage collection? Is this what the article is saying?
评论 #16273952 未加载
beached_whale超过 7 年前
I think it depends on where you sit on the stack. A library can take a lot of the complexity away from the higher levels in C++ code. The user code can look fluent and understandable. On the implementation side of the library being used(depending on where it sits in abstraction) is where some ugly complexity shows. But this also generally reflects the competence of the authors.
评论 #16275248 未加载
carapace超过 7 年前
I think there's a "sweet spot" in complexity (at least for software): too complex gets rejected, but being too simple lacks traction. I think artifacts like C++ memetically infect the brain better than a more elegant PL might, exactly because they require you to think about them a lot, but you can still get things done and not be (totally) overwhelmed.
mar77i超过 7 年前
Isn't there anyway some of a pendant to Conway's law in this? I mean, C++'s standard library is - or at least used to be - rather complex, so the people that would go there and use C++ for their project - would more likely than not - carry at least some of that complexity over into the project...
petters超过 7 年前
I like the fact that in C++, the line<p>x = y;<p>behaves the same if the types are int and vector<int> (unlike e.g. Java and Python).
评论 #16275840 未加载
geoffroy超过 7 年前
Does anybody know a good tutorial or book for learning modern C++ 17, focused on best practices (new language paradigms, TDD/BDD, etc.) ? Something like Michael Hartl's Ruby on Rails Tutorial
commandlinefan超过 7 年前
Well, if you haven't encountered any brain-bending Javascript, you haven't gotten very far into Javascript.
otabdeveloper1超过 7 年前
C++ is not more complex that its competitors like Haskell or Rust.
评论 #16273691 未加载
评论 #16272705 未加载
评论 #16272907 未加载