Welcome, Guest. Please login or register.
Amiga Kit Amiga Store Iridium Banner AMIStore App Store A1200/A600 4xIDE Interface

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

0 Members and 1 Guest are viewing this topic.

Offline Plaz

C vs C++ ... or whatever language
« 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
« Last Edit: February 07, 2018, 03:30:36 AM by Plaz »
 

Offline AmigaEd

  • His Dudeness, El Duderino
  • Hero Member
  • *****
  • Join Date: Jan 2005
  • Posts: 512
  • Total likes: 0
Re: C vs C++ ... or whatever language
« Reply #1 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.
"Pretty soon they will have numbers tattooed on our foreheads." - Jay Miner 1990

La Familia...
A1K - La Primera Dama -1987
A1K - La Princesa- January 2005
A2K - La Reina - February 2005
A2K - Doomy - March 2005
A500 - El Gran Jugador - April 2005
A1200 - La Hermosa Vista - May 2005
A2KHD - El Duro Grande - May 2005
A600 - Prístino - May 2005
A1200 - El Trueno Grande - July 2005
CDTV - El Misterioso - August 2005
C64 - El Gran Lebowski - August 2005
A3K - October 2010
y mas...
 

Offline CodePoet

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

Offline bbond007

Re: C vs C++ ... or whatever language
« Reply #3 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.
« Last Edit: February 07, 2018, 07:32:01 AM by bbond007 »
 

Offline psxphill

Re: C vs C++ ... or whatever language
« Reply #4 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.
« Last Edit: February 07, 2018, 11:27:37 AM by psxphill »
 

Offline DLH

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

guest11527

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

Offline Louis Dias

Re: C vs C++ ... or whatever language
« Reply #7 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...
« Last Edit: February 07, 2018, 03:54:32 PM by lou_dias »
 

Offline kamelito

Re: C vs C++ ... or whatever language
« Reply #8 on: February 07, 2018, 04:10:54 PM »
Objects another abstraction that do not comply (map) the underlying HW like assembly or C.
 

Offline olsen

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

Offline asrael22

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

Offline Plaz

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

Offline psxphill

Re: C vs C++ ... or whatever language
« Reply #12 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.
« Last Edit: February 08, 2018, 10:06:47 AM by psxphill »
 

Offline Daytona675x

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

Re: C vs C++ ... or whatever language
« Reply #14 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. :)
“Een rezhim-i eshghalgar-i Quds bayad az sahneh-i ruzgar mahv shaved.” - Imam Ayatollah Sayyed  Ruhollah Khomeini