Is C++ too complex?

Started by
121 comments, last by Vortez 11 years, 4 months ago
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 say Code! You say Build! Code! Build! Code! Build! Can I get a woop-woop? Woop! Woop!
Advertisement

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.

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.
f@dzhttp://festini.device-zero.de
I've been learning D today, and I would like to put forward a request that someone make a D board on these forums. Just because the forums on dlang have so many boards, and so few replies. D for dead as a dodo I guess. I reckon using D for game programming where the D is built on top of c/c++ would be a move worth trialing just because it'll reduce bugs and it suits game programming a little better. I'm trying to say this without insulting myself and other game programmers, but yeah... deadlines vs code quality; getting paid vs writing good code. It has a few interesting features, but the main part will be getting the benefits of all it's scope features & the gc. Normally I would be hating on a gc, eating up cycles when and grrr/rage. But it has the feature that you can use malloc to get around the gcc, and make a custom allocator which also gets around the gc as well as lets you use static memory for short-life objects (or everything if you're not scared of code that should crash, not crashing). Actually come to think of it I wouldn't mind turning off the gc altogether. Could that can't work without GC, shouldn't work, ever.

Anyone have any experience with getting C++ and D to work nicely together?
I say Code! You say Build! Code! Build! Code! Build! Can I get a woop-woop? Woop! Woop!
There's no point in making a D forum here. Traffic would be abysmal.

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.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

You are going to laugh me right off the site but yes C++ is way too complex.

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.
It's not really hostility if you don't get more replies. We have this unfortunate thing of not posting replies when we're not completely confident we know this answer. So yeah... the best way to get help from programmers is asking directly....
I say Code! You say Build! Code! Build! Code! Build! Can I get a woop-woop? Woop! Woop!

[quote name='Karsten_' timestamp='1354273814' post='5005651']
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.

how would you replace the goto in this bit with an exception

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?
[/quote]


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);


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.
I'm getting more and more into this D thing. An experienced programmer can write an interface and a unit test using the tools already embedded in the language, then get a junior to build the interface to pass that unit test. As only a mid level programmer myself I'm not the authority on this; but this gets rid of thick skulled juniors (like I was) doing things wrong right?
I say Code! You say Build! Code! Build! Code! Build! Can I get a woop-woop? Woop! Woop!

This topic is closed to new replies.

Advertisement