C++ as a first language [closed]

2020-02-16 06:44发布

I've been self-learning C++ for about 4 months now. I'm enjoying it, and I think I'm doing quite well. However, an answer to a question of mine got me thinking that I might be setting myself up for a fall.

So, what do people here think about C++ as a first language to learn? And is it worth me just carrying on now that I've made a good start?

标签: c++
30条回答
贪生不怕死
2楼-- · 2020-02-16 07:20

Is C++ a good first language?

It's certainly usable as one, as you've found out. I wouldn't specifically recommend it for an introduction to programming in general (I'd prefer Python or Scheme), but it depends on your goals and learning style. I've taught programming in C successfully, and when approached properly C++ is no more difficult.

If your goal is simply to learn C++ for some particular purpose, I really don't know a better method than going ahead and learning C++.

If you like challenges, you might want to jump into C++. The learning curve is fairly nasty, but once through it you'll know a lot of stuff. (People still do learn how to use the vi editor, after all.)

I would recommend learning the higher-level stuff first. Learn vectors rather than arrays, use smart rather than ordinary pointers, that sort of thing. Partly because you should wind up programming like that (for most purposes), and partly because there's less stuff to remember at first. You will need to learn the lower-level stuff eventually, just like you'll need to learn the bit-twiddling stuff eventually.

查看更多
Viruses.
3楼-- · 2020-02-16 07:20

If you're four months in and doing fine, stay the course. However, I wouldn't recommend C++ as a first language in general.

In grad school, I was a teaching assistant for a first year computer course that all engineering students had to take. The course used C++ as the teaching language and I think now that this was a very poor choice. About 10-20% of the students 'got it' right away and breezed through the course (as a SO user, you're probably in this catagory), the middle 70-90% worked hard and did OK, and the bottom 10-20% were still having trouble telling the difference between a variable declaration and a function declaration half way through the course.

Too many students were bogged down in the syntax of C++ as opposed to using computers to solve problems, which is what a general first-year computer course should have really been about.

查看更多
Anthone
4楼-- · 2020-02-16 07:22

Carry on. C++ is still widely used and THE language for certain kind of work. So it depends on what you want to do - systems programming is done in C++ or C, business and web apps tend to be done in other things.

I do strongly recommend that you explore other languages as well. Python is my second language, for example; it may give you new insights about object-oriented and functional programming and make you a better C++ programmer (and a better programmer overall).

I believe being exposed to as many languages (and, more importantly, to many different programming paradigms) will make you a better programmer overall. Take a look at Haskell, Prolog, Lisp, and an Assembler variant, at least.

查看更多
爷、活的狠高调
5楼-- · 2020-02-16 07:23

Lots of support for c++ here, but I have to disagree. Every language has it's plusses and minuses (some achieve a better balance than others, of course).

That being said, for a first language, I'm convinced most people will learn how to program more effectively with a language that a) doesn't have an edit-compile-run cycle (which is inherently slower for you as the programmer b) has garbage collection c) has good runtime introspection. Best of if there is an interactive evaluator as well, to mess about with.

Development (if not runtime) is almost invariably faster in such languages, there are fewer things to trip you up, and there are better tools to help figure what went wrong when it did.

Which isn't to say learning the vagaries of memory management in a language like c++ isn't something worth doing, etc., etc., it just isn't the place you really want to start.

Another issue with c++ is that for all its practicality the sheer size of it added to the fact it has incompatible parts that can lead to subtle issues best avoided as a beginner.

edited: John D brings up the point in a comment that some people who learn first on a GC'd language (which is by no means limited to "scripting" languages) never learn pointers later. This is a red herring, though. Some people fail to learn all sorts of things, for all sorts of reasons. I maintain that worrying about pointers is a distraction when you're learning the basics. At some point you may well need to learn about manual memory management, but it's not fundamentally important to do this at first. Or more accurately, the gains made by avoiding this are more important than the costs.

Let me be clear though, I'm not saying that c++ is an inferior choice for a first language because it lacks garbage collection. That's just one of many issues that get in the way of learning the fundamentals of programming well. The real problem is that it is a large complicated language, with quirks all over the place and even internal inconsistencies (e.g. pointers and exceptions don't play well together). Of course all of this can be managed properly and you can learn good practice to keep from getting in trouble.

However, none of this will make much sense to a real neophyte at first. So some of learning it will end up being "do it this way, not that way". "why?" "because I said so --- you won't understand the details yet". Hardly an auspicious start.

The bigges gains for learning a first language though are probably in avoiding a edit-compile-run cycle (of any kind) and having good introspection.

查看更多
Explosion°爆炸
6楼-- · 2020-02-16 07:23

C++ will be (much?) more approachable if you learn "modern C++" rather than "C plus some new stuff". For example, use std::string, std::vector<>, and unique_ptr<> / shared_ptr<> instead C-style strings, arrays, and pointers.

The already mentioned Accelerated C++ by Koenig and Moo is one book that does exactly this.

查看更多
▲ chillily
7楼-- · 2020-02-16 07:23

I think that C++ might not be the most user-friendly language to develop in for a first timer, but it is also not going to hold your hand and necessarily lead you towards too many bad habits (I didn't say any, just not too many).

C++ was the introductory language that my university's programming courses were based in and that's where we learned all the basics and about data structures and algorithms before branching out into the languages of our choice.

查看更多
登录 后发表回答