You will eventually discover a subset of the world’s population who cannot grasp this fact. And they all work in HR.
Almost but not quite, and in ways which matter to beginning programmers who will take example code at face value. For example, the typing rules in C++ are stricter than in C, so some good example code will work in C but not in C++, and lead to confusing errors if you try to treat it like C++. For an experienced programmer, like you or me, this is an annoyance. For a beginning programmer, like the OP, this matters.
wolly: Learning Python is good to learn how to program; that is, how to create algorithms and data structures, how to debug, how to structure code so it’s readable, and how to go from an idea to something which runs.
Learning C is good for learning how pointers work, how memory management works at a fairly low level, and how to do things like interface with an OS or, if you go the embedded route, how to directly control hardware.
Going from Python to C will involve a few new concepts, but the basic ideas of algorithms, data structures, code organization, and debugging don’t change.
I wanted to learn c++ and not c…
I just don’t understand.You can’t use c++ for microcontrollers?Why?Why is c used and not c++?
C is good for low-level stuff. You have to understand the bits and bytes and pointers to use it. That also makes it very powerful and fast for programming low-level stuff. It’s NOT object oriented, and it won’t be easy to move from C to C++.
C++ is object oriented and can be used for higher-level programming, but it’s out of date. C# would be better.
You don’t need to learn C to understand pointers, but it could help. If you like hardware and want to understand machine code, start with a simple hardware simulator with a limited instruction set.
I’m still not clear what you actually want to do and why.
You don’t need most of what C++ gives you in order to write code for microcontrollers. You don’t need objects, because your program won’t be big enough for things like inheritance to make a big difference in complexity, for example. The stricter type rules for C++ would just get in the way, given the kind of code you need to write to control a microcontroller’s peripheral hardware. And so on.
C is better for smaller programs which do relatively simple things very fast. C++ has good features for organizing larger programs, and a few nice features smaller programs can make use of, but it isn’t better than C in all respects, and, in some ways, it’s worse.
Even in microprocessors and processors you can use C++ and not C?
And don’t forget the bigger point. All those extra features like inheritance and templates and tons of other arcane syntax that is very confusing and complicated are basically all done better in Python. Or C#. But especially Python.
And if a program is big enough that writing it in C++ will help, it’s probably running on a system with enough memory for the Python interpreter.
Python’s only drawbacks are it’s slow execution speed and it’s relative newness in large scale systems. And you can fix the execution speed by profiling and redefining/rewriting just that hot 1-5% of the code in C.
C++ has pointers with the usual C operators. I’ve programmed with pointers in C++ many times. But a lot of the commoner uses go away in C++. And that’s a good thing.
It’s Java that has seriously messed up pointers so that coding “fun” linked data structures is a nightmare. (You often have to keep around a reference to a reference.) A large part of the problem is not allowing 1st order call by reference so you make stuff second order for no good reason.
So it is okay to start with c++?
Microprocessors cover a lot of ground. 8080s, no. The latest from Intel or ARM, yes.
You still haven’t told us what this is going to be used for. If you really, really want to learn C++ go ahead, but it might not be as useful as something else.
Everybody here is basically saying no. But I’m sure you’ll do what you want, anyway.
I do the vast majority of my coding on “small” devices. These days that usually means processors with somewhere between 1K and 64K of SRAM, and 4K and 128K of Flash. In these devices, every single byte counts, so a language that generates compact code is important. Also, I never, ever let software manage my memory. So, no malloc, no recursion, no garbage collection, no fancy “objects” which can instantiate themselves and use unpredictable amounts of stack or heap space. So, C++ is pretty much useless for me on these devices.
If you want to learn C++, don’t learn C first. The way that pointers are used in modern C++ is so different from how C uses them learning C first will hurt you far more than it will help. There’s no reason why you can’t learn about pointers while learning C++.
The following may be a useless digression for someone seeking employment, or trying to find the best language for a particular niche or curriculum, BUT …
I’ve wondered whether personal temperament should play a role in a person’s choice of programming language. After all, programming can be fun and fun is good.
As some very old examples, some engineers loved Forth, while others hated it. Lisp also had both ardent lovers and haters.
Although C and C++ may seem similar, I wonder if they sometimes appeal to opposite personality types! The old-fashioned “philosophy” of C is very different from the “philosophy” of C++. Just as one hint of what I’m speaking of: “Use the Source, Luke!” was a common mantra in C programming, while making the source of libraries unreadable was seemingly sometimes touted under C++. :smack:
Uh,Computer hardware and electrical equipment.That would include RAM,CPU,GPU,SOUND BOARD,security alarm,etc.
I haven’t found in what field of hardware C++ is used and I guess that C is more common in all electrical or electronical systems.
What a strange statement. I code all the time on small devices and use C++ exclusively. Sure, there are some things that should be avoided, like virtual methods. Other things, like basic organization into classes, is just good coding practice and has no machine overhead. And some things, like templates, are crucial for squeezing every cycle out of a function while maintaining generality.
IMHO, only a masochist would choose C over C++ at this point. C++ compilers are pretty ubiquitous now, even on tiny microcontrollers.
C++'s chief advantages are also its chief weaknesses: its extreme flexibility and extreme power. There are no alternatives, at all, for some kinds of problems. But that does mean it’s overkill for some things.
Python is a fine language but its high level of abstraction means that users can never really understand what’s going on under the covers.
I’ve been writing device drivers for nearly two decades and we use 100% C++.
And yes, the language does not obligate you to use all features. For various reasons, we don’t use exception handling, nor to we use the STL. Both things like templates are crucial. It’s far beyond just using the C subset of C++. We’re doing a lot of things that are just flat-out impossible under C.
Never heard of that before. Well-written C++ is easy to understand. Easier, in fact, than C. Of course you can run any language through an obfuscator if you don’t want people to read it.
I think there is a mindset difference between languages. I like to know exactly what my language is doing except on toy projects. Is this loop 6 cycles or only 5? (no, I’m not feeling lucky). I was recently reading a defense of the Go language as compared to C/C++, and it listed as features (among other things):
- No pointers
- Bounds-checking on all arrays
- Garbage collection on all memory allocs
Great–that makes it useless for real high-performance programming. I’m sure it appeals to some types, but not me.
When I was learning C++ after years of COBOL, it was obvious that many C/C++ programmers prided themselves on using as few characters as possible, readability/maintainability be damned.
At the time, I heard COBOL referred to as a “read-only language” (as in it was generally easy to tell what a program was doing but there wasn’t a lot the language could actually do) and C/C++ as “write-only” (you could make it stand up and dance if you wanted, but Zeus save the person who had to modify a program (and yes, there is unmaintainable code in any language (see the story of Mel, but C/C++ seems to lend itself to the problem)).
I phrased my remark incorrectly. I was thinking of a company (or companies?) which sold C++ object libraries and did not provide source code. The absence of source code was billed as a feature — “You don’t want your dumb programmers to even think of messing with this!”
I stand by my main point: Despite strong similarities, C and C++ have almost opposite philosophies and may appeal to programmers of opposite temperament. I’m afraid my temperament is strongly of a low-level DIY bent, so I don’t think I can offer any objective judgement on these languages. :dubious: