Should I learn C before C++?
Adisharma
Posts: 2
Hello All, I am a new one in this forum and I just completed my b.tech from computer science, I want to learn to programming. So Should I learn C before C++? or directly move to C++. I want to learn C++ programming.
Comments
Word of warning, and I'm sure you've heard it before: Because of the no-hand-holding nature they're probably the hardest languages to fully handle. There is no fast track learning it. Bugs are often crash inducing without notice. C/C++ is why debuggers exist.
You have to know C anyway, in order to write classes in C++. A beginner in C++ will have to learn all the basics of C before tackling classes.
The main difference for a beginner is using the C++ overloaded << operator to format output rather than C's printf(). A C++ course will teach you to use <<, but you can still use printf() if you wish: many C++ coders prefer it.
Which is almost entirely C anyway. The C equivalent would be
You'll be fine jumping directly into C++.
Once you have learned C though it's definitely worth-while going on to learn the rest of C++.
Learn C++, which is a superset of C anyway, when someone puts a gun to your head and makes you.
This is the same as: Of course, it's usually used with much more complex initializers. The case I saw was an iterator.
Never seen C++ before. From this C++ is so much better???
Not 100% true. For example, const works different in C++ and C has some strange features C++ doesn't have. Nothing too major though.
No, this example isn't what makes C++ better (though the << operator is much more space efficient than printf, and why I use it in PropWare). I was just drawing attention to that fact that, as you walk through a C++ tutorial (or a formal class), you will learn the basics of C too. You will learn about functions and pointers and structs. You will surely learn about some of the C standard library too, like printf, just by using Google when you have a question. Most of the C standard library you would likely never learned if you focused 100% on C++, and that would be sad, but exactly the same thing can be said about not learning the C++ standard (template) library.
If your end goal is to learn C++ (I'm going to assume that is a valid end goal for the moment, because debating that C vs C++ requires knowledge which we don't yet have about the application or intended applications), then I think focusing on C tutorials is like learning Latin before Spanish. Will it help? SURE! Is it necessary? Not remotely.
So, I would say learning C first is probably an easier path to go... For small projects, it's like high-level assembly code, in some ways. It stays very close to typical instruction code (well, on the Propeller, I'm stretching that thinking a bit).
Object oriented programming (in C++ and other languages) adds a higher level of thinking about any particular project. You have to decide how your project can be reflected in objects and procedures that make up the code. Lots of up-front decisions, some trial and error as you become more familiar with the concept, but eventually you get it!
When you have a new project in mind, a new processor and languages to learn you might want to start with the most simple environment. C is probably a good start (outside of Spin, on the Propeller!).
Just my observations...
dgately
To play devil's advocate...
I'd argue one should be writing object-inspired code in C, too. Create a "module" for relate code and a struct to hold all of the state for that module. Make it a consistent pattern to always pass an instance of that struct - as a pointer - as the first parameter of every function in the module. Provide a function for initializing and cleaning up instances of the struct. And what do we have now??? A class in C
I didn't say you can't write OOP code in C C++ does intentionally provide infrastructure for OOP, while in C, it is up to the programmer to create the OOP realm from more primitive means... But, I agree that one can gain from an object-inspired style of writing code in any language!
dgately
With more things to do they move on to a super-loop that for example use 10ms greatest common denominator.
I would say the pinnacle is a 32task Co-operative state machine Functions, you just need to add new from template (below) if you need another task and add its name in common.h,
You don't have to add anything in main.c that runs the 1uAh rtc task scheduler, any task can sleep for any random length between 1/1024 sec to 4hrs.
All tasks boot-state is run at... boot (eventset = 0xffff is one time set in main) so you can set pins and IRQs, or just leave empty and the break there.
Would like to add a custom pre-compiler so it can do shared IRQ vector merger so each task just have its isr snippet, but maybe could be done without.
You can write perfectly fine C++ code using just the C runtime libraries, and never touch the C++ runtime libs or STL. Most of the negatives people associate with C++ are in the libs/STL. If you turn off RTTI, which most do because of the bloat and security issues, then C++ becomes a fairly nice language to code in. The leanness of C with some niceties to make coding more rapid/efficient.
That being said, I've heard udemy is very good (never taken a course there myself) and it's the second highest rated suggestion.... Maybe go for it?