LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-15-2010, 09:15 AM   #76
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723

Quote:
Originally Posted by manu-tm View Post
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.
Old 04-15-2010, 09:30 AM   #77
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
Quote:
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.
 
Old 04-15-2010, 10:07 AM   #78
manu-tm
Member
 
Registered: May 2008
Location: France
Distribution: Ubuntu, Debian
Posts: 343

Rep: Reputation: 43
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.
 
Old 04-15-2010, 05:21 PM   #79
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
Originally Posted by smeezekitty View Post
Just always take Sergei Steshenko's posts with a grain of salt.
Same as with yours, you mean?

Yours preferably with salt & tequila.
 
1 members found this post helpful.
Old 04-15-2010, 05:23 PM   #80
icecubeflower
Member
 
Registered: Mar 2008
Location: USA
Distribution: Slackware 13.1
Posts: 313

Rep: Reputation: 34
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.
 
Old 04-15-2010, 05:36 PM   #81
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by tuxdev View Post
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.
 
Old 04-15-2010, 05:39 PM   #82
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by icecubeflower View Post
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.
 
Old 04-15-2010, 05:45 PM   #83
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by tuxdev View Post
...
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.

And the efficiency comes from templates.
 
Old 04-15-2010, 06:25 PM   #84
icecubeflower
Member
 
Registered: Mar 2008
Location: USA
Distribution: Slackware 13.1
Posts: 313

Rep: Reputation: 34
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?
 
Old 04-15-2010, 06:39 PM   #85
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by icecubeflower View Post
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++.
 
Old 04-15-2010, 07:11 PM   #86
icecubeflower
Member
 
Registered: Mar 2008
Location: USA
Distribution: Slackware 13.1
Posts: 313

Rep: Reputation: 34
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.
 
Old 04-15-2010, 07:18 PM   #87
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by icecubeflower View Post
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.
 
Old 04-15-2010, 10:08 PM   #88
Dan04
Member
 
Registered: Jun 2006
Location: Texas
Distribution: Ubuntu
Posts: 207

Rep: Reputation: 37
Quote:
Originally Posted by manu-tm View Post
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.
 
Old 04-15-2010, 10:17 PM   #89
Dan04
Member
 
Registered: Jun 2006
Location: Texas
Distribution: Ubuntu
Posts: 207

Rep: Reputation: 37
Quote:
Originally Posted by Sergei Steshenko View Post
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

Code:
class std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >
 
Old 04-16-2010, 08:17 AM   #90
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
Quote:
Originally Posted by icecubeflower View Post
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.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:05 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration