Welcome, Guest. Please login or register.

Author Topic: C vs C++ ... or whatever language  (Read 21157 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Daytona675x

  • Newbie
  • *
  • Join Date: Oct 2014
  • Posts: 46
    • Show all replies
    • http://www.goldencode.de
Re: C vs C++ ... or whatever language
« on: February 08, 2018, 11:37:43 AM »
@kamelito
Quote
Objects another abstraction that do not comply (map) the underlying HW like assembly or C.
Sorry?

But you do know that a class is ultimately just a struct?
And that an C++ object is just an instance of that struct in memory, just like a C struct?
And that a member function call like ObjType* object->Func() is ultimately nothing else than writing Func(struct ObjType *this) in C?
And that a virtual function is ultimately nothing else than invoking a function-pointer in C?
And that, if you wanted to achieve the same semantics / behaviour in C, you'd either have to write / maintain some switch-case-construct or a function-pointer-table by hand?
And that deriving one class from another is first of all nothing else than creating a new struct, either copying over the stuff from the other or by putting the other inside, just in a much more convenient way?

And I repeat it: since many of the additional language-features of C++ help the compiler to better grasp what you want to achieve (or what you explicitely DONT want to do, e.g. const), it has a chance to create superior code.

@Plaz
Quote
C++ can be buried in layers of abstraction if the coder so chooses, Trying to unravel what they've written can be soul killing.
And in C you can easily be confronted with funny spaghetti-code that's equally hard to unravel ;)
Whether non-trivial code is hard to understand or not is pretty much language independent. You can create a mess in C++, you can in C, you can in Java - and you can create well structured code in all of those too. C++ just offers some features over C that can help here.
And whether comments help depends on the quality of those.

@psxphill
Quote
If you've got good documentation, then it's likely the person isn't a developer at all and you might as well throw the code away.
Ahh, no, that's not true. You cannot really make a generalization like that.
And actually, at least if working in a team it's very likely that your boss will force you to document the stuff you write. For four reasons mainly:

1. a mismatch in documentation / code indicates a bug and probably also quickly reveals if you're good or bad at what you do.
2. other team members may have to mess around with your stuff and a decent documentation is simply a tool to help them get on track quicker.
3. it's a myth that well-named variables and funcs and such are always enough documentation, especially if things are getting a bit more complex. A good additional documentation at least of non-trivial code areas can't hurt (especially if you dig out (even your own) code after some years).
4. it makes it easier to get rid of you and to put somebody else there :)

That being said, in my personal projects most comments look like that: ;)

// don't change that!!!
// FIXME
// ouch
// X can never be >15, no check required

@thread
For me one of the most powerful features of C++ is to have constructors and a destructor which are called in an absolute predictive way.
And, again: that you can freely chose what to use or not. For example, you could decide to simply write plain C style, enriched with some templated functions.
AmigaOS 4.1 FE (sam440ep, sam460ex, X5000, Tabor,  R200 / RadeonHD), MorphOS 3.9 (PowerMac G4 733MHz R200), AROS (x86), A1200 (060 80MHz Indivision MK2), A600 Vampire2 / Furia, A500, CDTV
[Dev Videos][Facebook][Old Wings Development Diary]
 

Offline Daytona675x

  • Newbie
  • *
  • Join Date: Oct 2014
  • Posts: 46
    • Show all replies
    • http://www.goldencode.de
Re: C vs C++ ... or whatever language
« Reply #1 on: February 10, 2018, 10:39:15 AM »
Quote from: Hans_;835981
They only suffer from using C++ if they don't know how to use it.
+1
Exactly.

@kamelito
Really, if they "suffer" from using C++ they either aren't that talented or that experienced (at least regarding C++) as they made you believe they are.
If Mr. Blow blames C++ for being the reason why their game didn't ship earlier then that's just a lame excuse for either incompetence or to cover the true reasons.

@Thomas Richter
+1 , especially, but not only, for mentioning references and operator overloading.

@Einstein
I don't really understand why somebody can not like references last not least because they also help to auto-document code and also help you to easily avoid redundant potentially inefficient unneeded NULL-checks by clearly answering the question "damn, do I have to check for NULL now or did the calling function F from X levels higher already make sure that it's valid?".
What I can understand though is if people don't like the syntax of references :)
AmigaOS 4.1 FE (sam440ep, sam460ex, X5000, Tabor,  R200 / RadeonHD), MorphOS 3.9 (PowerMac G4 733MHz R200), AROS (x86), A1200 (060 80MHz Indivision MK2), A600 Vampire2 / Furia, A500, CDTV
[Dev Videos][Facebook][Old Wings Development Diary]
 

Offline Daytona675x

  • Newbie
  • *
  • Join Date: Oct 2014
  • Posts: 46
    • Show all replies
    • http://www.goldencode.de
Re: C vs C++ ... or whatever language
« Reply #2 on: February 10, 2018, 11:00:00 AM »
@Einstein
Well, the whole C/C++ syntax is pretty perverted...
Actually I find the &-reference-syntax to be quite consistent with other C syntax madness ;) (e.g. try to explain the * madness to a C (or C++) student :P )
It's just a matter of getting used to it, some practice, nothing else.
AmigaOS 4.1 FE (sam440ep, sam460ex, X5000, Tabor,  R200 / RadeonHD), MorphOS 3.9 (PowerMac G4 733MHz R200), AROS (x86), A1200 (060 80MHz Indivision MK2), A600 Vampire2 / Furia, A500, CDTV
[Dev Videos][Facebook][Old Wings Development Diary]
 

Offline Daytona675x

  • Newbie
  • *
  • Join Date: Oct 2014
  • Posts: 46
    • Show all replies
    • http://www.goldencode.de
Re: C vs C++ ... or whatever language
« Reply #3 on: February 10, 2018, 03:31:02 PM »
@kamelito
Quote
I don t think That shipping successfully 2 games like Braid and The Witness make him a bad C++ programmer
You are wrong if you think that the one (shipping successfully) must have any relationship to the other (being a good or bad C++ programmer / the game's code quality (and I know exactly what I'm talking about :P )).
Again: if somebody claims that it's the fault of the programming language XYZ that he didn't get his job done in time, then that's a very very strong indication that this guy simply is no good in language XYZ or that he chose the wrong tool for the job in the first place (which also makes him a non-expert for XYZ automatically) or that the true reasons are others.

Quote
It seems that not a single C++ book did a good job teaching how to program properly in C++
You simply picked the wrong books it seems.
To get you started pretty much any C / C++ for dummies book should do.
After you have practiced and have become more or less familiar with it, then I recommend the following pretty thin and to the point books:
"Effective C++" line of books by Scott Meyers. If you understood those, then go for
"Modern C++ Design" by Alexandrescu and finally
"C++ Templates" by Vandevoorde / Josuttis.
Those guys really know what they are talking about!
Yes, some of those books / chapters are tough stuff, without doubt. But that's how it is with a language that offers such a high amount of features and possibilities to exploit. It's no Kindergarten, and if you think that you can master C++ just like that, then you're mistaken.

Quote
Why big games companies need to wrote their own STL implementation to have good performance?
Most likely most of them don't.
However, the STL is made to be a standard for every day use. Which also means it is made to perform well in the avg. usecase.
It's a shoe that should fit okay, it's not a shoe that you can expect to always fit *perfectly*, especially not in corner cases or your very very specific scenario X.
But actually it's in *no way* different with the C standard library, e.g. the whole 0-terminated-C-string functions: okay for small stuff, but insanely slow and inefficient in other usecases. Or qsort: okay for many cases, but useless as soon as you need a stable sort (yes, yes, before somebody starts nitpicking: it's an example and I asume that you cannot just make the comparison function stable :rolleyes: ).
« Last Edit: February 10, 2018, 03:33:37 PM by Daytona675x »
AmigaOS 4.1 FE (sam440ep, sam460ex, X5000, Tabor,  R200 / RadeonHD), MorphOS 3.9 (PowerMac G4 733MHz R200), AROS (x86), A1200 (060 80MHz Indivision MK2), A600 Vampire2 / Furia, A500, CDTV
[Dev Videos][Facebook][Old Wings Development Diary]