views:

631

answers:

16

I know that there is a long debate regarding this matter. I also understand that this is strictly not a programming question. But I am asking here as this platform contains wide range of experts from different realms.

When we got admitted in a Computer Science and Engineering(CSE) course in university, we were first taught C. The course was actually structured programming language but we used C as the language. And on next semester we were taught C++ and Java as OOP. Recently I have heard that the department is going to introduce Python as the first language. I strongly oppose the idea for the following reasons:

  1. Python is a super high language. In the first course the students should become familiar with the basics of programming concepts like data type, pointer, by value or by reference etc. You can write lots of things in Python without understanding these in details.

  2. Python has a wide range of build in data structures and library. In first language students should become familiar with basic algorithms like sorting or searching. I know there is sorting library in C too, but that is not as widely used as Python's sorting methods.

  3. Python is OOP. How can you teach someone OOP when (s)he does not have the basic knowledge of structured programming. If Python is the first language, then they might not differ OOP with non-OOP concepts.

  4. Memory is crucial. If you allocate, then you need to release the memory. These concepts are not necessary with a language with garbage collector.

So what is your opinion? What do you prefer as the first teaching language?

Please don't start a flamewar or something similar. Whatever you suggests, please explain why you think so. And also please keep in mind that the course is for university level. It's not for kids and so trying to make things simple is not much helpful.

And also I know that Python is a great language. I am personally a fan of it. But the question is whether Python should be first teaching language instead of C.

Thanks in advance.

EDIT :

  1. When I asked this, I was not aware about programmers.stackexchange.com. It can be moved there if that is better.

  2. The question contains my opinion. That does not mean I don't wanna hear others. In fact that is exactly what I want. Please don't get me wrong. I am not designing the curriculum. So my opinion has no effect on it. The thing is I think this and this, and I want to hear what others think.

  3. I am well aware that this is not a question in that sense. My first para tells that.

+18  A: 

Bottom-up learning is often considered the "better" way to learn. Start from first principles and make your way up to more advanced ideas. The problem with this approach is that much of what we humans learn in life doesn't follow that model at all. Children, in fact, are the fastest learners and they do so by pattern-matching, extrapolation, interpolation, etc., all of which would be thoroughly frowned upon by anyone promoting the classical bottom up system. And yet somehow they run rings around adults in learning, say, the language in a new country, not by reading the bottom-up text books faster than the grown-ups, but by talking to other kids.

I don't know whether Python is the best language to use, but I do believe that any language that gets people writing code and solving interesting problems quickly can't be too bad a choice.

Marcelo Cantos
+1 ... and your ideas fit nice with a learning-by-doing-approach. Python is great due to it's pseudo-code like syntax and more functional semantics (as opposed to C's .... syntax). You can learn from complex but interesting things
Dario
Static typing might be great though ... Vote for F# :P
Dario
"any language that gets people writing code and solving interesting problems quickly can't be too bad a choice" -- Agreed
taskinoor
I'm kind of interested in the level of knowledge you are talking about. With the first language course, the target is pretty much to make the students understand what is a variable, what is a cycle and what is a function. Those who finish the course should be able to rewrite a simple algorithm (written in words) into code.
Let_Me_Be
Eric Raymond recommends Python as first language, too.
Rob
Eric Raymond recommends a lot of things...
Amigable Clark Kant
@Let_Me_Be: that is boring, though. why not make them able to create a Tetris game from scratch? which one is more likely to keep someone taking CS courses?
Claudiu
+2  A: 

Since you say it yourself

In the first course the students should become familiar with the basics of programming concepts like data type, pointer, by value or by reference etc. You can write lots of things in Python without understanding these in details.

C looks logical.

However, starting with Python will add concepts like functional programming into the students toolbox. They'll be able to handles concepts like map-reduce, or sharding, or parallel-processing much more easily than their peers...

I've been taught C, then C++, and today i must say that understanding functional programming is a bit hard since i think in these languages' patterns.

If you've got a say in the process, perhaps C should be taught for basics like memory management and pointers, but i'd recommend ditching it for Python as soon as the basic concepts are taught

samy
For that, there is Lisp, or Scheme.
Amigable Clark Kant
+2  A: 

In my opinion, C is better to start. It might be more frustrating than Python in the beginning, and you need more time to achieve the same end results, but in change, you teach them much more than just a programming language if you do it well and in detail.

joni
+1  A: 

As a C++ programmer, I would have to agree with your points. C teaches the concepts of programming languages that get closer to the nuts and bolts of how computers operate, with datatypes, memory management, ect.. On the other hand, python is alot easier to use, and may actually be effective as the first step, and it may make learning C easier (familiarity) or harder (datatypes?!?! whats that?)

I'd teach C first.

Alexander Rafferty
+4  A: 

Definitely C for the sole reason that it is a compiled language. Python moves a huge amount of errors into runtime. That is something unacceptable for the first language.

Our University recently dropped Pascal (which had even better compile checking then C) in favor of C for the programming introduction course. This choice was done because Pascal language syntax is something rarely seen elsewhere. Most used language have C-style syntax.

Let_Me_Be
C can also have a big runtime. Anyway, I think the reason is not compiled versus interpreted. An interpreted language can be very small, have a small runtime and powerful. See my answer.
Amigable Clark Kant
@Amigable How is that relevant to the first language choice?
Let_Me_Be
I think a first programming language should be a) Expressive b) Small syntax = easy to learn c) No side effects, also easy to understand d) Simple enough that a student can and will implement it in C. This will bring deep understanding of both theory and how computer hardware works.
Amigable Clark Kant
@Amigable LOL, reading that, one language jumped to my mind. Prolog. Interestingly throughout my studies and career I have met very few people who actually can grasp logical programming.
Let_Me_Be
@Let_Me_Be, +1 for Prolog. I have tried several times, I think I understand the syntax somewhat, but whenever I try to write even the simplest program in Prolog - I just stare at the screen.
Amigable Clark Kant
What does it matter whether the error happens compile time vs run time? Python doesn't have a compilation phase. With C, the there are a thousand times as many errors to trip over than with Python, and that is disheartening when you are learning and you can't even compile. If you can at least run it and see it dies after this point, it is easier to debug for a newbie, because you understand how far it got, even if you don't understand cryptic error messages.
Joshua Cheek
@Joshua Cheek. Python does have a compilation phase. It's when it catches syntax errors and indentation errors. All of the other errors (afaik) can only be caught at runtime because it's dynamic.
aaronasterling
@Joshua Not it isn't. Once a program compiles and dies during the run, it is impossible to debug for someone who is just learning programming. Irrelevant in what language. Plus with dynamic languages, the code almost never dies, what it does though is either die in a totally unexpected place or just return nonsensical data without any warnings or errors. C compiled in GCC (-std=c99 -pedantic -Wall -Wextra) and runtime checking with valgrind is the best thing out there prevent semantic and logical errors.
Let_Me_Be
I agree it's useful to learn the C syntax, because so many other languages look similar. However, I don't agree with your argument regarding compiled vs interpreted.
Zsolt Török
@Let_Me_Be If you write a program to do a,b,c,d and it does a,b and then dies. Even if you don't fully understand why it died, you at least know where to begin looking (between b and c). Alternatively, if it just flat refuses to compile, the problem could be any of a,b,c, or d. Plus error messages are nicer, you don't have to worry about accessing bad memory addresses, for example. C can die at runtime in ways where there is no feedback. Dynamic languages will always be able to give you a stack trace, at least.
Joshua Cheek
@Joshua If it refuses to compile then the problem is obviously where the compiler is telling you it is. What you describe in the first sentence is extremely rare in dynamic languages, the program will most like finish normally, just return nonsensical output. Clang error messages are pretty nice (although I still prefer GCC for its huge set of warnings) plus finding memory errors is trivial. You get information about what line is causing the error, what memory blocks were adjacent to that access (or if it is a double free, then where the block was previously deallocated, etc...).
Let_Me_Be
@Let_Me_Be no, you don't. This is a runtime error in C. http://img514.imageshack.us/f/screenshot20101026at103.png/ I don't know Python, but here is the equivalent in Ruby http://img176.imageshack.us/f/screenshot20101026at104.png/
Joshua Cheek
@Joshua Yeah, I sure don't :-D http://i.imgur.com/uLgJE.png
Let_Me_Be
@Let_Me_Be Well that's funny, I showed you my entire session, and I didn't get anything like that. I just got "segmentation fault" let me follow your steps and reproduce... oh, I can't, because you cut out everything except the alleged output. C programs are binary files. They don't have line numbers, metadata, or runtimes to analyze their failures and print useful errors. That would make them dynamic languages (like Python). Besides, even still, the Ruby version "`printf': can't convert nil into Integer" still makes more sense than "Address 0x0 is not stack'd, malloc'd or (recently) free'd"
Joshua Cheek
@Joshua Actually that's not the error, that's additional information. The error is the invalid read. Which is exact and precise. As per request, here is the full output: http://imgur.com/SllOr.png
Let_Me_Be
Now compare http://img176.imageshack.us/i/screenshot20101026at104.png/ You really think using gcc with an mouthful of flags and third party software that probably doesn't install on Windows in order to get a poor mimic of a runtime that comes default and fully empowered in any dynamic language is easier for newbies? Invalid read is exact and precise? If you don't know what that means (ie you're a newbie) it is cryptic. Compare to Ruby's saying in file.rb, line 2, printf can't convert nil into an integer. THAT is exact and precise. Starting CS with C is like starting History with the Dark Ages.
Joshua Cheek
@Joshua Interestingly that third party (kind of funny notion when talking about C which does not have any non-third party tools) will catch all memory errors (and thread errors). Yeah, cool ruby interpret can catch one specific error and provide a more meaningful output then C. And you don't like many command line options? OK, use clang then with it's nifty graphical output of errors (i will stick with my GCC, thank you).
Let_Me_Be
If what you are doing works for you, that is good, and I am not criticizing that. But you shouldn't assume that is what is best for someone new to programming. When I was a newbie, if I had tried to use what you are using, I would have dropped the major and gone to math. I sometimes tutor "intro to CS" students. Their biggest hurdles have more to do with environment than programming. It is important that there be a learning curve, not a learning cliff, or newbies will drop out like flies.
Joshua Cheek
@Joshua LOL, if that is true, then I would be responsible for a lot of drop outs :-D I teach C and C++ on a University.
Let_Me_Be
+3  A: 

In the first course the students should become familiar with the basics of programming concepts like data type, pointer, by value or by reference etc.

Mostly False. "data type" is True. The rest is not a basic of "programming". It's a basic of C.

You can write lots of things in Python without understanding these in details.

False. You need to know "data type". The rest (pointer, by value or by reference) is about C. Not programming.

In first language students should become familiar with basic algorithms like sorting or searching.

True

How can you teach someone OOP when (s)he does not have the basic knowledge of structured programming.

Easily. More easily than procedural programming.

If Python is the first language, then they might not differ OOP with non-OOP concepts.

False. Indeed, it doesn't make much sense. When you learn SQL, you learn non-OOP concepts just fine. No problems.

If you allocate, then you need to release the memory. These concepts are not necessary with a language with garbage collector.

Correct. But completely irrelevant. Everyone learns how objects are automatically created and removed in Python. It's easier to teach that than it is to teach C-language memory management.

Everyone gets C-language memory management wrong -- often for years. It's very, very hard to debug memory allocation problems. So much so that many folks give up on C because they can't understand how pointers work. Pointers and memory management isn't "essential". It's a bad hack.

Python's reference counting is easiest to teach and always works.

Since a few of your assumptions are wrong, what's the point of this "question"?

S.Lott
While I agree with you, I´d like to see the list of ``basics of programming concepts´´ extended by things like recursion, pattern matching or algebraic data types.
Jochen Walter
@Jochen Walter: In the context of this question, your comment doesn't make too much sense. The question didn't mention those concepts. Why introduce them?
S.Lott
@S. Lott: Because restricting the ``basics of programming concepts´´ to low-level things makes the question heavily loaded. But I seeyou changed your answer and exclude pointers and passing byvalue/reference from the list, which is also fine with me.
Jochen Walter
@Jochen Walter. In the context of this question, your comment doesn't make too much sense. "recursion, pattern matching or algebraic data types" Are not in the original question. Why did you bring them up?
S.Lott
+4  A: 

As I already say there my feeling is that Python is far more acceptable as a first language. It implies lot less things to explain to start.

Didier Trosset
+11  A: 

In the first course the students should become familiar with the basics of programming concepts like data type, pointer, by value or by reference etc

Why? You just state this without any justification. These are not necessarily fundamentals of programming, they are just fundamentals of programming in C. If you don't learn C, there's no reason to learn this.

Now, it's true that for advanced programming you will need to learn this. But you don't give any reason why it should be required for beginners.

Memory is crucial. If you allocate, then you need to release the memory. These concepts are not necessary with a language with garbage collector.

Again, why? Because C does it that way. But most of the other languages that they are likely to come into contact with allocate and release memory automatically, whether by reference counting or garbage collection. Doing it manually is simply not required for a beginner.

Like most people, I got started in programming through a language with no pointers and no memory allocation. In my case it was BASIC (Sinclair Spectrum version, since you ask), but these days a lot of people begin with dynamic languages like Python or Javascript. I certainly don't think I'm a worse programmer because I learned about pointers and malloc later rather than sooner.

Daniel Roseman
+1 I'm with you! See my answer please. I think though, that it helps if the language you start with is simple. Like MSX Basic for me, Sinclair Basic for you, or ideally if we had professors back then, Lisp. Python is not it though in my humble opinion. It is very complex.
Amigable Clark Kant
+1: These are not... fundamentals of programming, they are just fundamentals of programming in C.
S.Lott
@Amigable: Python is an amazingly simple language to learn. I have found that almost anyone with technical ability only needs to be shown how just one or two of their problems can be solved in Python, and they are immediately hooked (even the skeptical types), and invariably report a dramatic increase in their productivity within a couple of weeks. The fact that there is an awful lot to the language when you want to get more advanced is irrelevant.
Marcelo Cantos
@Marcelo, if you want to measure productivity, yes, it is irrelevant. If you want to teach the mathematical foundations of programming, no.
Amigable Clark Kant
@Amigable: The *mathematical* foundations? You must be joking. The mathematical foundations of programming are in the lambda calculus, complexity theory, the halting problem, type theory, the relational model, turing machines, models of concurrency, and so on. All of these can be taught much more easily in Python than in C.
Marcelo Cantos
@Marcelo, yes, but I am arguing those can be told _even_ easier in Lisp. :-)
Amigable Clark Kant
@Marcelo, I wonder if this is called in *violent agreement*.
Amigable Clark Kant
Gah, teaching this in something different then Haskel is a heresy.
Let_Me_Be
@Amigable: Call it that if you like. But since you argued that Python is very complex and I argued that it is very simple to learn, and then you countered with some argument from teaching mathematical foundations that struck me as a non-sequitur (How is the complexity or otherwise of Python connected with its suitability for teaching the foundations?), so I'm left struggling to see anything that one might call *agreement*.
Marcelo Cantos
@Marcelo. I think Python is better to teach fundamentals than C. I think though, that its' wealth of features and rich library support may detract from the essentials. That's it. So I agree on the C vs Python first language thing. If I get across any different, it's because I ramble too much.
Amigable Clark Kant
+5  A: 

Neither!

I think students should be taught Scheme or Lisp first. (Not Common Lisp, tail recursion, CLOS and what not. Just plain Lisp.) This will give an understanding of lambda calculus (no need even to mention explicitly that is what the students are doing.)

Lisp is math. Python is math plus a lot of clever pragmatic tools and libraries, with a sprinkle of peculiar white space handling. :-)

Math (Lisp kind of math, not trigonometry) is the most important thing to learn for a programmer. Then, when the students know about data structures in their purest form, recursion (which is neither an ugly word nor, which some people seem to believe, hard) they can learn C.

This will have the double benefit of not locking thought - mistaking the machine and the peculiarity of a specific machine or pointer model for the essence of programming, while still giving a deep understanding of both.

A perfect exercise for such a C class it to write a Lisp interpreter. You know, a really small one. For that extra aha moment the professor should make damn sure that all Lisp examples and code from the first Lisp class will execute in the Lisp interpreter the students write themselves.

This is not hard! It's just the order in which things should be taught.

We did much bigger C projects in school without most of us thinking it was too much ask.

In such a curriculum I propose, of course Python could be made to serve the role I propose for Lisp. But I fear all of Pythons features, libraries, rich syntax, classes, runtime, exceptions and so on may take away focus from what is the essence of programming.

Amigable Clark Kant
Math should be taught in mathematical software like Maple/Matlab/Mathematica.
Let_Me_Be
@Let_Me_be: not this kind of math: http://mitpress.mit.edu/sicp/full-text/book/book.html
Amigable Clark Kant
Hmm, interesting. We don't call that math here.
Let_Me_Be
http://en.wikipedia.org/wiki/Halting_problem <-- things like that were discussed by mathematicians at mathematical conferences.
Amigable Clark Kant
Well, that might be mathematicians, but we call this computer science or more specifically theoretical informatics. The same way you don't call a theoretical physicist mathematician. But we are not an English speaking country, so the semantics might be shifted.
Let_Me_Be
+1  A: 

I got taught C although they originally said that it was C++. My feeling is that you should teach bottom up, get the basic principles of logic and looping.

Then following on from this you should learn about OO, it took a week or two for the penny to drop with OO after learning C & the procedural way of programming.

For me personally OO after procedural way of programming opens your eyes to the power of OO.

As a developer you can then choose which way is right for your situation.

It also helps for when you are interviewing people - I have seen people claim they are OO developers and yet still write procedural code.

Datoon
+2  A: 

In my view (as an interested amateur) is that the first language should be a simple one where you can deal with the basic idea of breaking down a problem into steps, flow control, logic etc. This should be followed fairly quickly by learning a low-level language which forces you to learn wha is going on under the hood - what is actually happening to perform your algorithm. This would include all the things like memory addressing, pointers etc. After that any modern high-level language can be learnt in a useful way.

I started with various forms of basic (back in the day), followed by having great fun with assembler, c and c++. Although pretty much everything I do now is in python, it is great to have a bit of an understanding of what has to go on beneath the hood to acheive what I'm asking.

One of my friends is studying computer science and their starting language was Haskell. This seemed crazy - it might be a good language but it is so abstracted that it gave no understanding of what the computer is actually doing and therefore no suggestion of what was easy to calculate and what was crazily complex.

neil
Move from Python to assembler -- or the other way around. Then play with any other language you want.
Noctis Skytower
+5  A: 

The main thing about learning anything is to have fun and a sense of accomplishment.

I don't think a programming course should necessarily start with a programming language.

E.g. doing web pages in a text editor is great for learning about text and formal languages.

Alf P. Steinbach
He he, somone who prefers to be anonymous doesn't think that fun and accomplishment has much to do with learning, and voted this down. :-)
Alf P. Steinbach
+2  A: 

As a C++ programmer, I remember I have completely fallen into computer science only when I learnt C++. This was the language I wanted, well-organized, at the time I wanted - though I would have prefered learn it before (but everyone one around me was repeating it is difficult, hard to read blah blah blah)

Had I stayed stuck to the first languages I had learnt: BASIC, asm, Turbo Pascal or C... Then I would have simply given up computer sciences : They are too limited, syntacticly ugly. And I really don't think they taught me anything enough, since I thought they were ugly.

As some C++ features can be pretty hard to understand, slow learning curve, maybe it is not the best choice for all beginners. Depending upon their will, their needs...

So I would go for Python with OOP, and basic concepts: loops, logical test, lists...

And don't get me wrong, I really really understood pointers almost two years after having been teached them. But I could use them blindly without really minding: they must not be NULL, and we get their content with writing mytypeValue = *pMyPointer; that's all.

Pointer algebra is not as valuable as you may think. It's really self contenting to play with memory addresses and write something proudly like int iValue = ((++pMyPointer)^0x0F) ah ah ah this is complicated and I can do great programs...

But no this is not inteligent computer science. This is ego-C-esoterism ;-)

For beginners: If not for C++, with well organized classes. Then I would go for Python, with well organized classes.

Only my point of view... of course.

Stephane Rolland
+2  A: 

If you want to be familiar with machine compulting internals, like address arithmetic, memory allocation, data widths it is better to learn C (or even some another 'machine close' language (even assembler).

If you are more about high level concepts, like OOP, python (or any other high level language) is choice for you.

Ofcourse you may have OOP, GC and many other HL conceps in C (GTK has them!), but it will look not so elegant like in any language implementing these natively. OTOH you may also write programs in machine-close style in python, but there's no gain.

Vovanium
+4  A: 

I do not agree with the OP. I believe that students should be taught a higher, simple language like Python first, and then learn C.

In some ways, it is like learning to be an automobile mechanic. Although it is not required, most people learn how to drive first. When they start working on the internals of the engine, they have a better idea of why the engine works the way it does.

Many moons ago, I first learned BASIC in high school (this was before OOP even existed as a concept). In my first semester in college, I was taught structured Fortran. It was not until later courses that we were taught assembly language. At that point, I understood the concept of data structures, and learning how the libraries actually implemented them at the most fundamental level made perfect sense.

Similarly, I believe the beginning student will be better served by learning Python first. He or she will learn the uses of the data structures without having to be bogged down understanding how they work. Later, when they learn C, they will have a much better appreciation for them. Similarly, I would never advocate teaching a course in data structures before teaching an introductory language course. Imagine trying to explain how a red-black tree works when the student does not know what a subroutine does.

I have taught C as a first course and found it very difficult to get some of the more complex concepts like arrays and pointers across. I would much prefer to tell the students that this variable represents that array, without having to explain how the variable, in fact, binds to the address of the first location in the array, which happens to be on the heap.

If I were going to teach my father how to program, I would certainly not start with C :-).

My two cents...

Ralph
Red-black tree is a pure theoretical concept, there is no programming language involved in understanding how rb trees work. Plus teaching pointers in an introductory class, wow, that's bold.
Let_Me_Be
@Let_Me_Be: "Teaching pointers in an introductory class, wow, that's bold" -- yeah, and it didn't work.
Ralph
+1  A: 

In my opinion, its better to continue with C as the initial language to be thought. Python internally uses C implementation and assembly. The suggested syllabus for a junior student is

1) Assembly => Will give a real hardware platform exposure

2) C => Gives a rich idea to implement common data structure, will give a feel of using libraries. Compiling , Linking , Error fixing etc

3) OOPs => What ever be the language, a before moving to Objects oriented programming a student need to get a through idea, on the practice and patterns

4) C++ => Since the student is good with C/OOPs he can try for implementing the concepts with C++

5)Java/C#/Python etc which uses a better memory management pattern .Also being a advanced language, he can enjoy the flexibility of memory management, availability of built in data structures, libraries.. etc.

Being Python a powerful language students can take care of its benefits in scripting, Automation, Automatic test case execution etc.

It will be always a good idea to direct them to choose the technology based on the scenario rather than completely sticking to a language.

From my experience with the industry for designing applications like

Boot loader, Embedded applications go for Assembly/C

If a rich UI and less development time go for C# or any advanced languages

For using the power of plugins/Web portability go for Java

Python for automation , Creating a base COM engine etc.

C++ for a bridge between the real embedded hardware and the user interface.

Directing students in this way will be recommended..

Sajan Kumar