There most certainly are. std::locale is both under and mis-specified. Any non-trivial localization work requires implementation dependent information, defeating the point have having a standard library solution, and certain functions are useless because they assume single character returns when in actuality languages can have multiple character returns. Exception specifications outside of throw() are worse than useless, adding overhead without benefit, and even throw() has sufficient issues that C++11 had to introduce noexcept. Template export is only implemented in one compiler family and even they recommend against its use because the export specification has some consequences that the standards committee missed when they created it. Don't even get me started on the most vexing parse or the places where signed integers have undefined behavior rather than implementation defined behavior.There are no 'bad' places of C++.
Is C++ too complex?
#21 Moderators - Reputation: 6781
Posted 30 November 2012 - 10:10 AM
#22 Members - Reputation: 437
Posted 30 November 2012 - 11:40 AM
All good answers guys, it was nice to read every single post confirming my biases that there's nothing unnecessary in the language, next time I read an article that has me challenge my assumptions about c++ I'll ignore it. Also using a subset for clarity seems like a good idea.
The question presented was whether there were any components to C++ that were so complex as to be unecessary. There are definitely unecessary parts to C++ -- Valarrays immediately come to mind -- but I'm not learned enough in the language to identify any language features that are unecessary out of overcomplexity (except the ultimate low-hanging fruit goto).
#24 Members - Reputation: 2501
Posted 30 November 2012 - 12:26 PM
#25 Members - Reputation: 1408
Posted 30 November 2012 - 01:04 PM
It can be funny also, making practical jokes (not possible with proper configuration management).C++ most assuredly has features that are too complex and/or arcane for their own good. Sure, they're "valid" features, but if you use one in your code you're going to get slapped upside the head during the code review. For example, overriding the comma operator
#define struct union // Save memory
#define while if // Speed optimizer
#26 Members - Reputation: 2820
Posted 30 November 2012 - 01:19 PM
No, I kid you not. The Java exception runtime in gcj is the C++ exception runtime in g++. They do not just share terminology. They are the same runtime library. Java and C++ exceptions are conceptually and fundamentally identical.No, exceptions in C++ are a fundamentally different construct than exceptions in Java, they just happen to share terminology.
Professional Free Software Developer
#27 Members - Reputation: 212
Posted 30 November 2012 - 01:54 PM
...
Oh lord, another 'goto' topic.
Most production code really isn't very nice to look at. Just look at the source code for Doom 3 (https://github.com/TTimo/doom3.gpl) It's not exactly the most beautiful code out there, but it gets the job done, and in the end that is what matters most. And as a side note, the Doom 3 source code is littered with 'goto', so you can certainly use it. But as with any loaded weapons... handle with care.
#28 Crossbones+ - Reputation: 1094
Posted 30 November 2012 - 03:14 PM
The very worst thing about the language is how it makes undefined behavior nearly impossible to avoid (Sicrane noted one instance, but there are a lot). Even if that kind of lack of safety was necessary for C++'s goals of best possible optimization and wide platform support, basic operations should be safe by default, and the coder should explicitly ask for the unsafe version in the <0.1% of situations when that is actually beneficial. Likewise, most things in the language should be const by default, and explicitly marked as mutating/mutable when necessary. That ties into how metaprogramming should be a matter of simply writing a bunch of code that has a const result, easy enough for most programmers to do, instead of the template metaprogramming hell of C++. Behavior of value/reference/move semantics should be visible and obvious. Name lookup should be fixed to be way simpler, and to work the same in different situations.
I haven't used D, but based on what I have read about it, it gets most of the things right which C++ gets wrong.
#29 Members - Reputation: 533
Posted 30 November 2012 - 03:52 PM
What makes C++ complex is what developers end up doing with it. What makes C++ tricky is memory and pointer management, which (imho) is the main reason most folks are hesitant to get well versed in the language. Exceptions? Meh. Classes? Meh. Templates? Meh. Pretty straightforward stuff.
To use an analogy - it's like saying a spoon is complex when you see someone using nothing but spoons to build a working zeppelin. Maybe that's a bit extreme, but yeah.
#30 Moderators - Reputation: 8420
Posted 30 November 2012 - 05:12 PM
No, I kid you not. The Java exception runtime in gcj is the C++ exception runtime in g++. They do not just share terminology. They are the same runtime library. Java and C++ exceptions are conceptually and fundamentally identical.
No, exceptions in C++ are a fundamentally different construct than exceptions in Java, they just happen to share terminology.
The underlying mechanism is kind of orthogonal to the use cases though.
In C++, exception safety means RAII and a lot of care in order of operations. That means unwinding a stack can be expensive. In Java, you just let the GC deal.
[Work - ArenaNet] [Epoch Language] [Scribblings] [Journal - peek into my shattered mind]
#31 Members - Reputation: 287
Posted 30 November 2012 - 09:02 PM
#32 Members - Reputation: 3370
Posted 30 November 2012 - 09:10 PM
So for a future of clean c++ code, there doesn't necessarily need to be a complete revision of the language, but a definition of a sub set of the language that is the best practice usage. Is there a good wiki describing this available, or should I learn Dlang and then figure out the c++ equivalents and preference that equivalent subset in my coding?
I would argue that the variety of styles and idioms used for the variety of C++ libraries, as well as the disjointed tacking on of syntax makes clean C++ code not just a simple subset of best practices for non-trivial code. I mean sure, you can make it more clean, but not *clean*.
As for D... I wouldn't bother. If it was going to take off, it would've done it by now.
#33 Members - Reputation: 1337
Posted 01 December 2012 - 01:10 AM
I am still of the opinion that exceptions are too costly to use for anything but exceptional situations.
To be fair, that's why they are called "exceptions" and not "common stuff happening" or "code flow control construct". As such you could easily argue that someone using exceptions for situations that aren't actually "exceptional" errors is probably using them wrong.
vector::at throwing at an invalid index is fine (it IS kind of a big screw up), std::find throwing if an element isn't found would be silly (as it's a perfectly expected case). Which leads to a nice anti-pattern called "expectation handling".
c++ is not too complex, just you need some dedication and you can easily learn the c++...
first try to learn c it will help you in learning c++ easily and in efficient manner..
dynamicmounting.com
Strangely enough, everytime I hear someone claim "C++ is easy" it is accompanied by "C with classes" and the person in question not even knowing enough about C++ and its countless dark corners to realize just how little he/she actually knows.
Edited by Trienco, 01 December 2012 - 01:18 AM.
#34 Members - Reputation: 287
Posted 01 December 2012 - 02:25 AM
Anyone have any experience with getting C++ and D to work nicely together?
Edited by Kyall, 01 December 2012 - 02:28 AM.
#35 Moderators - Reputation: 8420
Posted 01 December 2012 - 03:32 AM
D is an interesting but failed experiment in trying to make C++ suck less. Its lack of adoption and toolchain maturity is a serious problem, but not nearly as serious as the fact that moving to D from C++ is a painful process. If you're going to undergo the misery of converting massive legacy codebases to a new language, you may as well pick one that's better than D.
[Work - ArenaNet] [Epoch Language] [Scribblings] [Journal - peek into my shattered mind]
#36 Members - Reputation: 103
Posted 01 December 2012 - 04:47 AM
I thought I would explore the world of C++ programming. I managed to find the NeHE site where they have tutorials written in VC++ then translated into every know flavor.
Since I want my project to be cross platform I decided to take the first tutorial and compare VC++, Linux, and Mac. losw and behold there are like 3 different Linux translations that appear throughout the 48 tutorials, another discussion. So I copied the code into a spreadsheet and low and be hold not a single line of the 3 sources line up. I do not want to consider how the differrence between Intel and ATT syntax will further my confusion.
Now granted I come from a construction and accounting background, but I got to tell you every wall in the in the world since the invention of sheet rock is built with wall studs 16" on center. Every one states that C++ is a tool box well your tool box is cluttered.
On the otherhand I axcept that what you as programmers do is art and for that I am amazed. Andas such, as artists you all have your own style. Monet's little dabs and Picasso's odd balance. But, they all used the same brushes, the same base colors.
So I am more confused as ever after this mornings work. How can Qt and Code::Blocks, whom I thought would be the best tools for my project, can they claim to...code once, code less, deploy everywhere...with such differences in coding rules and styles? So I am starting to believe my 2 programer friends when they said I am in over my head. And, after posting on 5 forums and being "viewed" by over 200 people to have only one respond has given me the insight that I am not welcomed in this particular sandbox.
But I will figure this out and my 3 year old will get his learning game.
#37 Members - Reputation: 287
Posted 01 December 2012 - 05:06 AM
#38 Members - Reputation: 1302
Posted 01 December 2012 - 02:44 PM
how would you replace the goto in this bit with an exception
The parts of C++ that should generally be avoided (unless necessary) is misusing C stuff rather than the C++ alternative.
For example fopen, malloc and goto could be replaced with ifstream, new (with smart pointer) and exception respectively.
Whilst the ability to use classic C stuff seems to make the language complex, I actually prefer the way C++ extends rather than reinventing the whole language again from scratch (such as C#).
Kindof like OpenGL is seemingly quite hard to learn for new developers because it still has all the old stuff rather than dropping it all and starting with a brand new graphics API.for (int bar =0; bar < 100; ++bar) { for(int foo = 0; foo < 100; ++foo) { if (foo * bar == 100) { goto loopBreak; } } } loopBreak: printf("%d", 100);
The code I am presenting is not doing something usefull at all to be honest but imagine a difficult calculation going on over a grid in which if a certain condition is met you need to break out of both loops and continue the rest of the algorithm with the results already calucalted?
for (int bar =0; bar < 100; ++bar)
{
for(int foo = 0; foo < 100; ++foo)
{
if (foo * bar == 100)
{
foo = 100;
bar = 100;
continue;
}
}
}
printf("%d", 100);
#39 Members - Reputation: 6183
Posted 01 December 2012 - 03:34 PM
for (int bar =0; bar < 100; ++bar)
{
for(int foo = 0; foo < 100; ++foo)
{
if (foo * bar == 100)
{
foo = 100;
bar = 100;
continue;
}
}
}
printf("%d", 100);
So instead of a goto whose purpose is immediately obvious (you even get a label in whose name you can document what's going on), now we have code which expresses intent worse and requires changing the ranges in two places if they ever change. What if we now want to do something when the loops end without the condition ever being found? With the goto, you just put that code before the label; with the new code, there is really no obvious way of doing it. What if we are interested in knowing the values of foo and bar whose product is 100 beyond the loop? Again the old code was easier to adapt.
The only "advantage" of the second code is that it doesn't use goto, which as far as I am concerned is a ridiculous metric.
Edited by Álvaro, 01 December 2012 - 03:35 PM.
#40 Members - Reputation: 287
Posted 01 December 2012 - 07:26 PM






