If someone wants to learn programming starting from scratch, in which order should I recommend to learn which programming concepts? Should he start with data-structures or algorithms. When obejct-oriented-programming should be introduced? Should he take a look at functional programming? Should he learn about pointers and heaps, even if I recommend in the end a language with automatic memory-management?
"Beginning Programming" from Wrox Press mentions different languages, then talks about editors and compilers before any other concept. Then it gets into the idea of statements, and "paragraphs" of code, before getting into functions, then data (variables).
When I teach complete newbies, I start with the idea of variables, move into assignment, then conditionals, then loops. The concept of "statement" naturally falls out, and the concept of "block" comes along with conditionals. Only then will I start on functions, both calling and then creating.
Althoug it never happens this way, it's not entirely a joke :
- Hello World
- Commenting and documentation
- Design by contract
- Unit Testing
Backing up and Version Control
All the rest
UPDATE :
A true tragedy it is, that unit testing and commenting and the like are seen seperate from programming!! It is the reason so much bad code is around us. Indeed, a good language should incorporates stuff like commenting (javadoc, sandcastle) and even design by contract (eifel, spec#)
Start a complete beginner with much, much more basic concepts:
- Tiny program examples, to introduce
- Logic, fundamental structured programming concepts: sequential operations, branching, looping
- User (keyboard) input, then very simple file I/O
- Data types: integers vs. floats, characters, strings
- Records: collections of data, including arrays; write records to a file
- Dynamics: memory allocation or object (record) instantiation, based on unpredictable events like user input
Once a beginner understands basic logic and branching, grouping & typing of data, file I/O, and the concept of dynamic memory use, then they're potentially ready to start on serious data structures (lists, trees, hashes) and algorithms (sorts, hashing, graph traversal). Organizing code into functions comes somewhere in the #4-#6 range.
I am teaching my 12 year old son programming in c#. I would not necessarily have chosen c# but the book I found is the best I have seen. It allows me to have an outline and story to work from. To get to the point, it starts with viewing the customer needs, writing requirements, then UI, then coding, then test. The 2005 book is very beginner. The 2008 book is more focussed on writing code. http://www.johnsmiley.com/main/mybooks.htm
Here is my list:
- Hello World
- Backing up and Version Control
- Unit Testing
- All the rest
Reasoning: You should be able to code something very small because the rest doesn't make sense without this.
Next is how to manage your code in a VCS. This should come early so it becomes a natural part of your workflow.
Before you start to learn "poor man's unit testing" (write code, run it, eyeball the result, fix it, repeat), you can spend the time to learn the real thing for the same price.
Anything else is just icing on the cake and can be deferred until you need it.
I don't think you really need to look much father than the chapter headings of K&R (The C Programming Language), With maybe some adjustment for modern practice.
- Types, Operators and Expressions
- Control Flow
- Functions and Program Structure
- Pointers and Arrays
- Structures
- Input and Output
Nowadays Structures would probably be 'Structures and Objects' and Pointers and Arrays would place less emphasis on pointers, but it's still a remarkably valid set of fundamentals and the order in which to approach them.
I recommend first learning generally a little more about how computers work, how the memory works, etc. It shouldn't take to much time if the person is already familiar with the basics. If this is not possible then a basic explanation of the memory concept.
After that, the person should try to get a feel of programming by learning as much as necessary to be able to build his own modified version of a "Hello World application", compile it and run it. The "Hello World" is very basic in every programming language and can be quickly explained, understood and picked up. At first, the person should be able to find a way to interact with the programming languge syntax and basic construction of a working program without much writing and memorizing.
Object oriented programming should, in my opinion, be introduced after the person has had a sense of the language and basic algorithm and array construction. It should be soon after loops and functions, after the person is comfortable with the previous knowledge.
Pointers and heap often confuse people so they should be mentioned and then reviewed later on before getting serious into memory. A bit by bit the person should feel good about programming and wanting to move on.
Many of the suggestions so far are excellent.
I'd advise starting with something simple that lets them see visible results quickly. As ugly as Basic is as a language; it let us do that back when people learned it in QBasic, on Commodores or Apples, etc. Python, perhaps with Pygame, can probably do that today.
The order of instruction in K&R also seems wise. After they've gotten through that, then I might start them on functional and perhaps object-oriented programming.
My approach would be to slowly immerse in the programming world through real-life examples.
Introducing objects and inheritance using means of transportations, for one, helped me understand quickly. Properties are logical from there on, and variables can be easy to connect to.
As in: Bob has a car. Bob's vehicle has four wheels. Carl has a motorbike. Carl's vehicle has two wheels. Carl gets rid of his motorbike and decides to use Bob's car too.
Such examples helped me start. Then, when there is solid comprehension of the general concepts of programming, go on with language-specific stuff.
[edit for addition] In an order of personal preference, I would go with simple comparisons first, along with typing, then loop structures, basic understanding of the mechanics of events (as in "things happen when stuff interacts with objects"). Starting there, you should have some curiosity in other stuff, and maybe the tools needed to go a little further without hitting your head repeatedly on a brick wall. As a student, that's how I learned, and that helped me alot when learning new languages.
My steps:
- Boolean algebra
- Algorithms (using Data structures, Numerical Maths)
- C/C++ (use this language to write programs)
- After this you choose any language you want and start learning it.
I'd recommend starting him with a language such as python. This is one of the easier languages to learn.
I think teaching him a functional language to start with would be a big mistake. After he has a solid understanding of imperative languages and is ready for a new way of looking at writing programs, introduce something like Haskell.
The temptation here is to go to one of two extremes:
The newcomer is lost, terrified, huddled in a corner next to a cursor and the word "printf". They are in a dangerous environment and a C++ compiler will eat them if they put a foot wrong. Make everything soft and fluffy and sit them down in front of Python or Ruby or something like that.
The newcomer is a perfect, 100% attention-giving nerd who will not hesitate to give three days of his life understanding the concept of a class or a function (or a unit test) before touching the keyboard. Give him a copy of C#, a 700-page textbook and a coke and leave them to it.
Neither of these extremes are much good but I guess it is about judging their character. Some people -- even some of us techies -- need instant success, like caffeine, whereas others of us will go for hours for just a single number to read correctly. It depends on the person.
(I know we are bored of it depends answers... but it's the truth!)
Oh and find that writeup that went around (anyone have it?) about will-a-person-make-a-good-programmer. Quite apart from their litmus test, it has educational value of its own.
Well,
I started with Borland C++ and quite often fellt like this was'nt the worst choice for my 'fist language'. Actually I think the 'older' languages are a good starting point since they are not as overloaded as some of the newer ones appear to be.
Don't get me wrong, C++ is way not simple - but it's a good starter anyways. I think.
Best,
KB22
Most beginners become lost and lose their focus quickly. I find it helps to work with them towards a concrete goal, such as displaying data on a webpage, or a desktop app that can talk to google. Although they won't fully understand everything it keeps them focused and excited.
These responses are good but, honestly, they are all missing one small point. Because the OP was asking about "someone" learning, I think the place to start is with the "someone." Learning is always best when the student sees the information as relevant, and relates it to something already familiar. It's also best when s/he sees it building toward a desired end point, i.e., working towards learning how to program something personally interesting. So, I would ask what sorts of things the person is interested in doing?
I'm only a hobbyist. There are lots and lots of things I still need to learn; watch for posts from me in the coming weeks and you'll see what I mean :-) However, I'm experienced enough to have dabbled in languages as different as Python and Delphi. I love each one, but find them to be best for different kinds of tasks. I wouldn't go so far as to say one is "better" for all beginners than the other.
Just my .02.
My List:
- Simple output ("hello world")
- variables, simple data types
- flow control (if/else, loops)
- basic i/o (users, files)
- arrays, strings, other more 'advanced' data types
- functions
- objects
- recursion
- data structures
- design patterns
- regular expressions