ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
For graphics or scientific computing, OO programming is ok, I agree with that. The problem is when people use C++ for everything (there is an interesting point of view from Eric S. Raymond here.)
That's pretty much my point of view.
The only place I really see OO being practical is in programs where the user interacts with objects, like characters in a game or widgets in a GUI.
But when programming in Java I noticed I was doing excessive, unnecessary, and kludgy layering because it forces me to use OO even where you shouldn't.
But I still like OO for those applications. The reason I don't like C++ is not because it's OO, but because it's IMO poorly done.
Last edited by MTK358; 04-15-2010 at 09:18 AM.
Click here to see the post LQ members have rated as the most helpful post in this thread.
But I still like OO for those applications. The reason I don't like C++ is not because it's OO, but because it's IMO poorly done.
You need to read "The Design and Evolution of C++". It says *exactly* why all the warts are there, and why it's about the best way that "better C" could have really happened given practical constraints.
Really, I don't like it when anybody writes off C++ without really understanding why it came to be the way it is, and ends up retreading over the exact same ground that Stroustrup did.
What I meant about Torvalds vs Stroustrup achievements was in the sense of pragmatical vs theoretical when it comes to big projects coordination and maintenance. Anyways I will read the book.
Can anybody explain the big argument in noob-speak because I don't even understand it. I mean in my project I made a structure that loads images into openGL and then I made another structure that holds all the guys on my map and every cycle of the game that structure is sent an update signal. I use C++ and those structures have all their own functions and private variables. But I guess I could just as easily have used C and used malloc and figured out how to get by without constructors and destructors.
I don't know. I guess I haven't done anything big enough to see the pitfalls of C++ that everyone is talking about.
I believe there's a way you can ask CLang for that.. Useful for debugging the compiler, and utterly useless for debugging actual programs.
...
???
No, it doesn't make sense. The true templates power is in templates specialization (IIRC the term). I.e. templates are expanded recursively, often with "branches", i.e. one of possible ways of expansion is chosen depending on inputs.
So far so good.
Now, if there is an error in templates, expansion may run (remember, it's recursion !) until memory is exhausted. And exactly this scenario I want to be able to track. I.e. i want to be able to see as early as possible at what moment the expansion went wrong. I.e. in I want to see the final template-less C++ file with messages more or less like this:
Code:
// expanding template FOO(arg1, arg2, ... argN) from line #NUMBER from 'SOURCE.cpp' file
.
Whenever I write a code generator/template engine, I from the very beginning implement such functionality. And I do not understand why the mainstream C++ compilers do not have it - the compilers definitely know what they are expanding with what arguments.
If CLang (part of LLVM, right ?) does this, it's the first decent C++ compiler I've heard of.
Can anybody explain the big argument in noob-speak because I don't even understand it. I mean in my project I made a structure that loads images into openGL and then I made another structure that holds all the guys on my map and every cycle of the game that structure is sent an update signal. I use C++ and those structures have all their own functions and private variables. But I guess I could just as easily have used C and used malloc and figured out how to get by without constructors and destructors.
I don't know. I guess I haven't done anything big enough to see the pitfalls of C++ that everyone is talking about.
The power of C++ vs "C" is the ability of C++ to decide many many things (much more than "C") at compile time. But, as I'm trying to point this out, this useful ability is implemented through C++ template engine, and the latter is real pain in parts of the body to debug.
...
C++ is used pretty heavily on the Joint Strike Fighter (aka F-35).
...
Hardly an argument in favor of C++ - taking into account how expensive the whole project happens to be .
But yes, C++ is used a lot in scientific calculation, and from one quite efficient project related to matrix manipulation I know how templates are difficult to debug.
So is the STL a bad thing? I thought it was a good thing. What do C programmers do when they want a queue or a linked list? Do they code each one up fresh or is there a C version of the STL?
So is the STL a bad thing? I thought it was a good thing. What do C programmers do when they want a queue or a linked list? Do they code each one up fresh or is there a C version of the STL?
Who said STL was bad ?
Actually, STL is often criticized for inefficiency, but there are alternatives. So STL by itself can't be an argument against C++.
Not me. I like STL. It uses templates though and I thought the C fanatics were bashing templates. I think Torvalds trashed STL in his rant. I don't know. I guess I will have to quit thinking about it. After I do a few projects I will look back and comprehend what everyone is talking about.
Not me. I like STL. It uses templates though and I thought the C fanatics were bashing templates. I think Torvalds trashed STL in his rant. I don't know. I guess I will have to quit thinking about it. After I do a few projects I will look back and comprehend what everyone is talking about.
I am saying that a fundamental C++ flaw in its present implementation is undebuggability of templates. I.e. I see no real reason for templates to be undebuggable, I just see really bad from the point of debugging implementation.
For graphics or scientific computing, OO programming is ok, I agree with that. The problem is when people use C++ for everything (there is an interesting point of view from Eric S. Raymond here.)
As someone with a job writing web applications in C++, I agree with you.
I am saying that a fundamental C++ flaw in its present implementation is undebuggability of templates. I.e. I see no real reason for templates to be undebuggable, I just see really bad from the point of debugging implementation.
Even compiler error messages are utterly horrible. A simple map<string, string> turns into
That is the book to have, often referred to as "The Gang of Four" I'll highlight two patterns from the text which you may want to look at:
Singleton
Factory
The Singleton is useful when you only ever want a single instance of an object. This could be (for example) the World object of your game, or maybe a parser which you use to convert instructions to method calls. Once you understand that pattern you see uses for it in many different guises.
The factory pattern (there are several flavours) essentially returns an instance of an object for you. So if you have a string that says "apple" you can send it to the factory and it will return an Apple object, now send the factory the string "pear" and it will send you a Pear object.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.