PDA

View Full Version : C or C++



michaelglaz
10-01-2014, 05:40 PM
I'm just starting out in the world of OpenGL. I was wondering whether C is preferred to C++ in the world of scientific visualization? I know the latest Red Book is in C...

mike

quadcricket
10-01-2014, 08:11 PM
I'm just starting out as well, so far C has been very difficult to learn in. Most of the tutorials and helper libraries I have found have been in C++.

Agent D
10-02-2014, 05:29 AM
If you have in-depth understanding of the languages, it's just a matter of taste.

To clarify a few things first, I have an electronics and assembly background, so I learned programming from a very lowlevel perspective as oposed to someone who,
for instance, learnt Java at first and has no knowledge of what the machine actually does, therefore what follows should be considered as biased in that way.

I personally prefere C89 and advice people to learn C since you have to understand what you are doing and it is easier to grasp what's going on by looking
at source code than some "creative" C++ constructs I've seen in the past (not concidering a mix of templates and lambdas and some more recent C++1x features yet).
It is prefereable to stick to a simple subset of a language to keep code readable, but C++ is just so humongously huge and has so many syntactic constructs.

You will probably get a lot of comments from people that C++ can do object orientated programming and C can't. However this is nonsense; C++ simply has syntactic
elements that make OOP easier. I also prefere C here, since those syntactic constructs can/will be used in horrible and unreadable ways by people who don't know what
the machine actually does and only have a very high level understanding.

mhagain
10-02-2014, 06:34 AM
There's no right answer to this question.

If you were asking about D3D I'd recommend C++ hands-down, because, while it can be done in C, it's just that bit more painful. OpenGL however is a C API so the actual OpenGL code you write will be essentially identical irrespective of which you choose.

My personal preference is to mostly use the C-like subset of C++, taking advantage of some features such as default parameter values, function overloading, and some lightweight classes where they help most (I also like the stronger type safety), but that's just a personal preference rather than a "thou shalt". It's really up to you and you should decide based on which of the two languages you feel most comfortable working in.

michaelglaz
10-02-2014, 08:08 AM
I guess my main concern is whether there are performance issues between the two languages?

Nikki_k
10-02-2014, 08:16 AM
I guess my main concern is whether there are performance issues between the two languages?


Thar entirely depends on the code you write.

C++ makes it ridiculously easy to write bloated, unperformant code while in C you need to think more to make this mistake - but it's not impossible
In general if you use C++ merely as 'safer' C plus some more lightweight OOP features you won't notice any difference.

I don't use C anymore because the stricter type checking makes C++ even better suited for purely procedural code - and classes and inheritance definitely make a programmer's life easier but as a matter of principle I steer clear of the more complex stuff C++ - especially C++11 - can do. I always get the feeling that the main reason for existence of these features is to write code that solves simple things in a complicated way.

kaufenpreis
10-06-2014, 07:39 AM
C++ is not just C with object orientation. C++ brings huge libraries aimed at easing development. Despite its academic roots, C++ has been qualified as bloated by prominent experts:
"C++ is an insult to the human brain." (Niklaus Wirth)
"I invented the term Object-Oriented, and I can tell you I did not have C++ in mind." (Alan Kay)
"There are only two things wrong with C++: The initial concept and the implementation." (Bertrand Meyer)
"Whenever the C++ language designers had two competing ideas as to how they should solve some problem, they said, 'OK, we'll do them both'. So the language is too baroque for my taste."

michaelglaz
10-11-2014, 11:51 AM
C++ is not just C with object orientation. C++ brings huge libraries aimed at easing development. Despite its academic roots, C++ has been qualified as bloated by prominent experts:
"C++ is an insult to the human brain." (Niklaus Wirth)
"I invented the term Object-Oriented, and I can tell you I did not have C++ in mind." (Alan Kay)
"There are only two things wrong with C++: The initial concept and the implementation." (Bertrand Meyer)
"Whenever the C++ language designers had two competing ideas as to how they should solve some problem, they said, 'OK, we'll do them both'. So the language is too baroque for my taste."

Thanks for the useless quotes by so called "important" people.

Nikki_k
10-12-2014, 03:12 PM
C++ is not just C with object orientation. C++ brings huge libraries aimed at easing development. Despite its academic roots, C++ has been qualified as bloated by prominent experts:
"C++ is an insult to the human brain." (Niklaus Wirth)
"I invented the term Object-Oriented, and I can tell you I did not have C++ in mind." (Alan Kay)
"There are only two things wrong with C++: The initial concept and the implementation." (Bertrand Meyer)
"Whenever the C++ language designers had two competing ideas as to how they should solve some problem, they said, 'OK, we'll do them both'. So the language is too baroque for my taste."


'Stupid' doesn't even begin to describe your post - because - well - nobody forces you to USE that bloat in the first place. The naked language without this shit is actually quite nice.