Welcome, Guest. Please login or register.
Amiga Kit Amiga Store Hollywood MAL AMIStore App Store A600 Memory

AuthorTopic: C vs C++ ... or whatever language  (Read 6943 times)

0 Members and 1 Guest are viewing this topic.

Offline olsen

Re: C vs C++ ... or whatever language
« Reply #15 on: February 08, 2018, 12:24:37 PM »
Quote from: nicholas;835909
Speaking as a professional Higher Education teacher, this is the best tutorial book for those new to C++ that I've come across.

https://www.amazon.co.uk/Accelerated-Practical-Programming-Example-Depth/dp/020170353X

What kind of path to learning and to keep on learning does the book strike, considering that it was published in the year 2000 and has been on sale ever since then?

The many C++ books I bought over the decades were typically geared towards presenting the new shiny language features which had arrived since the last edition. For a beginner, I would hope that the authors would not just introduce the language well (Andrew Koenig - the man's a legend), but also try to provide the reader with the tools to expect and adapt to the changes the language would invariably go through.
 

guest11527

  • Guest
Re: C vs C++ ... or whatever language
« Reply #16 on: February 08, 2018, 12:39:02 PM »
Quote from: psxphill;835905
I always find it better to architect the structure better than spend time trying to document it. Writing the documentation and updating it when the bad code changes is soul killing as is having to map what the documentation says to the bad code.
Well, I wouldn't be that critical. Good documentation is great. Code that requires good documentation is bad.
 

Offline nicholas

Re: C vs C++ ... or whatever language
« Reply #17 on: February 08, 2018, 01:42:56 PM »
Quote from: olsen;835911
What kind of path to learning and to keep on learning does the book strike, considering that it was published in the year 2000 and has been on sale ever since then?

The many C++ books I bought over the decades were typically geared towards presenting the new shiny language features which had arrived since the last edition. For a beginner, I would hope that the authors would not just introduce the language well (Andrew Koenig - the man's a legend), but also try to provide the reader with the tools to expect and adapt to the changes the language would invariably go through.


The last time I used it professionally was probably around 2005ish but rather than just teach the shiny new features or just document the language it teaches by giving real world problems and introduces language features and standard library features together as you implement the solutions for each problem.

Never had a student that didn't love it.
“Een rezhim-i eshghalgar-i Quds bayad az sahneh-i ruzgar mahv shaved.” - Imam Ayatollah Sayyed  Ruhollah Khomeini
 

Offline asrael22

Re: C vs C++ ... or whatever language
« Reply #18 on: February 08, 2018, 06:14:36 PM »
Quote from: Daytona675x;835908
@kamelito
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.



Yep. The Sun JVM is written in C (the majority of the backend code at least) and uses lots of this stuff. Well, you don't really have much choice. :)



Manfred
 

Offline kamelito

 

Offline asrael22

Re: C vs C++ ... or whatever language
« Reply #20 on: February 08, 2018, 08:12:37 PM »
This might be interesting as well (it's actually f...ing awesome):
https://www.youtube.com/watch?v=pvkn9Xz-xks&t=3s

And the views of this guy on C language, interesting:
https://www.youtube.com/watch?v=443UNeGrFoM



Manfred
 

Offline Plaz

Re: C vs C++ ... or whatever language
« Reply #21 on: February 09, 2018, 02:10:31 AM »
Quote from: Thomas Richter;835912
Good documentation is great. Code that requires good documentation is bad.



Well put. I find most code I meet pretty good. Commentary would make the learn curve much easier on the "new guy" though. Heck, even more sensible naming conventions would be a big improvement.

So much reading to figure out "x_blah"... what is this a member of and what it is used for?  dig dig dig

Plaz
 

Offline psxphill

Re: C vs C++ ... or whatever language
« Reply #22 on: February 09, 2018, 06:55:58 PM »
Quote from: Thomas Richter;835912
Well, I wouldn't be that critical. Good documentation is great. Code that requires good documentation is bad.

Back in the old days when manuals were printed and cost money then there was some good documentation.

You can't learn language features without documentation, but for everything else if you have the source code then you don't need documentation and shouldn't trust any that you find.

Quote from: asrael22;835919
And the views of this guy on C language, interesting:
https://www.youtube.com/watch?v=443UNeGrFoM

There are pros and cons to C, I watched some of the video and he doesn't seem to be objective enough. To me he sounds like he is in denial.

There was a C project I worked on for many years and it was stuck because it needed to be built for some 8 bit platforms too and we only had a C compiler for those. By the time those disappeared there was no justifiable reason to convert it to C++, but looking back I wish I'd done it. There were some places that would have benefited from C++, but due to my own denial it never got done.
« Last Edit: February 09, 2018, 07:03:24 PM by psxphill »
 

Offline kamelito

C vs C++ ... or whatever language
« Reply #23 on: February 09, 2018, 08:27:52 PM »
It is not denial IMO, in the game industry you've no choice if you're into maximum performance, C++ is the de facto standard. These guys are very talented and experienced developers. They just «suffer» from using C++. Jon Blow wrote that if he had written a new language and wrote The Witness with it, the game would have shipped sooner. Now he is writting it, it is called for now Jai. If you are interested look at his YouTube Channel.
« Last Edit: February 09, 2018, 08:34:34 PM by kamelito »
 

Offline Einstein

Re: C vs C++ ... or whatever language
« Reply #24 on: February 09, 2018, 09:49:52 PM »
Quote from: psxphill;835959
There are pros and cons to C, I watched some of the video and he doesn't seem to be objective enough. To me he sounds like he is in denial.


I write my (native) libs and apps in plain C. I'm happy. I considered, maybe twice after just playing, to migrate to C++, but realized that the features I actually required were provided by C already. I'm sure some people actually need C++ (instead of C) for the same reasons that I need C (instead tof asm, if we ignore portability) myself. Some people need C# (instead of C++). I wouldn't mind namespaces, I haven't needed templates, I cannot stand references, I despise operator overloading.
I have spoken !
 

Offline Hans_

Re: C vs C++ ... or whatever language
« Reply #25 on: February 10, 2018, 08:36:22 AM »
Quote from: kamelito;835963
It is not denial IMO, in the game industry you've no choice if you're into maximum performance, C++ is the de facto standard. These guys are very talented and experienced developers. They just «suffer» from using C++.


They only suffer from using C++ if they don't know how to use it.

I use both C and C++, depending on the project. Early on I preferred to use C in an object orientated fashion (using Abstract Data Types (ADT)). Then I realised I was writing lots of boilerplate code that the C++ compiler generates automatically (e.g., allocating/deallocating objects). That's when I switched to C++, and made an effort to learn how to use it properly.

Every programming language has its pros, cons, and tradeoffs...

Hans
http://hdrlab.org.nz/ - Amiga OS 4 projects, programming articles and more. Home of the RadeonHD driver for Amiga OS 4.x project.
 

guest11527

  • Guest
Re: C vs C++ ... or whatever language
« Reply #26 on: February 10, 2018, 09:15:40 AM »
Quote from: Einstein;835967
I write my (native) libs and apps in plain C. I'm happy. I considered, maybe twice after just playing, to migrate to C++, but realized that the features I actually required were provided by C already. I'm sure some people actually need C++ (instead of C) for the same reasons that I need C (instead tof asm, if we ignore portability) myself. Some people need C# (instead of C++). I wouldn't mind namespaces, I haven't needed templates, I cannot stand references, I despise operator overloading.
You never "need" a language. All languages we discuss here are Turing complete, so you can select whatever you please, and every project can be equally well done in C, C++, assembly or Pascal (for the sake of the argument).

The question is rather, how well can you express your architecture with a given language, and how expressive the language is in supporting you. Namespaces help to isolate symbol sets from each other, which helps a lot if your project depends on a lot of other contributions to avoid conflicts in naming. References are more expressive than pointers as they cannot be NULL. The syntax ensures that you cannot pass "empty" references. Operator overloading should only be used were natural, and that is in mathematics or numerics. If you don't do that, don't use them - though "functor" objects do come handy (classes that overload operator() and can be used as functions). Templates can be very handy to generate very fast code as they use the compiler as code generator. Instead of writing the code multiple times, you only write it once, and let the compiler do the job. Simpler to write, simpler to maintain, excellent results.

Of course, one can overdo it. Operator overloading: At the time the STL was designed, "operator overloading" was the new kid on the block, and it was used as essential element in the I/O functions. However, the result is not only harder to read, it is also less flexible than "printf and friends". If I want to localize a program, all I need to do is to localize the "printf format string". With some extended syntax, it can even reshuffle its arguments. "cout << " is less expressive and cannot do that, and its "manipulator syntax" is kludgy and less handy.

Net result: I don't use this stuff. The good thing about C++ is: You don't have to. "" exists, and continues to work. This is quite different from other languages. If you don't like "type erasure" in java, then that's just your bad luck.
 

Offline Daytona675x

Re: C vs C++ ... or whatever language
« Reply #27 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 Einstein

Re: C vs C++ ... or whatever language
« Reply #28 on: February 10, 2018, 10:47:29 AM »
@Thomas Richter

Indeed, and those features aren't required by me. I wouldn't mind namespaces as I mentioned, mostly to keep all native OS identifiers from polluting my "namespace". The not-too-many external libs I have used in the past have properly prefixed everything. But I have survived the single global namespace problem without introducing inconsistencies in my framework.

Regarding references, the perverted syntax of reusing the (1) "address of" operator for references, and doing so in the definition while (2) not requiring (explicit) syntax in the call is just unacceptable. Even if (an)other character(s) would be used in function definition/declaration-place, I still find it inconsistent with pointer syntax and harder to tell what is actually being passed by looking at caller code. Has there been a fix in newer C++ standards ? But like I wrote, I don't need them (and cannot stand them due to syntax).

Besides, I like to have my (C) habits easily translate over to asm land. With proper C++ habits, that would be much more inconvenient.
« Last Edit: February 10, 2018, 10:57:15 AM by Einstein »
I have spoken !
 

Offline Daytona675x

Re: C vs C++ ... or whatever language
« Reply #29 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]