Amiga.org

Operating System Specific Discussions => Amiga OS => Amiga OS -- Development => Topic started by: Plaz on February 07, 2018, 03:28:35 AM

Title: C vs C++ ... or whatever language
Post by: Plaz on February 07, 2018, 03:28:35 AM
I was posting in another thread and found myself going way off topic, so I decided to spin this off to it's own thing.
 
Longer ago than I care to admit, I moved from embedded asm projects to C. I found C annoying and after a couple of projects I changed up careers and moved on to other interesting things. C++ came up along the way, but I said, "meh, looks like that annoying C to me. no thanks."

Fast forward a good bit. I'm now back to C++ based projects "for fun and profit".
My personal story...  First  C++ was a huge, complicated PIA to learn. I don't seem to be alone in this opinion. However once I started getting the hang of it, I found I preferred it over plain C. Why? who cares. My point is, if you want to learn to program, find what works for you and go with it. Java, Rust, python... try them all on for size, pick one or two and run with it. I think I made a mistake for along time asking "what's the best one to learn?" Instead I found projects I really liked, then learned what the project called for. I turned up my nose a bit a first at the C++ based stuff because , ya know... C. But I dug in anyway and find myself enjoying coding again.

Side note to my side note...
For a couple of years now  I've been reading about "the next thing to replace C++ because it so complicated". Since C++ is continually evolving, I just can't see that happening soon and I can't understand why so many seem to want to replace it. "Because programming is too hard, we have to make it easier", is my personal guess at the reason. YMMV

Thanks for reading

Plaz
Title: Re: C vs C++ ... or whatever language
Post by: AmigaEd on February 07, 2018, 04:44:28 AM
I started with asm on the z80, then 6809, the 8085 (went a bit backwards there) and then the 68000.  I loved asm but C and C++ have never really appealed to me for some reason which I can't really quite put my finger on.

However, I have used both C and C++ in various projects and use Java (which doesn't really appeal to me either) on an almost daily basis.
At some point I would like to do a real, functional, and useful C or C++ program for the Amiga.

I guess I just need to find a "driver" usually in the form of some other project as this is how I usually end up deep diving into something.
Title: Re: C vs C++ ... or whatever language
Post by: CodePoet on February 07, 2018, 05:17:14 AM
What was the learning curve like going from C to C++? OO scares me and I haven't really given myself enough of a chance to migrate.

Most of my work is either microcontroller firmware or terminal programs, but I'd like to be able to create Linux/Windows applications without devolving to basic for a change
Title: Re: C vs C++ ... or whatever language
Post by: bbond007 on February 07, 2018, 07:26:48 AM
Quote from: CodePoet;835858
What was the learning curve like going from C to C++? OO scares me and I haven't really given myself enough of a chance to migrate.

Sometimes in c you are using a bunch of functions that all operate on the same struct and in c++ you can refactor that into a single object with methods.

I think its  how you approach c++

You don't have to use all of it at once.
Title: Re: C vs C++ ... or whatever language
Post by: psxphill on February 07, 2018, 11:25:34 AM
Quote from: bbond007;835862
Sometimes in c you are using a bunch of functions that all operate on the same struct and in c++ you can refactor that into a single object with methods.

I think its  how you approach c++

You don't have to use all of it at once.

I have written in assembly, C & C++. I still use all 3 to varying degrees.

Converting a C function & struct to a C++ class might be how most people start with C++ but it's not the most effective way to highlight the benefits. If you have a negative view on C++ then it will just be a waste of time.

One C++ project I did just had main() but used vector<>, lambda & enum class. No classes, just a few struct. It started in C, but I took the opportunity to throw in some C++ features where it made the code simpler. Then I ended up switching wholesale.
Title: Re: C vs C++ ... or whatever language
Post by: DLH on February 07, 2018, 01:33:26 PM
Shameless Plug for book I have listed on ebay right now

Inside the Amiga with C Second Edition (383 pages)

https://www.ebay.com/itm/332543506531

thanks

DLH
Title: Re: C vs C++ ... or whatever language
Post by: guest11527 on February 07, 2018, 02:37:37 PM
Quote from: Plaz;835851
I
Fast forward a good bit. I'm now back to C++ based projects "for fun and profit".
My personal story...  First  C++ was a huge, complicated PIA to learn. I don't seem to be alone in this opinion. However once I started getting the hang of it, I found I preferred it over plain C.

The good part about C++ is that there is more than a single way how to approach it and how to use it. Look at other languages: Every java program looks pretty much alike - there is only one style that is supported by java, this is the correct style, and everything else is wrong.

This certainly means that java is easier to approach than C++. You learn quickly what you have to know, and there is one correct way how to do it.

C++ is different. You can use it in multiple ways. Fully fledged OOP with lambda-functions and the STL all over the place, as a sophisticated code-generator for C, even "C plus exceptions" is a possible style. While not recommendable, it is certainly possible.

In my experience, thinking in objects helps to organize your projects because it requires you to ... keep organized. "Architecture" is much more important in C++ than "coding". If you believe you write a program by typing in functions, then that approach will not get you far. Actually, in no language. You will be lost sooner or later, if the project just grows large enough.

While you can follow an OOP style in C, C++ can express "architecture" in a much better way than C can.

Look at AmigaOs: "graphics" is just "a lump of inconsistent functions", together with a lump of inconsistent structures that are not extensible. "datatypes" are just the other way around. An extensible system of classes that work nicely together just by fixing a couple of interfaces.

Both are "mostly C" with some asembly language here and there (and more of that in graphics), but datatypes would certainly been easier if it would have been in C++.
Title: Re: C vs C++ ... or whatever language
Post by: Louis Dias on February 07, 2018, 03:47:07 PM
I think C/C++/C# were created by satan and I want to slit my wrists when I code in them or have to look at code.  Same more or less for every C-syntax language (PHP, JAVA, JavaScript, etc...)

I <3 VB.Net - always evolving and encompassing...because you shouldn't have to fight the syntax to code.

One thing I don't like that's all the rage now is lambda functions...and I don't like how it looks in VB either...ugh...

NOTE: I learned 6502/8502 and 8088 assembly back in the day...at least assembly is straight forward.  Frak C!

I also learn Visual FoxPro years ago and was OK with that.  In C# and VB.Net, they added LINQ functionality but it looks ugly and is different from SQL enough to annoy me where as FoxPro let you create in-memory data cursors and the syntax remained like SQL.  Now I realize LINQ is a bit more flexible but way uglier.  Again - fighting the syntax is not something you want to do when you are looking at someone else's code...
Title: Re: C vs C++ ... or whatever language
Post by: kamelito on February 07, 2018, 04:10:54 PM
Objects another abstraction that do not comply (map) the underlying HW like assembly or C.
Title: Re: C vs C++ ... or whatever language
Post by: olsen on February 07, 2018, 05:12:22 PM
Quote from: DLH;835867
Shameless Plug for book I have listed on ebay right now

Inside the Amiga with C Second Edition (383 pages)

https://www.ebay.com/itm/332543506531

thanks

DLH

Hey, good one - this is the book which I read when I took my first baby steps to learn Amiga programming (with the original Kernighan/Ritchie "The 'C' programming language" introducing me to 'C' at the same time). If I remember correctly, Rob Peck's book "Programmer's Guide to the Amiga"  turned out to be the better choice, and not just because it covered so much more of the operating system. These two books, along with the example programs on the Aztec 'C' disks, as well as the early AmigaLibDisks were teaching me how to program my Amiga 500, back in 1987.
Title: Re: C vs C++ ... or whatever language
Post by: asrael22 on February 07, 2018, 08:55:36 PM
Quote from: Thomas Richter;835871
The good part about C++ is that there is more than a single way how to approach it and how to use it. Look at other languages: Every java program looks pretty much alike - there is only one style that is supported by java, this is the correct style, and everything else is wrong.


There are different styles in Java as well.
Some 'design' for extensible use of anonymous subclasses.
Some use other styles, there are many. Especially with Java 8 where Closures came into play.

But I agree, Java, like C++, gives you more opportunity to architecture your program better. Abstractions, Dependency Inversion, etc., its all a bit easier to implement.


Cheers
Title: Re: C vs C++ ... or whatever language
Post by: Plaz on February 08, 2018, 02:05:06 AM
Quote
I guess I just need to find a "driver" usually in the form of some other project

Exactly were I finally found my motivation. Before that I wondered aimlessly knowing I needed to improve, but never sticking to any study or project long enough.

Quote
learning curve like going from C to C++?

For me it was more of a perspective change than a learning curve. If you're already good with C, then you're starting farther along than I did.

I'm a very visual learner, if you are too see if this helps... Visualize a world full of C structures who's internals not only include data, but also their own independent code and functions. Matter of fact those internal functions might even be other structures. A new structure might clone an existing structure and then add it's own uniqueness, all the while being able to to refer back to the original structure's "guts".

What I've quickly and crudely described is a class with members and methods. An object.
The language is still C (with more semantics added), but the ways in which you can use it to manipulate "objects" is expanded.

I've never found one great book on C++. But the one I got the most from was
C++ primer plus by Steven Prata

 Watching different videos on a tough subject was typically helpful.

Quote
I think C/C++/C# were created by satan and I want to slit my wrists when I code in them or have to look at code.

oh boy does that sound familiar.  But I'm in a better place now.

On the other hand what I still find evil is when people code their projects with no comments. C++ can be buried in layers of abstraction if the coder so chooses, Trying to unravel what they've written can be soul killing. Clearly they never meant to share their code so why bother explaining it? I've seen a couple of projects wither and die after someone tried to pick up where someone else left off. Better to borrow the concept and start over with a new code base.

Also as a newbie don't be afraid to assume the code in a project you're looking at might not be correct. (rare as it might be) I once spent hours and hours assuming I had learned something wrong and I was just too dumb to figure out how the code I was looking at worked. While I'm often a dummy, in this case I finally figured out the flaw in the code. Annoying as it was, the time I spent troubleshooting was valuable in my learning.

One last tip. C++ syntax is only one part of the puzzle. Understanding what your compiler is doing with your text is as equally important. Compiler is making a lot of assumptions that a beginner doesn't know about. Study guides refer to this but I don't think they highlight the topic nearly well enough.

Plaz
Title: Re: C vs C++ ... or whatever language
Post by: psxphill on February 08, 2018, 10:03:18 AM
Quote from: Plaz;835885
On the other hand what I still find evil is when people code their projects with no comments. C++ can be buried in layers of abstraction if the coder so chooses, Trying to unravel what they've written can be soul killing.

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.

If a developer can't choose descriptive class/variable/method names and lay the structure out in a sane way, then any documentation they write is going to be worse. 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.

The only time documentation is useful is for libraries, where you don't necessarily have the source to hand or an example of how you're supposed to call it.
Title: Re: C vs C++ ... or whatever language
Post by: Daytona675x 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.
Title: Re: C vs C++ ... or whatever language
Post by: nicholas on February 08, 2018, 11:47:51 AM
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

There are pdf's on libgen.pw for the wallet impaired. :)
Title: Re: C vs C++ ... or whatever language
Post by: olsen 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.
Title: Re: C vs C++ ... or whatever language
Post by: guest11527 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.
Title: Re: C vs C++ ... or whatever language
Post by: nicholas 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.
Title: Re: C vs C++ ... or whatever language
Post by: asrael22 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
Title: Re: C vs C++ ... or whatever language
Post by: kamelito on February 08, 2018, 07:16:37 PM
https://www.youtube.com/watch?v=rX0ItVEVjHc
https://www.youtube.com/watch?v=443UNeGrFoM
Title: Re: C vs C++ ... or whatever language
Post by: asrael22 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
Title: Re: C vs C++ ... or whatever language
Post by: Plaz 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
Title: Re: C vs C++ ... or whatever language
Post by: psxphill 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.
Title: C vs C++ ... or whatever language
Post by: kamelito 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.
Title: Re: C vs C++ ... or whatever language
Post by: Einstein 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.
Title: Re: C vs C++ ... or whatever language
Post by: Hans_ 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
Title: Re: C vs C++ ... or whatever language
Post by: guest11527 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.
Title: Re: C vs C++ ... or whatever language
Post by: Daytona675x 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 :)
Title: Re: C vs C++ ... or whatever language
Post by: Einstein 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.
Title: Re: C vs C++ ... or whatever language
Post by: Daytona675x 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.
Title: Re: C vs C++ ... or whatever language
Post by: Einstein on February 10, 2018, 12:21:10 PM
Quote from: Daytona675x;835989
@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.


Yes, both '*' and '&' already serve more than 1 usage, references only add yet another usage to '&'.
Title: Re: C vs C++ ... or whatever language
Post by: kamelito on February 10, 2018, 02:51:39 PM
@Dayntona, Hand & Thor
I don t think That shipping successfully 2 games like Braid and The Witness make him a bad C++ programmer. Check his YouTube channel or better ask him directly on Twitter.
It seems that not a single C++ book did a good job teaching how to program properly in C++. Who need a phone book size one to just scratch the surface? Why big games companies need to wrote their own STL implementation to have good performance?
Title: Re: C vs C++ ... or whatever language
Post by: guest11527 on February 10, 2018, 03:06:24 PM
Quote from: kamelito;835995
It seems that not a single C++ book did a good job teaching how to program properly in C++. Who need a phone book size one to just scratch the surface? Why big games companies need to wrote their own STL implementation to have good performance?

Unfortunately, that seems to be correct and fits my experience. There is the Stroustrup, but even though it is the standard reference, I would not generally recommend the book because it is too big and tries to be too much at the same time. There are certainly very good C++ books around (I liked "Exceptional C++" by Herb Sutter a lot), but not a single one that covers all of C++ and that is "entry level". Probably because there is more than one way how a good C++ program may look like, and there is more than one way how C++ can be ideally used.

Concerning the STL: I also tend to agree, despite people advocating it. I find the STL bulky, and needlessly hard to use, and prefer my own data structures. But this is probably only a "me" thing, and because C++ makes it so easy to come up with your own structures. For example, in Java, I happily use the standard java classes like ArrayList and friends.

My C++ style looks more like "C with classes plus template-enabled super-powers". But that is exactly what I like about the language: Nobody forces me to use the parts of the language that do not quite fit to my application domain (which is, these days, mostly image processing/signal processing related).
Title: Re: C vs C++ ... or whatever language
Post by: Daytona675x 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: ).
Title: Re: C vs C++ ... or whatever language
Post by: Mr_Capehill on February 10, 2018, 08:19:46 PM
Quote from: kamelito;835995
@Dayntona, Hand & Thor
I don t think That shipping successfully 2 games like Braid and The Witness make him a bad C++ programmer. Check his YouTube channel or better ask him directly on Twitter.
It seems that not a single C++ book did a good job teaching how to program properly in C++. Who need a phone book size one to just scratch the surface? Why big games companies need to wrote their own STL implementation to have good performance?


Which game companies rewrite the STL lib in 2015-2018? What exactly was the reason?

Something like std::vector is as fast as the C array.

C++ is a complex topic, that cannot be denied. But C++ today is also quite different to what it used to be. Check constexpr, auto, unique_ptr and ranged-for...
Title: Re: C vs C++ ... or whatever language
Post by: Mr_Capehill on February 10, 2018, 08:23:04 PM
Quote from: Daytona675x;835998

"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.


Yay for mentioning Scott Meyers! Can't go wrong with his advice.

Check also ETL: https://github.com/ETLCPP/etl
Title: Re: C vs C++ ... or whatever language
Post by: Hans_ on February 10, 2018, 08:57:56 PM
Quote from: kamelito;835995
@Dayntona, Hand & Thor
I don t think That shipping successfully 2 games like Braid and The Witness make him a bad C++ programmer. Check his YouTube channel or better ask him directly on Twitter.
It seems that not a single C++ book did a good job teaching how to program properly in C++. Who need a phone book size one to just scratch the surface? Why big games companies need to wrote their own STL implementation to have good performance?

In no way was I slagging off any particular developer's skill. I simply disagree with claims that C++ is so horrible that people "suffer from" it.

I'm sure that Jon Blow is a competent programmer, and I like his games (got The Witness). I also wish him well with developing his own programming language. After taking a quick look at his new language, it's pretty clear that he's spent some time tinkering with Haskell...

He may well be able to make some innovative improvements over existing languages, creating one that suits his programming style and game development well. However, like every programming language ever written, it's highly likely that his language will solve the shortcomings that frustrated him with other languages, but end up with a new set of compromises and limitations. Others will get frustrated with how it can't do certain things they want as easily as they'd like, and they'll start dreaming about creating their own programming language...

Hans
Title: Re: C vs C++ ... or whatever language
Post by: guest11527 on February 10, 2018, 09:31:14 PM
Quote from: Mr_Capehill;836009
Something like std::vector is as fast as the C array.

Actually, when I tested, it was not. There is another layer of indirection, and at least the GNU C++ compiler is not good at removing the overhead even in optimized mode. There is also the "valarray", but that is neither any faster. Yes, it almost all cases it does not matter. But if you do raw signal processing, then the best C++ offers you is the raw pointer (well, except if you have compiler intrinsics for vectorized operations, of course), and this particular case, it does matter.

The C++ vector shows also what I do not like about the STL. If I would design a library, then operator[] of the vector would be range-checked by default, there would be no "at" function (which is range-checked). In optimized mode, the range-change would disappear, and it would run into an assert in debug mode if I'm out of bounds, but it would not throw an exception. What is not right here is that the default mode is "unsafe", and that "exceptions" are used to capture "programming defects" for which we have assertions, and that checked/unchecked is a decision of the function, but not of the compilation mode.
Title: Re: C vs C++ ... or whatever language
Post by: nicholas on February 10, 2018, 09:32:27 PM
@Kamelito

A good workman never blames his tools is as true today as it was in the bronze age.
Title: Re: C vs C++ ... or whatever language
Post by: kamelito on February 10, 2018, 11:04:05 PM
Quote from: Mr_Capehill;836009
Which game companies rewrite the STL lib in 2015-2018? What exactly was the reason?

Something like std::vector is as fast as the C array.

C++ is a complex topic, that cannot be denied. But C++ today is also quite different to what it used to be. Check constexpr, auto, unique_ptr and ranged-for...


Performance was the reason, EA for example their implementation is now open source.
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2271.html
Title: Re: C vs C++ ... or whatever language
Post by: kamelito on February 10, 2018, 11:06:14 PM
Quote from: Mr_Capehill;836009
Which game companies rewrite the STL lib in 2015-2018? What exactly was the reason?

Something like std::vector is as fast as the C array.

C++ is a complex topic, that cannot be denied. But C++ today is also quite different to what it used to be. Check constexpr, auto, unique_ptr and ranged-for...


Reasons explained in the link below, EA for example their implementation is now open source.
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2271.html
Title: Re: C vs C++ ... or whatever language
Post by: bison on February 10, 2018, 11:59:30 PM
Quote from: kamelito;835918
https://www.youtube.com/watch?v=rX0ItVEVjHc
https://www.youtube.com/watch?v=443UNeGrFoM

Thanks for that second link; I probably never would have found it otherwise.
Title: Re: C vs C++ ... or whatever language
Post by: Mr_Capehill on February 11, 2018, 08:16:29 AM
Quote from: kamelito;836016
Performance was the reason, EA for example their implementation is now open source.
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2271.html


Posted in 2007.

But hey, the more the merrier. People can use STL, ETL, EASTL or roll their own. It's just a toolbox, not religion.
Title: Re: C vs C++ ... or whatever language
Post by: Mr_Capehill on February 11, 2018, 08:22:24 AM
Quote from: Thomas Richter;836014
Actually, when I tested, it was not. There is another layer of indirection, and at least the GNU C++ compiler is not good at removing the overhead even in optimized mode. There is also the "valarray", but that is neither any faster. Yes, it almost all cases it does not matter. But if you do raw signal processing, then the best C++ offers you is the raw pointer (well, except if you have compiler intrinsics for vectorized operations, of course), and this particular case, it does matter.


What sort of test case? I have used std::vector to take care of memory management and just passed the pointer (myVector.data()) to OpenGL, for example.
Title: Re: C vs C++ ... or whatever language
Post by: guest11527 on February 11, 2018, 09:47:57 AM
Quote from: Mr_Capehill;836024
What sort of test case? I have used std::vector to take care of memory management and just passed the pointer (myVector.data()) to OpenGL, for example.
In that case, of course, the speed is quite the same. No, I'm talking about a wavelet filter, in particular. No "pointer access", but then access to vector elements by operator[]. That is slower than doing it by pointers directly, even though, in principle, the compiler could optimize everything away. In reality, it does not.
Title: Re: C vs C++ ... or whatever language
Post by: Plaz on February 12, 2018, 11:49:08 PM
Quote
Accelerated C++: Practical Programming


I gave this a quick read today. I found it moves very quickly which may be a problem for new learners. (of course the first clue is "accererated") By the end of chapter 3 I wanted to raise my hand and as the instructor a question. Dang it, not included. :)

Plaz
Title: Re: C vs C++ ... or whatever language
Post by: nicholas on February 13, 2018, 07:40:14 AM
Quote from: Plaz;836074
I gave this a quick read today. I found it moves very quickly which may be a problem for new learners. (of course the first clue is "accererated") By the end of chapter 3 I wanted to raise my hand and as the instructor a question. Dang it, not included. :)

Plaz



Hehe :)

Yeah it's not for absolute beginners with no experience though I did give my old copy to a neighbour's sister last Friday who has only ever done a bit of JS (I think) with Codecademy, so it should be a good test of it. Admittedly she's got me to ask questions to.
Title: C vs C++ ... or whatever language
Post by: SamuraiCrow on February 16, 2018, 09:14:49 AM
Arguably, C++ is not for beginners either.
Title: Re: C vs C++ ... or whatever language
Post by: psxphill on February 16, 2018, 12:21:34 PM
Quote from: SamuraiCrow;836178
Arguably, C++ is not for beginners either.


It depends on how long you want to stay a beginner. If you're after instant gratification then c++ is not ideal.

There is no reason a beginner couldn't go straight for assembly language.
Title: Re: C vs C++ ... or whatever language
Post by: guest11527 on February 16, 2018, 01:18:56 PM
Quote from: psxphill;836182
It depends on how long you want to stay a beginner. If you're after instant gratification then c++ is not ideal.

There is no reason a beginner couldn't go straight for assembly language.

While I tend to agree, I believe he got a point. C++ does not force you into a particular programming style. While this property of the language is certainly helpful for advanced programmers, it makes it unecessary hard for beginners to develop a good style.
Title: Re: C vs C++ ... or whatever language
Post by: nicholas on February 16, 2018, 02:21:27 PM
Quote from: SamuraiCrow;836178
Arguably, C++ is not for beginners either.

I'd agree generally, but C++ in a "C with Classes" style is fine for total beginners in my experience.

This book proves it really http://steveheller.org/whoscpp.htm
Title: Re: C vs C++ ... or whatever language
Post by: psxphill on February 16, 2018, 10:04:10 PM
Quote from: Thomas Richter;836183
C++ does not force you into a particular programming style. While this property of the language is certainly helpful for advanced programmers, it makes it unecessary hard for beginners to develop a good style.

But taking a detour via another language isn't going to develop a good style either.

Your argument is like saying: Chinese is hard to learn, so instead of learning it when you are a child you should learn another language first and speak that for a while and then learn chinese when you're in your 30's.

Developing a good style is an innate skill. If you struggle then you're probably not cut out for development.
Title: Re: C vs C++ ... or whatever language
Post by: guest11527 on February 16, 2018, 11:07:50 PM
Quote from: psxphill;836199
But taking a detour via another language isn't going to develop a good style either.

I don't think so. Look, once you've learned one language, it is relatively easy to carry over concepts to another. Good software developers will master whatever language they should write programs in. It is just hard to get started and understand the concepts.

Otherwise, people from my age would have never been able to develop a style as probably most of us started from Basic. And that is a terrible language.
Title: Re: C vs C++ ... or whatever language
Post by: Karlos on February 17, 2018, 10:02:35 AM
I can say that in all honesty, I've had the most fun coding in C++ on the Amiga. It's a huge Swiss Army knife and I've found uses for almost every language feature but for 68K/Amiga my preferred approach is C with Classes with minor uses of templates, usually to provide type safe interfaces to low level specialisations around void* pointers or to provide custom inline assembler for certain operations.

These days I rarely get to code anything outside of work, let alone on the Amiga :(
Title: Re: C vs C++ ... or whatever language
Post by: kolla on February 17, 2018, 03:08:45 PM
What C++ options are there for Amiga? :)
Title: Re: C vs C++ ... or whatever language
Post by: Kronos on February 17, 2018, 05:33:05 PM
GCC obviously.

You could also go with StormC which might have been a MaxonC derivate from V1 to V3 and was GCC based in V4.
Title: Re: C vs C++ ... or whatever language
Post by: Plaz on February 18, 2018, 12:11:32 AM
Quote from: kolla;836231
What C++ options are there for Amiga? :)


With tech assist from Chris_Y I built GCC 6.x cross compiler, successfully build Netsurf and ran it on AmigaForver.

Plaz
Title: Re: C vs C++ ... or whatever language
Post by: nicholas on February 18, 2018, 09:17:55 AM
Quote from: Kronos;836234
GCC obviously.

You could also go with StormC which might have been a MaxonC derivate from V1 to V3 and was GCC based in V4.


SAS/C 7.01 supports a subset of C++ too.

http://aminet.net/package/dev/c/expsascxx
Title: Re: C vs C++ ... or whatever language
Post by: Kronos on February 19, 2018, 11:32:20 AM
Quote from: nicholas;836255
SAS/C 7.01 supports a subset of C++ too.

http://aminet.net/package/dev/c/expsascxx


You obviously never tried to compile C++ with that.

I did, on an 68030 with 7MB (4MB on the A2630,2MB Z2 and 1MB CHIP).

It might be somewhat useable with today's resources (NG or UAE) ....



.... for compiling and running........
Title: Re: C vs C++ ... or whatever language
Post by: nicholas on February 19, 2018, 03:33:41 PM
Quote from: Kronos;836304
You obviously never tried to compile C++ with that.

I did, on an 68030 with 7MB (4MB on the A2630,2MB Z2 and 1MB CHIP).

It might be somewhat useable with today's resources (NG or UAE) ....


.... for compiling and running........



Who in their right mind compiles anything bigger than hello world on 68k silicon today though? ;)

SAS/C 7 ran fine under MorphOS on my PowerBook last time I tried (circa 2013) but obviously there are far better solutions like GCC.

It's a shame vbcc was never given C++ support IMHO though.
Title: Re: C vs C++ ... or whatever language
Post by: Kronos on February 19, 2018, 04:58:37 PM
Quote from: nicholas;836307

SAS/C 7 ran fine under MorphOS on my PowerBook last time I tried (circa 2013) .


C or C++?

Compiling C with SAS on an 68030 was just fine in 199x.
Compiling C++ with Storm on an 68030 was just fine in 199x.
Compiling C++ with SAS on an 68030 was just useless in 199x.

SAS C++ isn't really a compiler but a preprocessor taking ages to create oversized C code.
SAS C then compiled that code into bloated object code (again taking ages).
Title: Re: C vs C++ ... or whatever language
Post by: guest11527 on February 19, 2018, 08:53:54 PM
Quote from: Kronos;836309
SAS C++ isn't really a compiler but a preprocessor taking ages to create oversized C code.

So was the first C++ compiler as well (CFront).  No matter what, SAS/C only supported a small subset of C++, and this subset even diverges from C++, even more so today. It is next to useless today. Some important C++ are missing completely, such as templates.