Is C++ too complex?

Started by
121 comments, last by Vortez 11 years, 4 months ago

If only they could get rid of some of the mistakes they made earlier on and make a cleaner lighter language. Not going to happen though.


The language is light....i really don't see the problem alot of you seem to have with it. Its the same with any programming language. Once you know how to programm you can basicly programm in any language.
Advertisement
You've probably never seen any really bad C++ code. C is a very light language but my, have I seen some terrible code which no-one understands. C++ is about 4 times worse if you write it badly.
"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

If only they could get rid of some of the mistakes they made earlier on and make a cleaner lighter language. Not going to happen though.


Wish I could upvote you twice. I don't know if I'd call them 'mistakes' but some of the changes seem a lot more like 'tack on another class' rather than actually incrementing the language itself to add new features.
void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

You've probably never seen any really bad C++ code. C is a very light language but my, have I seen some terrible code which no-one understands. C++ is about 4 times worse if you write it badly.

I think i have seen alot of code and c can just be as bad as c++. Same goes for every programming language. You can always write bad code and create structures that no one understands besides yourself. But that really has not so much todo with the language used.
Take the infamous C++ quiz by Washu and tell me C++ is not problematically bad.

You can write bad code in any language, sure. You can also commit genocide with any weapon, but some weapons make it a hell of a lot easier.

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

This one just got me the other day:


Which constructors and/or operators will be called in this code:

struct MyStruct
{
MyStruct() {}
MyStruct(int i) {}
MyStruct(const MyStruct&) {}

MyStruct& operator = (int) { return *this; }
};

MyStruct s = 5;

[/quote]
[spoiler]
This is an example of copy-initialization (see a GotW about it). First, [font=courier new,courier,monospace]MyStruct(int)[/font] will be called to convert [font=courier new,courier,monospace]5[/font] to a [font=courier new,courier,monospace]MyStruct[/font]. Second, [font=courier new,courier,monospace]MyStruct(const MyStruct&)[/font] will be called with the created temporary. The other two functions ([font=courier new,courier,monospace]MyStruct()[/font] and [font=courier new,courier,monospace]operator =()[/font]) are not called. The code is effectively [font=courier new,courier,monospace]MyStruct s(MyStruct(5))[/font] (fingers crossed that isn't accidentally a function declaration...).

It gets a little more complicated though, because of copy elision, so the compiler is allowed to optimize away the temporary and effectively just call [font=courier new,courier,monospace]MyStruct(5)[/font]. But it doesn't have to.
[/spoiler]

C++ is way too complex. I don't mean too complex for beginners. I mean it's way more complex than it needs to be.

Beginners can start with whatever they want. They just need to realize that it'll probably take them longer to get something shiny on the screen with C++. Like SiCrane said, no matter what language someone chooses, they'll make plenty of mistakes. It's not the end of the world if someone chooses C++. But it's not exactly a walk in the park, either. It's never a walk in the park.
[size=2][ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]
Ok when i saw that code i thought hmm pretty clear it should be the int constructor since the object doesn'exist yet....then i saw your explanation and i shrug...really? then i tried it just to be sure....first instinct was right your "spoiler" is wrong
Ok, reading through the comments, and the general "it's too complex, not a walk in the park, long time for something shiny on the screen, etc" hand-wavy consensus - I'm really curious: What, specifically, from the folks that consider the language overly complex, are the overly complex pieces of the language?

And I'm not talking about relatively obscure tricks/"abuses" of the languages. I'm talking about stuff you'll learn in your first years of Comp Sci, or an intro-to-C++ book.

I mean, I've seen my fair share of heinous code. In all manner of languages: C, C++, Java, C#, Python, LUA .. you name it. But what makes it complex has never been the language as much as the complexity of the code. In other words, I rarely ask myself: "Damn, what does this language feature do?" but rather ask "why in the world has the developer done this?"

I do believe, though, that pointers and the usage thereof continually trip folks up with regard to C *and* C++, and with good reason. Pointer management takes a while to get a good grasp of, but even Pascal had pointers and I can count on my left foot the number of times someone has said "Pascal is too complex" :) Even though Java and C# have *many* more language features than C and C++ combined, the fact that they (mostly) completely hide pointers and memory management makes it easier for most programmers to write code and not worry about memory consequences, right off the bat.

So, again, what *exactly* makes C++ so complex over, say, Java? Pointers aside, and considering only what you may learn in your first year as a CS student? (I make that distinction because as you spend more time in any language you'll eventually learn all sorts of 'interesting' things that'll make most folks' heads spin)
That question makes no sense to me.

The problem is that no first-year CS course will cover all the things you have to know to use C++ proficiently. It's like asking "what's so hard about being a chef? Limit your answers to the subject of boiling water."

Well, yeah, boiling water isn't hard. There's a lot more to being a chef than boiling water.

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


Ok when i saw that code i thought hmm pretty clear it should be the int constructor since the object doesn'exist yet....then i saw your explanation and i shrug...really? then i tried it just to be sure....first instinct was right your "spoiler" is wrong
This is a good demonstration of how confusing C++ is. Cornstalks told you exactly what happens, you went and tested it, and you are still wrong.

He said that the int constructor gets called, then the copy constructor gets called, but the compiler is allowed to optimize the copy constructor away. In the case of your particular compiler, your particular compiler version, your particular computer architecture, your particular compiler settings it so happens that the compiler does that optimization and only calls the int constructor. But with some other configuration of those things, the same code would result in both constructors being called, and in both cases the compiler could be a completely valid C++ compiler. This repeats over and over again in the language: valid C++ compilers are allowed to do a wide range of things, and if you want your code to be valid C++, it has to withstand all of those things. Therefore you have to know what the language says. If you don't know the copy constructor may get called there and you assume it won't, that can blow up in your face at some point in the future.

This topic is closed to new replies.

Advertisement