https://www.quora.com/Which-one-should-I-learn-first-C-or-C++
Which one should I learn first - C or C++?
34 Answers
I'm a bit of a hypocrite here - I learned FORTRAN and C long before I learned C++, and the C++ I learned first was a much less mature language than the current one, especially in terms of patterns - but I would like to point out a common fallacy that appears in nearly every single response that advocates C. Every one of them says something like "knowing C is a prerequisite for understanding C++" or "C++ is an extension of C". This is a clear indicator that they do not understand C++ as well as they believe they do. Here's the thing... to really understand C++, you have to understand the machine code it generates. You can best understand the machine code in terms of assembly, and C is closely mapped to assembly... but efficient machine code generated from well written C++ no longer in any way resembles well written C, and that's the point that the C advocates completely miss.
Modern C++ requires you to think in several paradigms at once. Once upon a time, long before the first standard, C++ encapsulated two paradigms - procedural programming (like C) and an object = data + methods + method overrides version of object oriented programming (like Java without annotations or reflection). Learning C taught a couple of bad habits, but it wasn't a huge jump from C to C++, and learning to write terse functions in C actually made you a better C++ programmer. Now, though, C++ has evolved to incorporate generic programming (in a manner far beyond anything Java could ever dream of), generative and algorithm driven programming (think of this as a static form of functional programming), and functional programming (though there are limits to lambdas in C++, mostly on account of the early evaluation of execution paths) - and, more to the point, it has evolved into a language that, in its best-use form, incorporates these paradigms seamlessly to express models of whatever problem is being solved. This is not something that comes easily to someone who has taken a deep dive into a single-paradigm language like C or Java. It comes more easily to someone who has started with a language like Python, as you have, though concurrency tends to be a difficult hurdle for people coming from Python.
Every so often I find myself trying to integrate an obvious C programmer who learned some superficial C++ concepts into a deep C++ codebase, and the effort is always painful. Do yourself a favor... if you do feel compelled to learn C first, don't go straight to C++. Fluency in Python does mitigate some of the pitfalls, but the temptation to view C++ as an extension of C is still a danger if you attempt that transition.
C is the ANSI standard assembler. C allows for very low level control of the system hardware resources, while making the use of higher level abstractions cumbersome.
C++ was an attempt to raise the level of abstraction of low level system programming without making any attempt to sacrifice the ability to get great performance. Unfortunately the desire to not sacrifice performance in general, and the desire to maintain backward compatibility with C at the source level, resulted in a programming language that was large, complex, and difficult to use or master.
I tend to describe C++ as the ANSI Standard Program Language builder. The reason being that no one programs in C++, what they program is a dialect that they create out of C++ either by restricting themselves to specific features or by creating abstractions that they require before you can usefully write code.
As a result of this programs written in C++ tend to be so divergent from C style and idioms that it makes a mockery of the attempts to retain C source compatability...
So which to learn first: if you're just trying to expand your toolbox, learn C. If you have a job to do and the job is in C++, just go and learn the specific dialect of C++ that the job requires, don't try and learn the entire beast of the language and bypass C. If you want to learn a very complex language system then I recommend learning C++ directly.
As you probably know, Python is written in C, and it's common that C is used to write third party libraries for use with Python. As a proficient Python programmer, C is a very good compliment, if you need to speed up parts of your Python applications, or e.g. interact with hardware which is only available through some C API. Cython is a convenient bridge between Python and C. The kind of additions that C++ brings to the table in addition to C's features are mainly things you can do much, much more conveniently in Python. C++ handles large programs better than C, but if you want to write largish applications, it might be a better idea to compose them from several smaller programs anyway... Particularly if you want to learn C++, you should make sure to learn to use the modern (C++11/14) features, since that's a much better language than last century C++.
Duc Nguyen
• Upvoted by Nathan F Yospe, C++ standards expert, fluent in Python, Fortran, Matlab, C, Java, C# and Sergey Zubkov, C++ programmer (using boost and C++14)
ViewsI suggest therefore, directly start with C++. The concept of C will be "automatically" learned then. (The language C is really smaller and easier to learn than C++ though)
Some good source for learning C++: Standard C++
Bonus point, I you're looking to experience what C is/was all about, write something using UNIX sockets APIs or anything that would require you to read old but still used 'man' pages. Like a simple server/client combo.
Travis Hance
• Upvoted by Jessica Su, CS PhD student at Stanford and Vladimir Novakovski,Competed in IOI, ACM World Finals
ViewsC is simpler, and in many ways knowing C is a prerequisite to knowing C++. It is true that there are many things you do in C that you won't need to do in C++ (for example, in C++, you'll use many fewer pointers and array and a lot more
shared_ptr
s, references, and vectors
). However, knowing these low-level concepts is essential to understanding what these higher-level C++ abstractions are doing and what problems they are solving.
Originally Answered: Which programming language to learn first C or C++ and why?
There will be people who might recommend learning C++ first and then switch to C (if want to do lower level stuff).
*Explanation:*
C is a procedural programming language. Therefore, learning C first forms a good base as every task you do in C will be structured in the form of procedures (also known as methods, functions, sub-routines). It means that every executable code will be contained inside these procedures.
This helps in constructing a series of computational steps to be carried out and will help you in dealing directly with the problem.
http://en.m.wikipedia.org
C++ introduces a different programming paradigm - object oriented programming. It forms an abstraction layer on top and treats every thing as an object which has methods/functions associated to it.
This offers a more real life scenario and helps structure the code better while dealing with problems.
http://en.m.wikipedia.org
Comparison:
The focus of procedural programming is to break down a programming task into a collection of variables, data structures, and subroutines, whereas in object-oriented programming it is to break down a programming task into objects that expose behavior (methods) and data (members or attributes) using classes/interfaces.
Thus, IMHO I'd recommend C first (but no need to dive deep) and then switch to C++.
Jerry Coffin,
• Upvoted by Nathan F Yospe, C++ standards expert, fluent in Python, Fortran, Matlab, C, Java, C# and Sergey Zubkov, C++ programmer (using boost and C++14)
ViewsIf you learn C++ first, chances are pretty good that you'll find restricting yourself to C later so irksome that you'll never really learn C as a thing in itself--you'll just learn C++ and a memorized set of restrictions that will let a C compiler process your code (but it probably won't really ever be comfortable C code).
If you learn C first, you'll have to spend a lot of extra time unlearning habits from C that are really counterproductive in C++. It is possible to get past all these hurdles and used C++ well despite knowing C, but at least if you learn to use C very well at all, it really will cause you a lot of extra work and pain.
So, if you really want to know both C and C++ well, there's not much real choice but to bite the bullet and put up with the fact that learning both is a lot more work than the mere sum of learning each one individually.
If you don't really care a whole lot about knowing how to use both well, then I'd advise learning the one you really care about, and leaving it at that. If that one is C++, you'll be able to read C pretty easily afterwards, assuming you can get past gritting your teeth at all the repetition, clean-up code everywhere because you don't have destructors, etc., ad nauseam. If that one is C, you'll probably be able to read most C++ code reasonably easily afterwards, provided it doesn't get too heavily into template madness and such.
I've used C for three decades and C++ for two, and my perspective is that C++ is
1) ANSI C without some of the really old stuff nobody uses
2) A fairly obvious class system that most C programmers think of, based on structs, but with a bunch of weird rules for overloading.
3) A game involving figuring out how many things you can do with the ampersand, const, a plastic chair, and an old guitar strap I got from Jeff Beck (c.f. Frank Zappa)
4) Some pretty powerful and magical templates
5) A pretty nice standard library, which you can't use on most projects due to cultural reasons
6) cin and cout, which hardly anybody uses outside of class and debugging and which serve mostly to illustrate the dangers of being able to overload operators to do something totally different from the C meaning
As much as many neo-programmers love to bash C, a lot of it is because so many flavor-of-the-month languages like Java and Python are so far removed from how a computer actually works that they're quickly bewildered. C is closer to the metal than any programming language other than Assembler while still retaining high-level abstractions. C is also much simpler than C++, as C is strongly procedural while C++ includes the capacity for every programming paradigm under the sun (and then some).
After so many years of living with your parents (Python), the next step is to live on your own for a while (C) and get a feel for that before trying to build your own house (C++).
Originally Answered: Which programming language to learn first C or C++ and why?
Both are excellent choices though, in my opinion.
I recently learned C, and then more recently learned C++ (really C++11 because I had the good fortune to learn from a standards committee member).
I think either path has its merits; you do need to know C, in a sense, to understand the details of any C++ implementation. But as far as learning to write C or C++ code, there are definitely some strongly contraindicated practices that will get you in trouble if you try to carry them from C to C++ (whereas you simply won't be able to use C++ features in C, so the transition would at least be enforced by the compiler).
I'd say reflect on the particular problem domain and/or workplace you'd like to enable yourself to work in, and go from there. Systems software and legacy C++ codebases seem to usually have large chunks of pure C they rely on, so learning both would most likely benefit you regardless of order; on the other hand if you want to write a cutting edge C++ application from the ground up (think computer games, fast big data server backends, similarly complex stuff), you'd probably be better suited by learning C++11 from the get go. C++11 is really great, and actually facilitates both faster writing and learning of C++ by deprecating some hacky practices that were necessitated by the feature richness of older specifications, especially regarding object construction. It's not entirely gone, and learning order of construction rules is still gnarly, but there are features available that let you circumvent the worst parts now.
Start with C, C++ is a complex multi-paradigm language with lot of warts whether C is a simple single paradigm language. Mastering full features of C++ takes years of practice.
C++ has basically five parts:
- Structured (Like C)
- OOP
- Generic Metaprogramming / template
- Functional - lambdas, value type.
- Other
It leads to anywhere you wish. It opens the pathway to Object Oriented Programming. So you can learn java/C#/python or any highlevel programing language.
If you like to learn low level programming, you can call assembly code or any C library from C++.
The whys of C++ are very tightly coupled with the whys of C and therefore C knowledge is required to truly work with C++ on an intuitive level.
You don't need to learn C and in fact, there are quirks about C like the way programs link, that do not exist in C++ as we know it today. However, C++ is a massively complex beast and it is easy to be overwhelmed by the seemingly never ending list of keywords at first and know which one you should use when. This is why most people suggest learning C. This is when you need to go back to the C roots to see why things are the way they are.
In the end, you will end up learning both.
You should go directly to C++.
Regards,
Nicolas
Pareto for Developers - How To be an Excellent Programmer
its really nice that you know about python programming .
As a computer engineer i would personally suggest you to begin your pursuit with language "C" rather then c++
Advantages-
1. you will be able to learn about pointers structures which will help you visualize the data structures like linked lists easily and efficiently
2. you will be able to implement algorithms on a very base level through c though a lot of coding is to be done to accomplish a simple task
3. Linux and unix os were written in c
decision is yours all d best goodluck
Please download a decent compiler like Clang/LLVM 3.4.x or GCC 4.8.x or recent version of Visual Studio express. All of them have excellent support for C++11.
As Bjarne Stroustroup puts it, "Modern C++" should mean in the 2010s: a language for programming based on light-weight abstraction with a direct and efficient mapping to hardware, suitable
for infrastructure code.
The C++ Programming book in its 4th edition is an awesome book to read.
The C++ Programming Language (4th Edition)
When i started reading that book, i couldn't put it down and read it cover to cover as i typed the various examples to understand the concepts better.
There are plenty of Open Source C++ projects whose code you can study as you work through.
If it so happens that you have to work on a project that requires you to look at C++ code base written in the last 10+ years or so, i'd suggest taking a quick look at 'Large-Scale C++ software design by John Lakos' or the two volume set of POSA to get going.
All the best for learning C++11 :)
If you want to learn C/C++ this is probably out of performance issues be it speed, code size, or memory footprint, in which case you need to understand the low level aspects first, which also means C.
Learning C will allow you to get the low-level power of C and C++, in particular the use of pointers which is possibly the most intriguing feature coming from a higher-level language. C will also give you a strong understanding of memory allocation issues, performance, and strategies (static vs stack vs heap).
From there, if you need to do OO programming you could then learn C++, giving you additional memory allocation strategies and much more. Your prior understanding of C will allow you to better understand the costs of various types of classes and inheritance.
C, although a very similar language to C++, is a very different language. The whole thought process in C is different compared to C++.
And as you say you are coming from Python, it is going to be even worse. I find C++ and Python more aligned and C totally out of the league (no offense).
C is more structured and linear. C++ and Python are more object oriented/based.
For any student who doesn't know much about programming, I would recommend learning C first, as it would help him understand a lot about memory handling. C is also a lot simpler with much lesser to learn.
C++ is a much larger language and has a lot to learn. However if one is already well versed with OOP then he should go with C++ first and move towards C later, which is a little closer to middle level language.
C
if you really care about the underlying logics of the working of a code and it's compiler. It's an old language, and hence, requires a lot of man-labour. But if you do get good at it, many things about the working of computers will become clear.On the other hand,
C++
, being fairly new, coupled with the latest libraries and standards, does reduce the code size to some extent. So, if you wish to apply and work with logics of the code, and dont bother yourself with the magic behind it all, go for it!However, I'd personally recommend going for
C
.You can always reduce the code size, once yo know exactly what will happen when you do `this` or `that`.
Besides, if you wish to write even smaller codes, go for python or ruby
'c' tag wiki - Stack Overflow
'c++' tag wiki - Stack Overflow
I learned C first by the way.
If C++ curriculum is taught in a manner where one is assumed to be familiar with C already, then C is a prereq.
It is not like you can never learn any other language without learning C. But if you have learnt C first then it will enhance your level of understanding.
So as per my point of view, learning any new language without knowing C and with knowing C is totally different.
You should learn C first.
Originally Answered: Which programming language to learn first C or C++ and why?
It doesn't matter but c++ is more powerful and covers all the features that c supports, I would suggest to start with c++.Most of the IT industries now uses c++. I have hardly seen any industry that uses C unless they have already developed something in C and they are just maintaining that flow. At last for a developer concepts for any language gonna be same just syntaxes are different
Comments
Post a Comment
Comment here.