问题
Right now I am going through MIT's introduction to Computer Science course via OpenCourseWare. As a part of this course I am learning the Python Language.
I've read a lot of things about the benefits of learning C. Before I dig any deeper into Python I wonder if I will be hindered or helped by learning Python first.
Do you think that I will develop any bad habits or anything like that from Python?
EDIT: Changed to Community Wiki, because of subjective nature of question.
I appreciate all the great answers to my first SO question. I am actually pretty blown away by the sincerity of the answers/comments. Thanks, a lot everyone!
回答1:
Speaking from 37 years of working in God knows how many languages, I can tell you that working in Python allows you to focus almost entirely on getting the algorithm correct and not worrying about details. I have written probably 300-400,000 lines of C in my life and the only way it was bearable was basically to create my own OO environment.
C has its uses, but these days they tend to be either to a) let you get closer to a piece of hardware, or b) handle a really tight loop. If you find a need for it, look at a tool like SWIG or SIP to integrate your C into your Python.
回答2:
For historical reasons, C was the first languages many programmers, in particular these of the previous generation, learned. Yet many of them (including in this older generation), first learned one or several other languages, typically ones with a higher level of abstraction (Basic, LISP, Pascal, to name a few) before learning C.
I was of the latter kind (i.e. C wasn't my "native" language, although, I mastered assembly very early on), and I'm quite convinced of the many benefits of associated with a earnest "tour" into the C language, even though, as a matter of practicality, many of us will never program much of any consequence in this language. This said, I don't see any compelling reason to make C be your first language, or any inkling that somehow mastering Python (or Prolog or ...) would somehow impair one's programming abilities for the next decade...
So my advice: enjoy Python, take it in!
When you get a feel for programming, do make a point to learn C at some time. It is particularly relevant in a curriculum which includes compiler writing and/or operating systems, and, as said, relevant in many other ways. You'll see that other than for possible "surface"/syntactical gotchas (these happen all the time, at least to me, when learning a new language or switching back to an old language of mine, after being exposed to something else for a while), you should have no problems with C, at least no problems associated with your learning other languages.
回答3:
I am not an expert programmer, but from my understanding and use is that Python is a very simple and powerful language that allows you to do about anything you need.
With C you get more control on what is happening and that also means you have to write all those details yourself while in Python someone has done it for you and you have options that work for almost all different cases.
Because C lower-level (closer to how the machine actually works) it gets compiled to machine code more closely to what the CPUs want while Python, being higher level language, won't end up being as fast.
I think the transition pains from Python to C will be more like "Why do I have to do all this? In python I would be done in a single line!"
回答4:
I can only offer that learning C will make you appreciate Python and other dynamically typed languages more. I often say the same thing to anyone who is proficient with PHP. The creation of both scratched some serious itches. And no, its not like a "when I was your age I walked 300 miles in the snow to school" sort of thing.
Being able to assign a value to a variable and have the variable just 'adjust itself' to store what you feed it is an amazing accomplishment to anyone who has spent substantial time working with C on multiple architectures.
Additionally, writing a multi threaded service of some kind in C will make you really appreciate just how portable Python really is.
There are other good reasons, the power, getting 'closer to the metal', understanding memory management and learning about compilers and optimization. However, I suspect, the first thing that will hit you is just how cushy higher level languages really are.
Disclaimer: I mostly use C.
回答5:
You have to get started somewhere, and Python is a good choice for a starting programmer: You don't need to use a compiler (--> easy to use), has a rich library (--> you can accomplish a lot), and is object-oriented (main stream these days). So avoidable frustration is minimized in this regard. But always keep in mind that there are lots of other languages out there, and that you should learn them, too. If you want to become programmer and earn money, you need to (at least) pick up C++, Java or C# after Python.
回答6:
Good question! Always remember that your programming skills should never be language dependent. Although, C is an ideal language to learn when it comes to Computer Science. You have 4 levels when it comes to programming and normally every university undergrad course offer these subjects:
- Procedural Programming
- Object Oriented Programming
- Programming with Data Structures
- Design Patterns**
You have to go step by step.Do master all these 4 levels. Then at the end of the day you have to decide what you really want to do and then you'll have enough knowledge what features in what language you have to use for what problem. C is the language of many Operating Systems including Unix, Linux and Windows. C's power of pointers cannot be matched by any language so far. Python is a good language and has its own benefits. One important advice i can give at this stage is that of the "syntax". Initially you should master C language and gain a little practical knowledge of Python as well.Once you are comfortable with C then it will be quite easier for you to program in C++, C#, Java, and PHP. But if you start from Python straightaway then you might not feel comfortable with C_syntax based languages.Same goes for beginners who have passion for programming and start from Visual Basic. Also keep an eye on the industry trends and developments in programming. But stick with what the undergrad courses are teaching you.
I'm an undergrad student of CS as well and working as a programmer at the same time so i know what you are going through. Hope my advice will help you.
回答7:
The primary problem with learning Python first is that every other language you try to learn after that will probably suffer from the inevitable comparison. However, there are times when you must use a different tool because you have no other choice. Examples of these situations might include:
- very fast execution (SWIG, Cython, psyco, pypy, unladen-swallow, etc)
- platforms on which there is no python runtime (but these are rare)
- demand for high multi-core concurrency (different python VMs can usually deal with this)
It is probably best to approach each tool from a position of need rather than one of prudence; in other words, learn C only when it is required to do so because of specific situational requirements.
回答8:
Python has an immediacy that makes it easier to learn. Python for the ease, C (and related languages) for the power.
回答9:
As the question is stated: No. Don't learn C first. Learn Python.
Eventually you will have to learn C when you need to hack embedded systems, bootsequences, Linux kernel code etc. You will need to learn about pointers and that your system will crasch and burn if you don't get them right the first time. You will need to return used memory by yourself. This is usually a nightmare, and don't really contribute to the joy of programming as these things just get in the way and makes you spend endless time in the debugger.
Eventually on embedded systems you will learn some assembly language, and then you will realise that C is just a wrapper around most assembly/CPU possibilities in the chip architecture. Pointers is an addressing mode that is supported deep down by the transistors.
All modern languages makes you a better and faster programmer, and they have done away with these things. You don't really learn how to use a typewriter these days, unless your going to a place without electricity, do you? C is simply for very special applications.
回答10:
I do not think that you will somehow become fundamentally flawed by learning Python first. There are a lot of benefits to learning multiple programming languages and Python itself is an interesting way to explore that. For example, if you have some performance issues with Python you can explore writing some parts of your code in C (or pyrex/cython or Fortran etc...) and then packaging it up and making it usable in your Python code.
Personally, I like to write a lot of code by hand when I'm learning things. I think it is a good practice and writing algorithms (on paper) in Python is a lot of times more convenient than writing them in C or C++ (not always). This is pretty much for the reasons Peter was saying, there is less effort being spent on details and so you can then spend that on other conceptual things.
I am still very much a hobbyist, but one thing that I am coming to grips with is that a programming language is a tool, but it is often a unique tool. There are programming skills that are meant to be taken from one language to another and these are great. But being able to 'grok' a language is also very important, in a practical sense. For this reason, I feel that whatever language you decide to learn first doesn't matter so much because it is important to develop the skill of moving on and learning to effectively express yourself in another language anyways.
回答11:
In the world right now there is a certain degree of python "fanboysm". More and more programmers (some of them very respectable) believe that python is the answer to all their grievances. After seeing how "cool" is python, they start to evangelize the language, at a psychotic degree, denying the obvious truth: python is not meant for everything / everybody.
If you will follow the python path you will probably develop an additional reflex: "let's look into the libraries to see if it's not already done.", and after a while, when the time comes, and you'll have to learn C, you'll desperately say: "I can't believe i have to write my own dict using some void* pointers for holding my data! What's with this C language anyways ?!"
回答12:
Having been taught C/C++ as my first programming language in 1996 via Borlands TurboC++ 1.0 (blue screen and yellow text) I can seriously recommend learning something (in this case Python) other than C. That said C/C++ will help you if you ever want to know more about hardware interaction (embedded development, driver writing, etc.)
According to the Hanselminutes podcast the VB.NET compiler is written in C so it still has it's uses.
回答13:
Most programming concepts are independent of language; you are far better served by starting out with a language that's easy to learn and apply so you can focus on the fundamentals. That language would not be C.
C makes a horrible teaching language; it was never intended to be used as such. It was designed for experienced programmers who wanted more flexibility and control than other languages of the time (early '70s) provided. You spend more time learning about C's quirks than you do about actual programming.
来源:https://stackoverflow.com/questions/2399471/is-it-a-good-idea-for-me-to-learn-python-before-c-or-some-other-compiler-languag