I Want To Learn GL Should I Learn C++

Originally posted by Robbo:
[b]
No - ehem. These days your `optimisation’ is usually at the algorithm level, rather than in some loop fragment.

[/b]

Well, that’s what kids in school think, IMHO.

Take a look at any contemporary performance comparison/benchmark/etc. The fight is for percents, not times, and definitely not for asymptotic differences. Of course, this is a no surprise, because everyone eventually comes to the best algorithm for the job and then the implementation details matter.


The lower level you code at the less chance the compiler will have to maximize and optimize your code.

Please, take a look at this thread in comp.graphics.algorithms http://groups.google.com/groups?dq=&hl=e…40eml.cc#link25
to see what a low level coding can give you.

I hereby challenge everyone to come with a faster C++ (or C for that matter) solution

Just setting a little asm method in there inline can totally screw the compilers optimisation strategy, so don’t bother.

With most compilers, yes. But certainly not the case with, e.g. GCC inline assembly where the compiler itself assign registers to the assembly block and basically knows everything about it.

Regards,
~velco

If you want to learn C++ is Thinking in C++ 1&2 two good books available for free download. The author recommends Borlands compiler and it can be downloaded from Borland. Remember that both OpenGL and C++ is big so do not underestimate the difficulties.

Here is the link to the books: http://www.mindview.net/Books/TICPP/ThinkingInCPP2e.html

Originally posted by velco:
[b] With most compilers, yes. But certainly not the case with, e.g. GCC inline assembly where the compiler itself assign registers to the assembly block and basically knows everything about it.

Regards,
~velco[/b]

Lol! It really doesn’t make a hell of a a lot of difference.

(1) If you want to get the job done - would you spend 8 hours getting an 18% speedup on Foo, or just write a reasonable Foo and maybe optimise it if the results weren’t good?

(2) How portable is code optimised to take advantage of the strategy used by some given compiler (x)? Not very.

(3) Even though GCC knows about register assignments inline ASM, it doesn’t make a fig of difference because x86 processors don’t have a whole lot of registers in the first place.

The difference in performance between c and c++ is so small that I cant see why anyone would want to use c. 3D engines, probably more so than any other type of program, lend themselves particularly well to object oriented deisgn. C++ will help you get your project done a lot quicker, and help you manage complexity. Those advantages outweigh the slight performance advantage of C by far.

I have been working on an engine for the last few months, and I know I wouldnt be anywhere near where I am now if I had used c instead of c++.

[This message has been edited by ioquan (edited 07-07-2002).]

This means that you do not know C good
Now coding in C++ is quicer - a myth.
The time spent on developing the apps is similar.
But time of analysis for OOP project is a lot
longer then with structural aproach.

( I mean a good analysis…not some like think what I want to do, sit down and code

Originally posted by Robbo:
Lol! It really doesn’t make a hell of a a lot of difference.

Lol! 18% or 33% is a HUGE difference. Do you really think the rest of the world is so stupid that you can always beet them by more than 18 or 33 percent ?


(1) If you want to get the job done - would you spend 8 hours getting an 18% speedup on Foo, or just write a reasonable Foo and maybe optimise it if the results weren’t good?

Yes

In the real world, quite often what matters is to be on the top, even by a 1% margin

[B} (2) How portable is code optimised to take advantage of the strategy used by some given compiler (x)? Not very. [/b]

This is so broad statement that it bears no semantics.

That’s not the point, of course, the point is that low level coding allows you to perform optimizations at the source level, which are advantageous due to the factr that the programmer generally knows more about the program than the compiler.


(3) Even though GCC knows about register assignments inline ASM, it doesn’t make a fig of difference because x86 processors don’t have a whole lot of registers in the first place.

Not true.

When the compiler can assign inline ASM registers it is able to: a) avoid unnecessary moves by allocating the register where the value already is, b) avoid unnecessary moves, by allocatins output value to the register that is its ulitimate destination, c) avoid unnecessary saves/restores around the inline ASM, since it knows particular registers are not modified, d) avoid unnecessary saves/restores around the inline ASM, since it knows that particular memory locations are not written, guess there are more.

As for the number of registers, 8 XMM + 8 MMX + 6 GPRs, while not a hell of a registers, are still a pretty decent amount.

Regards,
-velco

[This message has been edited by velco (edited 07-07-2002).]

Two things to have in mind then using C++:

  1. Working bottom-up by first identifying the classes and then implement functions for all possible cases can produce big and bloated code.
  2. Using dynamic memory for all objects can be slow compared to the big array approach that C programs often takes.

If you were right, then perhaps everybody would still be using C, and C++ wouldn’t be so popular.

As for speed, once again, I see no noticable difference. Would you like to give me an example of code I can write that is much faster in C than C++? Something meaningful, not just some obscurity.

If you want real speed, I guess you should write your code in all-assembler - why don’t you? Perhaps because erm, C offers more convienience - and for a lot of us C++ offers even more.

Writing code in C that is modular' often requires the use of C++ constructs in any case, so why bother typing more? (at least). You have to write a constructor for your object (probably called xxx_init), you have to pass pointers into yourmember’ methods ( xxx_init ( xxx *pThis ) ), etc. Whats the point? Some religious reason? I’ve coded in ASM, C, C++ (in order of bugginess).

Can you use the STL with C? No? Have you written your own STL? Why?

Originally posted by Zico:
[b]Two things to have in mind then using C++:

  1. Working bottom-up by first identifying the classes and then implement functions for all possible cases can produce big and bloated code.
  2. Using dynamic memory for all objects can be slow compared to the big array approach that C programs often takes. [/b]

You don’t have to use dynamic memory with C++ programs - you can use big arrays (and most do).

You don’t have to work top-down or bottom up - you can write a very simple vector class and then you can write your application object. As for code bloat' - having a complete’ class makes it more reusable. In your case, whenever you need a new operation on an object, of course you write one! So do C++ programmers!?! C++ has not syntactic prerequisite that you must write a complete' implementation for any given object. In the case of vector’, I made it complete because I knew in advance that all of the methods made available would eventually be used.

It seems like all the arguing really is just to make people feel better about themselves… because what’s going on is that everyone wants to be able to justify the language they prefer, and also probably know better than the other (and subsequently feel intimidated by people with the contradicting opinion because they know the other language better).

They both are used widely and have their positives and negatives. There will always be ways to put down someone with an opposing opinion. You know what the best language is between C and C++? THE ONE YOU LIKE BEST. That’s all there is to it. You will be quicker and more efficient with it, and happier (alhthough you should be familiar with both).

C++ its great. But some interresting on graphic engines:

quake 1,2: C
unreal: C
gta 3: C
Max Payne: C

All hardcore calculations on engine arent using c++ classes, objects etc. GUI things are almost always built in MFC (c++), ATL, or over opengl context.

Half-Life: C++

Hi to All,
This might not be at all topic
of this dicusion but since I am
new in gl I had to ask.
Someone mentoned that using
the GLUT (and 1 other lib) is not
that good if u r to realy know gl.
Why is that?
maxmagnus

Originally posted by Robbo:

If you were right, then perhaps everybody would still be using C, and C++ wouldn’t be so popular.

Well, I did a quick search for “programming language popularity”. Here are the results:

C: 2673
Perl: 1361
C++: 1020
PHP: 740
Java: 726
Python: 403
Unix Shell: 246
Tcl: 190
SQL: 124
Other: 89
JavaScript: 85
Assembly: 83
Other Scripting Engines: 41
Lisp: 35
Scheme: 35
Ruby: 31
Objective C: 26
PL/SQL: 21
Fortran: 18
Eiffel: 16
Delphi: 15
Ada: 15
ML: 15
Pascal: 15
Awk: 13
Zope: 13
Forth: 11
ASP: 9
Emacs-Lisp: 9
Haskell: 8
Cold Fusion: 7
Visual Basic: 6
Modula: 5
Rexx: 5
Dylan: 4
Erlang: 4
Object Pascal: 4
APL: 3
Smalltalk: 3
PROGRESS: 2
Prolog: 2
Simula: 1
XBasic: 1
Euler: 1
Euphoria: 1
Basic: 1
Logo: 0

Now, I absolutely do not support that some thing’s popularity is a measure for its merit, I’m just pointing out that you argument is completely bogus.

IMHO, part of the popularity of C++ is due to the fact that it indeed saves typing, i.e. programming time, and, of course, pointy-haireds promote C++, because thay care for for the wages they pay, not for the **** their staff delivers


As for speed, once again, I see no noticable difference. Would you like to give me an example of code I can write that is much faster in C than C++? Something meaningful, not just some obscurity.

You’ll see difference only after you open your eyes Not by declaring facts, which do not suit you thery insignificant, obscure, etc.


If you want real speed, I guess you should write your code in all-assembler - why don’t you? Perhaps because erm, C offers more convienience - and for a lot of us C++ offers even more.

Or perhaps because C offers often the same performance and the portabiluty comes as extra bonus.


Writing code in C that is modular' often requires the use of C++ constructs in any case, so why bother typing more? (at least). You have to write a constructor for your object (probably called xxx_init), you have to pass pointers into your member’ methods ( xxx_init ( xxx *pThis ) ), etc. Whats the point? Some religious reason?

The point is, e.g, not calling the constructor when it is not needed.


Can you use the STL with C? No? Have you written your own STL? Why?

Huh? What kind of argument is that? Of course, I’ve written my own hash tables, AVL-trees, red-black trees - all customized for my specific use. Did I spent more time than just writing “std::map<foo,bar,baz>” ? Sure. Did my program took less space, less compile time, less run time? Definitely.

And, of course, there’s GLIB.

And as a final post to this thread, I’ll repeat myself a little:

C++ has only slightly lower performance inherently, the problem is in the programmer, in that it is harder to write an efficient program in C++, to the large extent due to the fact that stuff that happens is not apparently visible from the source code, i.e, an innocent “a = b + c” could well translate to a single insn or to gross overloaded operator invocations and you have to look up an arbitrary amount of other sources (in this case, where “operator+” is defined) in order to figure out what that simple statement does.

~velco

Maxmagnus, I think he wrote that you can not use GLUT if you want to make a Direct3D port. He also belives that they support dumbness. My advice is simply to ignore comments like that.

Your quick search for programming language popularity is itself bogus. That result is only for open source projects posted up on source forge. Hardly representative of the real world. At my present company, only the driver writers use C (and sometimes at that) - we use VB and C++ for all our other work. At the video game company I worked for before that, everyone used C++ (VC++) - with D3D - and when I worked for a University writing a Neural Network simulator, the project was written in C++.

C is much quicker, I just have to open my eyes! Thats a quite hilarious argument - give me an example so I can check compiler ASM output and see if your argument is indeed true.

As for operator overloading and having to check sources - it is clear that when I’m adding two non-basic types, I am calling an operator overload:

void Foo ( vector v1, vector v2 )
{
vector res = v1 + v2;



}

I know that v1 and v2 are vectors and that adding vectors is only possible if operator overloads are used. So what is your point? I have to actually know what type v1 and v2 are to use the + operator? Good programmers sometimes know what types they are adding! Still not convinced?

Is C better than C++? C has less language features than C++, often produces more buggy code (reduced type safety) and is harder to maintain.

Oh and by the way, if you don’t want to call a constructor on an object then leave it empty - the compiler will optimise it away in any case.

ok so the post started off ‘what should I use’ and now has denigrated to ‘my preferred tool is better than yours’. What we’re seeing is a lot of people passing off what seem to be inherently biased opinions based on who they are, where they’re from, and what they’ve done. “You can’t accurately observe if you’re experiencing” seems to nbe a truism here.
I’m just learning opengl and objective-C. Why this combo? because the MacOsX developer tools are ready to go in this format, you go get the glut, plug it in, goto nehe.gamedev.net and get the tutorial, open it up in whatever the developer apps is called in macOSX and off you go. Every one’s going on about ease of use, managing projects, understanding code, optimisation etc. But really i don’t care whether i’ve chosen the wrong language or if I’m cutting myself off from a ‘deeper understanding’ or whatever. What I do understand is that all of the things i’m trying to do are to do with objects and the state they are in at any one time(do they examine themselves?). In 10 minutes i’m up and running and i’ve never written a line of code before in my life. Not only that but object-C looks like objects, especially when Syntaxed in the IDE.
So i ‘see’ these objects in the source. I get a feel for the state machine nature of opengl and then I have opinions about is this the leanest meanest hack? will it work on everything equally well? Is this a problem of conceptual understanding or actual programming understanding? What are the implications of my compiler, language, platform.
In a nutshell it’s what gets you going fastest, and that is a personal thing, i tend to play with lots of different things until i suddenly realise that i’ve forgotten about the other options 'cos i’ve found a methodology or GUI layout that i dig.