# What makes C++ so powerful?

This topic is 4265 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Quote:
 Original post by OluseyiAnyway, the nonsense persists, so it's time to bust out the heavy guns!So you think you know C++ Quiz 1 and commentarySo you think you know C++ Quiz 2 and commentary

Either those links are broken or the site they link to is broken. Some VBScript error or something...

##### Share on other sites
Quote:
Original post by CTar
Quote:
 Original post by Kazegames seem to not lend themselves well to most "good" oop practices and i usually end up with messy unmodular code that could have been done with much less code in a more flexible environment.

That's most likely your fault, OOP is perfectly capable of describing a game. Also what do you mean, when you say a "more flexible envirornment"? A procedural language like C or C++?

1 mostly that games inherintly have high coupling as you needs most of the main game elements to interact with each other, note that im not saying it cant be done, im just saying it dosent give a lot of benifit and usally requires more code and presents more organization problems
2 yes c++ but i also find .net to be a nice balance of flexibility and organized object driven design

##### Share on other sites
Fixed. It doesn't take #'s for some reason, i blame the dart:

##### Share on other sites
No, it was some wierdness with the forum software parsing - and subsequently mangling - links that have in-page anchors (ie, "URL#anchor") where the URL ends in an ampersand. Fixed by using good old &amp;.

##### Share on other sites
Your fix failed! You are firod!

C++ is a very hard language to master, even members of the standards body make mistakes with regards to the language from time to time.

##### Share on other sites
Quote:
 Just give'em a header from one of boost libraries that generates code from a mix of macro & template metaprogramming and they lay a brick in their paints....

snipped for brevity
#ifndef BOOST_ASSIGN_MAX_PARAMS // use user's value#define BOOST_ASSIGN_MAX_PARAMS 5#endif        #define BOOST_ASSIGN_MAX_PARAMETERS (BOOST_ASSIGN_MAX_PARAMS - 1) #define BOOST_ASSIGN_PARAMS1(n) BOOST_PP_ENUM_PARAMS(n, class U)#define BOOST_ASSIGN_PARAMS2(n) BOOST_PP_ENUM_BINARY_PARAMS(n, U, const& u)#define BOOST_ASSIGN_PARAMS3(n) BOOST_PP_ENUM_PARAMS(n, u)#define BOOST_PP_LOCAL_LIMITS (1, BOOST_ASSIGN_MAX_PARAMETERS)#define BOOST_PP_LOCAL_MACRO(n)     template< class U, BOOST_ASSIGN_PARAMS1(n) >     generic_ptr_list& operator()(U const& u, BOOST_ASSIGN_PARAMS2(n) )     {         this->push_back( new T(u, BOOST_ASSIGN_PARAMS3(n)));         return *this;     }     /**/        #include BOOST_PP_LOCAL_ITERATE()    }; // class 'generic_ptr_list'} // namespace 'assign_detail'namespace assign{    template< class T >    inline assign_detail::generic_ptr_list<T>    ptr_list_of()    {        return assign_detail::generic_ptr_list<T>()();    }        template< class T, class U >    inline assign_detail::generic_ptr_list<T>     ptr_list_of( const U& t )    {        return assign_detail::generic_ptr_list<T>()( t );    }#define BOOST_PP_LOCAL_LIMITS (1, BOOST_ASSIGN_MAX_PARAMETERS)#define BOOST_PP_LOCAL_MACRO(n)     template< class T, class U, BOOST_ASSIGN_PARAMS1(n) >     inline assign_detail::generic_ptr_list<T>     ptr_list_of(U const& u, BOOST_ASSIGN_PARAMS2(n) )     {         return assign_detail::generic_ptr_list<T>()(u, BOOST_ASSIGN_PARAMS3(n));     }     /**/    #include BOOST_PP_LOCAL_ITERATE()

##### Share on other sites
Quote:
Original post by Anonymous Poster
Quote:
 Original post by Anonymous PosterWhat about changing variables in hand directly from memory?What a terrible thing to do. A Java programmer does not think in terms of memory addresses ;)

What about making visual effect by changing memory. Some tricks known well from many years.

Java primitives are in fact something like virtual registers, and arrays are an abstraction of direct memory access. So expericenced programmer is able to think in terms of CPU registers, if he want, without worrying about any manual register allocation.

While Java prgrammer (not scrip kiddies) could do index arithmetic on array, in most situation they are using OpenGL, because of simplicity.

//
C++ like operator overloading decreases source code predictability. Imagine situation when you can see.
vector3D a = new vector3D(3D, 5D, 3D);
c = a * b;

And now tell me what is "c"? And what is the result of a * b?

##### Share on other sites
Quote:
 Original post by RagharC++ like operator overloading decreases source code predictability. Imagine situation when you can see. vector3D a = new vector3D(3D, 5D, 3D);c = a * b;And now tell me what is "c"? And what is the result of a * b?
The way I see it, the fundamental difference is as such. C++ functions under the (often incorrect) assumption that the programmer is competent. In contrast, Java assumes (sometimes correctly) the programmer is a dumbass who will make every mistake he can possibly make, turning his code base into a mess. As a result, C++ gives you all sorts of powerful tools, some very dangerous. Java takes away anything which the Java designers perceived as having any potential for abuse.

It's probably clear which side I favor.

##### Share on other sites
Quote:
Original post by Talroth
Quote:
 Original post by nmiAnd you should remember that Java also needed a second start (the first version was called 'Oak' if I remember correctly).

I'm fairly sure I read somewhere that Java was first called OAK, but changed to java due to copyright issues, (there was already a project oak) and the last version of Oak was the same as the first version of Java. I can look it up to be sure if someone cares.

Java is to OAK as Wii is to Revolution. Name OAK was used by different programming language so they decided to release it under another name. (It would be confusing if there would be two different languages with the same name. In fact even name javascript was confusing.)

BTW language specification is here.

http://java.sun.com/docs/books/jls/

##### Share on other sites
Quote:
 Original post by PromitThe way I see it, the fundamental difference is as such. C++ functions under the (often incorrect) assumption that the programmer is competent. In contrast, Java assumes (sometimes correctly) the programmer is a dumbass who will make every mistake he can possibly make, turning his code base into a mess. As a result, C++ gives you all sorts of powerful tools, some very dangerous. Java takes away anything which the Java designers perceived as having any potential for abuse.It's probably clear which side I favor.

Cute. ^_^

I'm using programming language as I want, not as it is expected to be used. However when you are talking about powerful tools, what happened to multipass compiler, short compile times, multiple entry points into program, type sizes preciselly defined in the standard, and SHR? To be forced into creating both 32 bit and 64 bit executable isn't nice either.

##### Share on other sites
Quote:
 Original post by RagharC++ like operator overloading decreases source code predictability. Imagine situation when you can see. vector3D a = new vector3D(3D, 5D, 3D);c = a * b;And now tell me what is "c"? And what is the result of a * b?
That's not really fair. Bad code can be written in any language.

vector3D a = new vector3d(3D, 5D, 3D);
c = a.Multiply(b);

Is that any clearer? Of course not. I'd assume b is either another 3d vector or a matrix of the correct dimensions. C could be the cross product. Maybe the dot product. Maybe b is a magnitude, and c is the scaled vector. Maybe the result of a matrix transformation. Regardless, poorly written code is poorly written code.

Vector3d unitVec = new Vector3d(x,y,z);
scaledVec = unitVec * scale.

The source code is only as readable as the programmer is willing to make it.

##### Share on other sites
well I can't recall reading through these 6 pages of replies and seeing the answer, so I'll put it here:

The Programmer!

##### Share on other sites
Quote:
 Original post by RagharI'm using programming language as I want, not as it is expected to be used. However when you are talking about powerful tools, what happened to multipass compiler, short compile times, multiple entry points into program, type sizes preciselly defined in the standard, and SHR? To be forced into creating both 32 bit and 64 bit executable isn't nice either.
And I moved to C# for my hobby work for the exact same reasons. Java did a lot of good things, but I feel like Java made a vast number of mistakes at the same time, and those mistakes are a point of considerable irritation for me when I have to work in Java.

##### Share on other sites
Quote:
Original post by Oberon_Command
Quote:
 Original post by SpoonbenderIf you really disagree with me, then show me a program in C++ that couldn't have been made using C#.

An operating system? You would need a C# compiler that compiles to native binary, and to the best of my knowledge there aren't any...

C# operating system
http://channel9.msdn.com/ShowPost.aspx?PostID=68302
A programming language can be used to do anything. To acknowledge a languages weaknesses is logical, but to say that it can't out right perform a task that all programming languages can do is foolish for it limits ones own creativity and sets a box on what can and cannot be done.

all programming languages have their strengths and their weaknesses.
The skill of the programmer can be used to overcome those weaknesses but when in a situation where the weakness of the programming language is too apparent than use another one.

C++ is a balanced language and can be considered the best simply because of the legacy it is build. No other programming language is as documented, as source happy, and as analyzed as it.

The fact of the matter is that it is the most widely used language out there, and it's one of the oldest. There is power in numbers. There is power in knowledge. Because of how programming works the most popular language becomes
The most powerful language.

C++ is the most popular language, thus it is the most powerful.

##### Share on other sites
Quote:
 Original post by JustOwninDaFINALBOSSC++ is the most popular language, thus it is the most powerful.

Popularity is a pathetic heuristic to determine whether a programming language is any good/powerful/elegant/etc/etc. Java being a prime example of it (time to put on the old flame, bullet, and bomb proof vest).

[Edited by - snk_kid on May 15, 2006 7:05:01 AM]

##### Share on other sites
Somebody mentioned operator overloading, there is nothing wrong with it infact it can be one of the vital ingredients for the recipe of domain-specific embedded language (DSEL). The problem with C++'s operator overloading model is it's quite limited and functions are not first class so one must resort to hackery and expression templates to achieve DSEL combinator libraries in C++.

##### Share on other sites
Quote:
Original post by Cold_Steel
Quote:
 Original post by RagharC++ like operator overloading decreases source code predictability. Imagine situation when you can see. vector3D a = new vector3D(3D, 5D, 3D);c = a * b;And now tell me what is "c"? And what is the result of a * b?
That's not really fair. Bad code can be written in any language.

vector3D a = new vector3d(3D, 5D, 3D);
c = a.Multiply(b);

Is that any clearer? Of course not. I'd assume b is either another 3d vector or a matrix of the correct dimensions. C could be the cross product. Maybe the dot product. Maybe b is a magnitude, and c is the scaled vector. Maybe the result of a matrix transformation. Regardless, poorly written code is poorly written code.

Vector3d unitVec = new Vector3d(x,y,z);
scaledVec = unitVec * scale.

The source code is only as readable as the programmer is willing to make it.

fully agreed. code is as readable as you make it.

personally, i would like a language where defining functions is much more flexible: you should be able to give it any name, be it "+" or whatever, and you should be able to specify if it only takes arguments on its right hand side, or that it accepts arguments from both sides, or is used as an unary operator.

something like function := [arglist] = [arglist] "functionname" [arglist].

i believe python does something like that?

##### Share on other sites
Quote:
 Original post by Eelcopersonally, i would like a language where defining functions is much more flexible: you should be able to give it any name, be it "+" or whatever, and you should be able to specify if it only takes arguments on its right hand side, or that it accepts arguments from both sides, or is used as an unary operator.something like function := [arglist] = [arglist] "functionname" [arglist].i believe python does something like that?

In haskell one can overload virtually any symbol with any number together (like +++ for instance) one can state the artery, associativity and precedence levels. Named functions can be made infix using quasi-quotes i.e 1 plus 2 is the same as plus 1 2, operators can be sectioned, all functions (including operators) are first-class so they can be passed/returned/stored. These are the reasons why haskell is so good for writing domain specific embedded languages (DSELs).

##### Share on other sites
Quote:
 Original post by JustOwninDaFINALBOSSA programming language can be used to do anything.

No, not if it doesn't have support for it. For example C# 2.0 doesn't have much support for systems programming, and no Singularity (the OS you talked about) is not coded in C#, it's coded in Sing#, which is a superset of the Spec#, which is an extension of C#. Also 2 % of the kernel is written in asm and 3 % is written in C++. The system used by Sing# is called Bartok.

Quote:
 C++ is a balanced language and can be considered the best simply because of the legacy it is build. No other programming language is as documented, as source happy, and as analyzed as it.

Does this make C++ a good language? No, legacy is a reason to why one might choose C++, it doesn't make the language itself more powerful.

Quote:
 The fact of the matter is that it is the most widely used language out there, and it's one of the oldest. There is power in numbers. There is power in knowledge. Because of how programming works the most popular language becomes The most powerful language.

Yes, because your program suddenly gets much better when 10000 other programmers starts to program in the same language.

##### Share on other sites
Quote:
 Original post by snk_kidPopularity is a pathetic heuristic to determine whether a programming language is any good/powerful/elegant/etc/etc. Java being a prime example of it (time to put on the old flame, bullet, and bomb proof vest).

Popularity is a pathetic heuristic to determine whether anything is good/powerful/elegant/etc/etc. Just turn on FM radio or pick up one of the romantic novels from the bestsellers section.

##### Share on other sites
Quote:
 Original post by CTarDoes this make C++ a good language? No, legacy is a reason to why one might choose C++, it doesn't make the language itself more powerful.

There is certainly some value in popularity. Ability to hire reasonably proficient programmers for less than astronomic salaries. Large body of available libraries and documentation. Ability to get some support from public forums.

I'm playing a devil's advocate. I'd hire four Lisp programmers rather than ten Java programmers for the same total price any day.

##### Share on other sites
Quote:
Original post by CTar
Quote:
 Original post by JustOwninDaFINALBOSSA programming language can be used to do anything.

No, not if it doesn't have support for it. For example C# 2.0 doesn't have much support for systems programming, and no Singularity (the OS you talked about) is not coded in C#, it's coded in Sing#, which is a superset of the Spec#, which is an extension of C#. Also 2 % of the kernel is written in asm and 3 % is written in C++. The system used by Sing# is called Bartok.

Quote:
 C++ is a balanced language and can be considered the best simply because of the legacy it is build. No other programming language is as documented, as source happy, and as analyzed as it.

Does this make C++ a good language? No, legacy is a reason to why one might choose C++, it doesn't make the language itself more powerful.

Quote:
 The fact of the matter is that it is the most widely used language out there, and it's one of the oldest. There is power in numbers. There is power in knowledge. Because of how programming works the most popular language becomes The most powerful language.

Yes, because your program suddenly gets much better when 10000 other programmers starts to program in the same language.

No the langueage itself does not get better. But the language as a tool gets better. Much better.

C++ is not in itself a superior language - actually some may consider it a horrible language considering all its bagage. But the fact that it's so widely used, documented, and so many third-party components exist for use with C++, makes C++ as a tool vastly better than it would've been without all those accesories.

So in a way C++ does improve (as a tool) simply on the account of the number of people using it.

##### Share on other sites
Quote:
 Original post by CoffeeMugThere is certainly some value in popularity. Ability to hire reasonably proficient programmers for less than astronomic salaries. Large body of available libraries and documentation. Ability to get some support from public forums.

Yes, good reasons to choose the language, but the language won't get any better because of it. The person I was quoting said that C++ could be considered the best simply because of legacy.

rohde: I agree