I think Python is probably an ideal first language; even though I dislike the language, it has automatic memory management, a
lot of included libraries, you can learn the syntax in a few minutes, and you don't have to write any boilerplate to get started. It also has a pretty good interactive interpreter which is important for some students (I personally have never liked using a REPL).
At my university, they teach Java first, so students are using classes before they even know what an object is. Students are writing all this stuff about classes and main functions before they know what any of it is. All they know is, they have to write a bunch of things that don't seem to do anything in order to make their program compile. With Python, you can just start writing code and the interpreter executes each line in exactly the order that you write them. When you learn about functions, you can start breaking your program up into functions, and when you learn about classes, you can turn some functions into class methods. The language naturally lends itself to learning to program in the most logical order.
After Python, they should teach C so that students learn how to do manual memory management. I don't think C should be taught first because introductory programming should focus on teaching concepts, but it is important to understand that garbage collection is only there to make things easier and not the way computers actually work. At some point you do need to know how memory actually works. Most courses have a vaguely-hardware oriented section and C should be taught in tandem with that. They could also teach at least one assembly language (my vote would be ARM) at the same time, especially to show how C is translated into assembly. On my course, they taught us AVR assembly and Arduino C(++, but we didn't create our own classes - we used Serial but we weren't told that it's a class object) in the first year, which I think was a good idea.
Then Haskell. At my university, functional programming is an elective module (although the professor who teaches it also teaches Data Structures and Algorithms, and in that module, he makes us write all our algorithms in a functional style even though we're using Java. I fully support that idea) but I think it should be mandatory. Functional programming will only increase in importance as clock speeds stabilise (already happening) and the focus switches to multicore.
Then Prolog, just so that after having their mental model of what programming is destroyed and reformed by Haskell, they can have their minds blown again by Prolog. I liken it to the programming equivalent of what LSD enthusiasts call "the thumbprint", in which a person consumes a thumbprint's worth of LSD crystals (equivalent to up to 1,000 normal doses) and completely loses touch with reality.
Finally, they can return to the world of mortals by learning C++, Java, C# or whatever, because realistically, to be considered a practical degree, they have to teach you a language you're likely to actually use. Most CS students aren't going into academia or anything cool, just code monkeying, so they're going to need more practical languages than just C and Python. Maybe those could be electives, instead of Haskell. Alternatively, they could teach these languages in between Prolog and Haskell so that students think they're safe, that Haskell was just one weird language that they'll never see again and they're back to the world where everything makes sense and code executes in order, and then BAM! Prolog.
I estimate that, using this method, CS courses could double or triple the productivity of their graduates (which is good, because they would probably also halve the number of graduates. But that would be good for us - fewer programmers means better salaries for the rest of us).
Avilius wrote: |
---|
I was comparing the common usage of C and C++. (Based on when I see it) |
Still, you were comparing idiomatic C++ with non-idiomatic C.
The struct implementation was clearly the superior one. |
Only if you don't need to control access to the values. C# has something called a property for that. It's used the same way as a member variable, but you can provide custom accessor and mutator functions
You can also implement your own properties in C++:
http://pastebin.com/pn4dJfb9