What's wrong with C++?

A place for Ogre users to discuss non-Ogre subjects with friends from the community.
Post Reply
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
Contact:

What's wrong with C++?

Post by jacmoe » Mon Feb 08, 2010 6:09 am

I just stumbled over this page, and thought it was funny! :D
Very smart people keep writing books with titles that read like "Esoteric Nooks and Crannies of C++", or "More Bizarre Pitfalls of C++". Or puzzles that start with "What's wrong with this code fragment that to all normal people looks perfectly OK?". You don't see such publications in the Java or C# community. C++ is becoming a freak language that's parading its disfigurements in front of mildly disgusted but curiously fascinated audience.

"So you have to put a space between angle brackets? How bizarre!"

"Are you telling me that you can't pass an instance of a locally defined class to an STL algorithm? How curious!"

"Talk to me dirty! Tell me more about name resolution!"

"Pardon my French, Is this specialization or overloading?"
:lol:

But, in the end there's no other language which I like better. :wink:
Strange as it is.

Probably because I'm not very good at it? Who knows.
0 x
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.

Vectrex
Ogre Magi
Posts: 1266
Joined: Tue Aug 12, 2003 1:53 am
Location: Melbourne, Australia
Contact:

Re: What's wrong with C++?

Post by Vectrex » Mon Feb 08, 2010 8:56 am

People like what they know ;) If you're used to bashing your head against a wall you might even come to look forward to it :)
0 x

Fulmens
Gremlin
Posts: 151
Joined: Sun Jun 22, 2008 8:29 pm
Location: Nantes, France

Re: What's wrong with C++?

Post by Fulmens » Mon Feb 08, 2010 9:01 am

If you want a full website for this kind of arguments, go take a look at the C++ FQA
0 x

User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
Contact:

Re: What's wrong with C++?

Post by jacmoe » Mon Feb 08, 2010 9:27 am

That FQA is not written by C++ programmers - or so it seems.
I don't buy those arguments.
Otherwise I'd use C#, D or something else. :)
0 x
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.

jjp
Silver Sponsor
Silver Sponsor
Posts: 597
Joined: Sun Jan 07, 2007 11:55 pm
Location: Cologne, Germany
Contact:

Re: What's wrong with C++?

Post by jjp » Mon Feb 08, 2010 9:42 am

I guess Ogre3D is about the only reason for me to use C++ in the context of game programming. Developing with C# or something like that feels much smoother.
0 x
Enough is never enough.

Fulmens
Gremlin
Posts: 151
Joined: Sun Jun 22, 2008 8:29 pm
Location: Nantes, France

Re: What's wrong with C++?

Post by Fulmens » Mon Feb 08, 2010 10:08 am

jacmoe wrote:That FQA is not written by C++ programmers - or so it seems.
I don't buy those arguments.
Well, I think you didn't browse the FQA enough before saying that. To me, the guy knows of what he is talking about. I don't say he is always right ; but as he says himself about what he considers quirks of C++ :
To be fair, some of the items by themselves could be design choices, not bugs.
And in his FAQ :
You are not very objective, are you?

No - it's your job. Do stuff, read stuff, think and make up your mind. Have you actually selected an entity which you think of as "objective"? This is like having a slave port in your brain.
Don't make me tell what I didn't, C++ is my favorite language for various reasons even though I've tried many others. But I found this FQA really interesting ; after all, when you love something, isn't it a good thing to know what his detractors are saying about, rather than being a zealot ?
I read most of the FQA (and the C++ faq lite too, of course), and it just strenghtened my opinion on one thing : C++ is a hard language, with its defects, but it didn't prevent me to go on working with it.
To summarize, the FQA doesn't reflect my opinion ; but it's far from being a random bunch of crap to me.
Last edited by Fulmens on Mon Feb 08, 2010 10:09 am, edited 1 time in total.
0 x

User avatar
syedhs
Silver Sponsor
Silver Sponsor
Posts: 2702
Joined: Mon Aug 29, 2005 3:24 pm
Location: Kuala Lumpur, Malaysia
x 1

Re: What's wrong with C++?

Post by syedhs » Mon Feb 08, 2010 10:08 am

I think nothing wrong - the world is just so diverse. Probably they should have asked themselves - what is your OS made up of? :mrgreen:

My interest in C (and then C++) began when I read a newspaper article that C is very hard to learn - I never heard C language before. I said.. wow.. that is good challenge, and the just one letter for the language name speaks of its brevity.

But with all honesty, I really think that C/C++ now belongs to elite programmers. It is comparatively harder to learn, and be productive with. And with certain applications like games engine, the result is well worth it.
0 x
A willow deeply scarred, somebody's broken heart
And a washed-out dream
They follow the pattern of the wind, ya' see
Cause they got no place to be
That's why I'm starting with me

User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
Contact:

Re: What's wrong with C++?

Post by jacmoe » Mon Feb 08, 2010 10:43 am

Fulmens wrote:Don't make me tell what I didn't, C++ is my favorite language for various reasons even though I've tried many others. But I found this FQA really interesting ; after all, when you love something, isn't it a good thing to know what his detractors are saying about, rather than being a zealot ?
...
To summarize, the FQA doesn't reflect my opinion ; but it's far from being a random bunch of crap to me.
No, don't get me wrong. I've bookmarked it, actually. :)
I like reading stuff like that, as much as I like to read Scott Meyers and various other C++ blogs.

I can't really explain what appeals to me about C++, I find it aesthetically pleasing in some twisted way.
And I like a challenge. :)

I am really looking forward to C++1x (let's hope it doesn't end up as C++2x) as it seems to fix a lot of issues with C++ as a language.
0 x
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.

User avatar
stealth977
Gnoll
Posts: 638
Joined: Mon Dec 15, 2008 6:14 pm
Location: Istanbul, Turkey

Re: What's wrong with C++?

Post by stealth977 » Mon Feb 08, 2010 12:03 pm

Well, whats the base of all constitutions? FREEDOM...

So, i like to be FREE to shoot my own feet with C++, yes it does let you do that in many ways that i human mind can not memorize, but its the most effective language that sets you totally free. If there exists a language which doesnt let you harm your own code, thats a restriction and that means you are not FREE...NO WAY!

:)
0 x
Ismail TARIM
Ogitor - Ogre Scene Editor
WWW:http://www.ogitor.org
Repository: https://bitbucket.org/ogitor

User avatar
Kyle_Katarn
Halfling
Posts: 92
Joined: Tue Jul 21, 2009 7:51 am
Location: Australia

Re: What's wrong with C++?

Post by Kyle_Katarn » Mon Feb 08, 2010 12:16 pm

One thing I like about C++ is that it doesnt pat you on the head and say "Dont worry, I will protect you from those nasty, scary and mean pointers. And rest your head, I'll clean up after you."

It's a hard ass language to learn, but it feels very rewarding.

And stealth is right, or at the very least, I agree with him, if I wanna shoot myself in the foot, so be it, let me learn that lesson.
*Feels slightly C++ elitist*
0 x

User avatar
_tommo_
Gnoll
Posts: 677
Joined: Tue Sep 19, 2006 6:09 pm
Contact:

Re: What's wrong with C++?

Post by _tommo_ » Mon Feb 08, 2010 12:21 pm

Sometimes i hate C++, but i just can't use in the same way the other languages... it's a love/hate relation, just like with Windows :)

Sometimes is downright ugly and old, for example for anything that concerns preprocessor or generic typization (o both :evil: ) but it's also unreplaceable when you need high level features with the lowest footprint possible... it's incredible HOW MANY clock cycles are just wasted by the higher level languages.

So there's a lot wrong with C++, but i would not use anything else :)
0 x
OverMindGames Blog
IndieVault.it: Il nuovo portale italiano su Game Dev & Indie Games

User avatar
mkultra333
Gold Sponsor
Gold Sponsor
Posts: 1820
Joined: Sun Mar 08, 2009 5:25 am
x 11

Re: What's wrong with C++?

Post by mkultra333 » Mon Feb 08, 2010 12:24 pm

I hate the idea of people being put off of C++ because it's supposedly "difficult." I went from programming BASIC to programming C++, and it wasn't a hard transition at all, because for me programming meant functions, loops, branching and variables. I programmed C++ for years with barely a clue what a class was, and I still only use a bare minimum of C++ capabilities. Polymorphic, virtual, STL, blah blah blah, who cares, I have some numbers I want to crunch and C++ for-next loops, if-else and other simple function calls did fine.

Some might say "Well, if that's all you wanted to do, why not use another, easier language?" The reason is that with C++ I knew I was future proof. I don't have to worry about people writing wrappers for stuff (for instance, I don't have to access Ogre through a wrapper), and as the need arises for more complicated techniques I don't have to worry that my language will hit a wall, making my prior years of experience worthless.

I think the horrors of C++ are exaggerated. Not becauses it doesn't have some ghastly areas of mind torturing obtuse, abstract nonesense, but because you only need engage that obtuse, abstract nonsense if you choose. C++ will happily let you play in a kiddie pool, far from the shark infested waters in it's deep end, and you know you can always swim out further if the need arises or your curiosity gets the better of you.
0 x
"In theory there is no difference between practice and theory. In practice, there is." - Psychology Textbook.

User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
Contact:

Re: What's wrong with C++?

Post by jacmoe » Mon Feb 08, 2010 12:29 pm

mkultra333 wrote:C++ will happily let you play in a kiddie pool, far from the shark infested waters in it's deep end, and you know you can always swim out further if the need arises or your curiosity gets the better of you.
Well put.
Extremely well put, actually. :)
You decide how hairy it's going to get.
Not a lot of languages let you do that.
0 x
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.

User avatar
syedhs
Silver Sponsor
Silver Sponsor
Posts: 2702
Joined: Mon Aug 29, 2005 3:24 pm
Location: Kuala Lumpur, Malaysia
x 1

Re: What's wrong with C++?

Post by syedhs » Mon Feb 08, 2010 1:17 pm

I really think C++/C is difficult, although I find myself very comfortable with it. And make no mistake there are lots of good programmers here, so you all may think that C++ is natural transition of whatever - and that is a honest compliment, if you may wonder what my statement means :)

But real world dictate the real thing: good and productive C++ programmers are hard to find, if you can find them they are already snatched by big firms who has granted them scholarship - sometimes, from their first year in the universities. That is part of the reason why there is a need for games script like LUA, Squirrel so that the everyone can easily pick it up (scripting programming).
0 x
A willow deeply scarred, somebody's broken heart
And a washed-out dream
They follow the pattern of the wind, ya' see
Cause they got no place to be
That's why I'm starting with me

jjp
Silver Sponsor
Silver Sponsor
Posts: 597
Joined: Sun Jan 07, 2007 11:55 pm
Location: Cologne, Germany
Contact:

Re: What's wrong with C++?

Post by jjp » Mon Feb 08, 2010 5:45 pm

I am totally not on that line. Of course you have a lot of freedom with C++ and it does follow a consistent design paradigm, i.e. performance >>> everything else. But practically it has a huge load of inconveniences and I am certain that even the most experienced C++ programmer will be more productive with almost any other language in the majority of situations. I would like to see the example where you could write something in 10 lines of C++ and it took 300+ lines in a higher level language.
0 x
Enough is never enough.

User avatar
madmarx
OGRE Expert User
OGRE Expert User
Posts: 1668
Joined: Mon Jan 21, 2008 10:26 pm

Re: What's wrong with C++?

Post by madmarx » Mon Feb 08, 2010 8:10 pm

I would like to see the example where you could write something in 10 lines of C++ and it took 300+ lines in a higher level language.
I don't understand this : with a good library you can do whatever you want, in the number of line that you want/need.

Example 1 :

Code: Select all

#include "Cimg.h"
Cimg<unsigned char> image("myImage.bmp"); // loading done.
Example 2 :

Code: Select all

#include "GisUltra.h"
Filter_NoFilter f;
Matrix m;
GisUltra image("myImage.ecw")
  .setMultithreadedCPUs(0,1,2)
  .setRasterizer("12523,92776", "12883,9920376",f)
  .setRamConsumption(500000 * sizeof(unsigned char))
  .deltaLimitBias(0.7)
  .setOriginalMatrix(m);
;
Of course in both case you just load an image. 1 Mb vs 50TB.

Problems arise when there are either bad libraries or too complex one for the usage that you may want.

bad framework => bad work anyway.
C++ => availability of many various good frameworks.
0 x
Tutorials + Ogre searchable API + more for Ogre1.7 : http://sourceforge.net/projects/so3dtools/
Corresponding thread : http://www.ogre3d.org/forums/viewtopic. ... 93&start=0

User avatar
syedhs
Silver Sponsor
Silver Sponsor
Posts: 2702
Joined: Mon Aug 29, 2005 3:24 pm
Location: Kuala Lumpur, Malaysia
x 1

Re: What's wrong with C++?

Post by syedhs » Mon Feb 08, 2010 8:36 pm

Justboo,

I think when the coding requires workaround, then it is normal to have 10 lines done in more than hundreds line - it is normal. I have done database programming in both C++ and VB, and given everything else equal C++ code always come up the harder one. VB even notoriously earn the reputation of stupidly easy, but practical enough for big commercial application.

To be fair, it is not necessarily the higher the LOC (line of code), the more difficult it is - although in many cases, it is true. I think the sentiment is this: given the same task which is doable by both languages, and everything else equal, C++ always come up harder to read, prone to error (eg failure to initialize variables or incorrect usage of pointers.) Aha.. pointers. A good VB programmer never ever have to deal with pointers. Of course, pointers are very powerful, but they are easy to crash the app too.
0 x
A willow deeply scarred, somebody's broken heart
And a washed-out dream
They follow the pattern of the wind, ya' see
Cause they got no place to be
That's why I'm starting with me

User avatar
lonewolff
Ogre Magi
Posts: 1199
Joined: Wed Dec 28, 2005 12:58 am
x 2

Re: What's wrong with C++?

Post by lonewolff » Mon Feb 08, 2010 9:30 pm

jjp wrote:I would like to see the example where you could write something in 10 lines of C++ and it took 300+ lines in a higher level language.
Not quite as asked, but here is an entire Hello World application in 16 bit assembly (21 bytes long - yes the application is 25 bytes - not 100 Kb) :)

Code: Select all

MOV AH,09
MOV DX,0107
INT 21
MOV AH,00
INT 21
// Fill in the following hex codes from next line
// \/ Hexcodes for "Hello World!" \/
4865 6C6C 6F20 576F 726C 6421 24
The C++ version of this app is 4000 times the size!

Can't get lower than that.

[edit]
That said though, I prefer C++ :wink:
I must have grown to like banging my head against that brick wall :lol:
0 x

User avatar
_tommo_
Gnoll
Posts: 677
Joined: Tue Sep 19, 2006 6:09 pm
Contact:

Re: What's wrong with C++?

Post by _tommo_ » Tue Feb 09, 2010 12:24 am

25 bytes in size, but 25 hours in time :D

You can't really say that using few lines of lowlevel code is just as simple than 300 lines of verbose java class-scripting... I mean, I too hate when you have to instantiate 3 classes (it's true!) only to read a crappy txt, but to the newcomer that comes as a miracle :D
Just think of it vs the C equivalent in terms of programmer time, where the "programmer" is not a passionate C++ expert that you can found around here, but just another type of office worker.
Clearly, that's more efficient for the company. And clearly, i would never like something like that :mrgreen:
0 x
OverMindGames Blog
IndieVault.it: Il nuovo portale italiano su Game Dev & Indie Games

User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7140
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 9

Re: What's wrong with C++?

Post by Kojack » Tue Feb 09, 2010 2:17 am

The C++ version of this app is 4000 times the size!
I just built a hello world in visual c++ 2008, size is 6656 bytes, so it's only 266 times bigger.
Still pretty big, but it could be cut down a lot if the standard libraries and c++ runtime weren't used (as I've done on gba).
0 x

User avatar
lonewolff
Ogre Magi
Posts: 1199
Joined: Wed Dec 28, 2005 12:58 am
x 2

Re: What's wrong with C++?

Post by lonewolff » Tue Feb 09, 2010 2:35 am

6.6K is pretty good though. :)

You might be able to get it down to 4K (or less) if you cheat and run it through UPX301.exe

Witth the initial post from Jacmoe. I don't think there is anything wrong with C++ (as frustrating as it can be sometimes). Sure, I would love to boast and do everything in 32 bit assembly. But, I would never get anything done as productivity would go out the door.

You also can't beat the support you get from other users. Whenever you as a programming question on the web, people just assume that you are using C++. 8)
0 x

User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7140
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 9

Re: What's wrong with C++?

Post by Kojack » Tue Feb 09, 2010 3:00 am

You might be able to get it down to 4K (or less) if you cheat and run it through UPX301.exe
Good guess, upx got it to 4608 bytes. :)
0 x

User avatar
volca
Gnome
Posts: 393
Joined: Thu Dec 08, 2005 9:57 pm
Contact:

Re: What's wrong with C++?

Post by volca » Tue Feb 09, 2010 7:39 am

JustBoo wrote:In 27 years time, every time I’ve tried “programming outside the box” using some scripting language or some 4GL/5GL language I ALWAYS ended up fighting, either the lame language itself or some nut-job constraint the language author put there to “help me.” I get frustrated when I have to write 300 lines of code in some goofy language to overcome a bad design choice by the authors when I could have done it in ten lines of C++ code. Can anyone (a professional) deny this has happened to them as well? Many of these “new” languages promote programming on a Rail. Not much thought required. Hell, one even named itself appropriately. Ruby on Rails. With C# (which I do use when appropriate) you too can write The-Next-Big-Astonishing-Never-Before-Seen-WinForms-Tied-To-A-Database-App. Woohoo.
Finally I hear this from somebody else :) I attribute this to the fact you get used to the luxury of C++. You get features and responsibility. The first is nice, the latter is easily got used to after some time. Going down to some other language means loss of features, or heck even receiving artificial limitations as a bonus. Outcome of this is frustration. :evil:

What I always grunt about for this reason is Java. It has an unfinished type system which, after it introduced generics, produces an unreadable and tiresome to write code (give me my typedef dammit! :) ). It has a standard library that was designed by a monkey probably, because there is no way this would be designed by someone thinking about practical usage (think XML handling for example). Thus all the apache libraries that try to replace the chaos in the standard libraries have to be used instead (sure, some of them actually add missing functionality, but that does not matter much). Thus a library like Joda time has to be used instead of the built in date-time classes. What puzzles me, for example, is that there is a foreach construct in the newer java versions, but it does not have a reverse iteration variant. Why can't I use primitive types in generics? (I know an answer to this, but it is stupid: Because it would mean operator overloading, which is a big no no :roll: )... and it goes on and on... :)
0 x
Image

jjp
Silver Sponsor
Silver Sponsor
Posts: 597
Joined: Sun Jan 07, 2007 11:55 pm
Location: Cologne, Germany
Contact:

Re: What's wrong with C++?

Post by jjp » Tue Feb 09, 2010 4:58 pm

lonewolff wrote:here is an entire Hello World application in 16 bit assembly (21 bytes long - yes the application is 25 bytes - not 100 Kb) :)
You're not answering the question ;) Obviously I mean the size of the source code, not of the compiled code.
0 x
Enough is never enough.

User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
Contact:

Re: What's wrong with C++?

Post by jacmoe » Tue Feb 09, 2010 5:01 pm

If you're looking for small size source code, why not Lisp ? :D
0 x
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.

Post Reply