tags:

views:

1271

answers:

21

I would like to know the best methods for learning to program. I've been directed towards the Python language because I was told it is good for beginners. I ultimately want to make games for OS X/iPhone.

My problem is that I understand what I read but I can't apply my knowledge to anything. I am a programming noob.

Should I stick with Python? (is there a better language I should be learning?) Where can I learn programming theory? I get very hyper when reading my book sometimes, any tips on staying calm and focusing? What are effective ways to learn how to program? Are there standard exercises for programming? (I feel solving problems helps my understanding immensely)

Ultimately I feel like I am in a never ending tunnel that leads me no where. It feels like I am just completely unable to pursue anything in the world of programming, yet it is something I want to do very much.

Thanks.

+9  A: 

Any language will do for learning the absolute basics. Python is considered very good for beginners and you should stick with that for now. If you want to end up doing iPhone development, you'll probably switch to Objective-C at some point.

First step, simply learn the three basic ways in which code is executed (apologies if you already know this, I'm assuming you're an absolute newcomer to programming as your question indicates):

  • sequence, one thing after another.
  • selection, choosing to do one of many things.
  • iteration, doing one thing over and over.

Then find a program that combines all three such as a program Celsius to Fahrenheit converter which also lists if water would be frozen at that temperature:

Celsius  Fahrenheit  WaterState
-------  ----------  ----------
    60-         76-  ice
    50-         58-  ice
    40-         40-  ice
    30-         22-  ice
    20-          4-  ice
    10-         14   ice
     0          32   ice
    10          50   liquid
    20          68   liquid
    30          86   liquid
    40         104   liquid
    50         122   liquid
    60         140   liquid
    70         158   liquid
    80         176   liquid
    90         194   liquid
   100         212   gas

Once you've mastered that (or something similar), move onto something more complicated. The best bet is to find your own itch and scratch it, trying to create something that will be useful to you (ask yourself what your interests are: cute kittens, heavy metal, torture implements of the early fifteenth century; then think of something that will aid you in that). That way, you're more likely to see it through to the end.

The code I used to produce that is below and could no doubt be improved but it's fine for entry-level. Don't look at it until you've tried it yourself since you'll get a much better sense of achievement from doing your own work. Think of it as something you could compare your solution to.

And as @deceze points out in a comment, learn the best places to find information on your language of choice: the documentation followed in a very close second place by Stack Overflow itself :-)

print "Celsius  Fahrenheit  WaterState"
print "-------  ----------  ----------"
for cels in range(-60,110,10):
    if cels < 0:
            cels2 = "%6d-"%(-cels)
    else:
            cels2 = "%6d "%(cels)

    fahren = 9 * cels / 5 + 32
    if fahren < 0:
            fahren2 = "%9d-"%(-fahren)
    else:
            fahren2 = "%9d "%(fahren)

    if cels <= 0:
            state = "ice"
    else:
            if cels < 100:
                    state = "liquid"
            else:
                    state = "gas"

    print "%s  %s  %s"%(cels2,fahren2,state)
paxdiablo
+1 I'd add to that *learn where to find information about your language of choice*, in this case learn how to read and search the Python documentation. Especially in the beginning you'll have many "how do I do this" moments, and finding the answer in the documentation is the moment when you're growing a little.
deceze
Apple's currency converter sample is a nice introduction to Objective-C/Cocoa. You could turn the currency converter into paxdiablo's temperature converter as exercise.http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ObjCTutorial/01Introduction/01Introduction.html
weichsel
Kimvais
+1  A: 

I think starting with a language such as python is quite a good idea. It has the advantage of being much less gnarly than something such as C or C++, gives you a quick edit test cycle so you very quickly see your mistakes, and it's widely used so there's plenty of wisdom out there. Also it's not your ultimate target, so you won't get sucked into being over ambitious and try to write the great apps you want to write before you have mastered programming.

That leads to my second point, it's really important to realise that there is a lot to learn and much of it is incremental, that is, things build. You learn one thing, and that enables you to do something else. You can't learn the later stuff first! So you must be patient, take whatever books you are using and do the examples. All (or at least most) of the examples. You are not just learning the details of the language you are learning ways of thinking and especially how to figure out the problems, why things don't work.

So my suggestion fo dealing with the lack of concentration is that you may need to spend more time doing. Don't expect to read too much before you try some doing.

Have fun!

djna
+1 for incremental approach
jbochi
+3  A: 

Personally I find the problem with learning how to program is finding a book that doesn't assume prior knowledge. So for example, you pick up a book like 'Beginning iPhone Programming' and discover it's not really for beginners because it assumes that you know about objects etc, or will say "...assume a knowledge in an OO language like Java, etc", and early examples have non-intuitive syntax:

int main (int argc, const char * argv[])

(Try explaining what the * means to someone who is a total beginner).

This is not a criticism of such books but it does mean that a beginner program does need to start off with something like Python at least to give them a foundation

I also strongly text recommend this book though (especially if the end goal is iPhone):

The Object-Orientated Thought Process

This book is really excellent because it teaches how to think about Objects without actually focussing on computer language (it does give examples in Java, C# etc ) but the focus of the book is as if you know none of these things but want to understand objects conceptually - I wish more books were like this.

Gazzer
A: 

Choose a language that is easy to read not easy to write. Programmers are lazy and pressed for time and many cannot type so they tend to invent languages with shorthand syntax making the code difficult to read.

Pascal and Basic were designed as learning languages with clean easy to read syntax. Later they grew to become fully fledged languages. There are both Basic and Pascal versions and compilers that you can use to write Operating Systems!

COBOL reads like the newspaper and although I have never written a single line of COBOL, I learned a lot about computing just by reading COBOL code.

So choose any language that is easy to read. Once you have learned programming then learning a second language is easy.

Square Rig Master
+2  A: 

It looks like you're a young guy, maybe in college? If programming is something you are really interested in, take a couple of computer science classes and see what you think.

itscaleb
A: 

First, learning how to program should be your interest. Second, Read, read and read(about programming language of your interest). Third, Practice what you have read/learned. Fourth, Apply! and Last but not the least, learn from others. Happy programming.

KG Sosa
A: 

I recently taught myself Objective-C/Cocoa (the language and libraries for OS X and iPhone development). I've been programming for six or seven years, I've learned multiple languages, and I found Cocoa really tough at first. It's all about using the Cocoa libraries and figuring out how to use them for what you want to do.

Developing GUI-based applications is a bit difficult, and I don't recommend it as a starting point.

I think Python is a great learning language. Start there, doing simple programs without graphical interfaces. Since Python is often used as a teaching language, there are probably lots of resources and text books you can use. If you're interested in games, but not ready for GUI programming yet, think of text-based games you can make. I did a text-based Yahtzee in high school, for example.

Once you're comfortable with Python, try making a simple graphical game. (I've used pygame before and it was a good experience.) It will probably be hard, but rewarding.

Then consider moving to Objective-C and Cocoa. There are lots of great books and tutorials for you, but they assume prior programming knowledge. You might have to read up on C a little bit, because Objective-C is obviously based on C. You'll need to know about memory management, which Python won't teach you.

Remember that this will take time. It took me years to become a confident programmer, and I still have a lot to learn. Unless you're making this your full-time job, it will take a while. Be patient, and have fun!

Also remember that you don't need a degree in CS to be a good programmer. I have a friend who majored in Anthropology in college and is now working as a full-time software developer at a major company because he taught himself a thing or two in his spare time.

Ellie P.
+33  A: 

I would like to know the best methods for learning to program

A. Read, practice and experiment

My problem is that I understand what I read but I can't apply my knowledge to anything.

A. Start with simple programs first. Your first program can be to print something on the screen. The next program can be a loop to print numbers from 1 to 100. And so on. Don't try to write large programs at the beginning itself.

Should I stick with Python? (is there a better language I should be learning?) Where can I learn programming theory?

A. No problem with sticking to Python. Its a good language for beginners. You can learn theory using good programming books or on the Internet.

I get very hyper when reading my book sometimes, any tips on staying calm and focusing?

A. You may be very exited to develop games and want to do it ASAP. But not able to do so in a small time makes you hyper. Please understand that it may take you several weeks to learn programming. Have patience. If you make haste, you may fail and eventually get frustrated and give up!

Ultimately I feel like I am in a never ending tunnel that leads me no where. It feels like I am just completely unable to pursue anything in the world of programming, yet it is something I want to do very much.

A. Reading the above lines, tells me that you are passionate about programming. I bet that you have the ability to be the best programmer. The problem seems that you are in a hurry to develop your first game! :) Once again, please be patient. If you are not patient, frustration of failure will make you give up and you may never be able to write your own games.

I had written the below article some time back. Read it.

If you are not so good at programming you might have surely asked this question. And if you are a good programmer you might have surely faced this question.

The question I am talking about is, "How can I learn programming?"

This article is an attempt to answer this question. I have written ten points which I think would be helpful for being a programmer. Here they go.

1. Improve your typing speed

Surprising? But this is the most important point. There is no way in which you can convert your thoughts directly into a program. You have to key in your code using a keyboard. If you are really slow at typing, you may get irritated when writing large programs.

Spend at least 30 minutes a day to practice typing. There are several free typing tutors available on the Internet which are worth trying.

2. Get access to a computer

You are not going to be a programmer just by reading programming books. Typing the programs, compiling and executing them is a must.

If you don't have a computer at home, get one. You don't need a brand new Dual Core processor to learn programming. Even an old machine would do for a beginner. If you can't afford that too, at least get access to a computer at your school, college, a library or at your friends place where you can practice programming.

3. Don't just read... Do it!

Don't just keep reading programming books and articles. Mere reading will not help you learn much. Type the programs, compile and execute them. In that way you will be able to remember the things better.

4. Study the code written by other programmers

No matter how intelligent you are, you cannot be the best at everything. You may be writing great programs. But somebody else may write some things better than you.

So even if you think that you have written the best program in the world, its worth checking how others have written the same thing. You can learn a lot from other's programming styles and tricks!

5. Experiment a lot

Don't just stick to whatever the books say or your teachers or friends say. Experiment! Try your own things. Try writing the same program in different ways.

Try whatever strikes your mind. Sometimes things which seem to be foolish will do the job just right! Sometimes your experiments will not give the results you expected, but they may result into something which you thought would never happen! If you get such results, try finding the reason behind them.

6. Be a self learner

Leave behind the habit of being spoon fed. Start learning yourself. There is wide range of content available on the Internet. There are thousands of books in the library waiting to be read. Go, pick couple of them.

If you expect others to teach you everything then programming in not for you. Technology is changing fast. You have to stay updated yourself.

7. Learn from other programmers

This point may seem contradictory to the previous one, but it isn't. I don't mean to say that you should learn programming from other programmers. What I mean to say is learn their programming style. Learn their habits. Try to find out why they are good programmers. Adopt some of their characteristics which you think will help you.

8. Teach someone

Teachers say this often, "You only learn when you teach." Agreed to a large extent.

After you learn something, teach it to someone who wants to learn it. When you teach someone, you will be asked questions. Finding the answers to those questions will grow your knowledge.

9. Think 100 times before blaming the compiler!

I have seen many newbies blaming the complier for errors. They claim their program to be correct and say that the compiler is producing wrong errors. I tell you, in most of the cases (rather in almost every case) it is the programmers fault. My advice is, please think 100 times before you blame the compiler.

10. Be patient and keep practicing

Have patience. You are not going to be a programming expert in a day or two. It takes time to build your knowledge and skills.

Sincerely keep doing your job of practicing, experimenting, learning and teaching. Don't give up!

Madhu
*"it may take you several weeks to learn programming."* it actually takes years.
just somebody
Yes, I understand. But if you are really passionate you can learn the basics in few weeks. Depends from person to person. (I am a self-learned programmer and I started learning QBASIC when I was 9. I am 23 now)
Madhu
11. drink coffee. NOW
johnnietheblack
@johnnietheblack: Thanks! :)
Madhu
And I'm assuming, @Madhu, that you have mastered QBASIC by now, yes? :-)
paxdiablo
@paxdiablo: LOL!! Yes, I did that long back. Don't use it anymore... :)
Madhu
I would extend 9 by saying "Search the Internet 100 times before asking a question". Since it will also make you a better programmer if you can help yourself, instead of creating a dozen questions on Stackoverflow each day.
Ivo Wetzel
"Think 100 times before blaming the compiler!". After 10 years a lot of people still blame the compiler/OS for bugs :)
Daniel Benedykt
A: 

The python website has an interesting tutorial. This is how I learned Python for the first time (in the summer between my first and second years at university). Granted, I had SOME programming experience from back in high school, but I didn't remember any of it when I was learning python.

Python is very easy to learn and learning python teaches you to think like a programmer. At first, you will have issues with not knowing how to apply things that you have learned. This is because what you have learned upto that point would be very simple (things like lists and other data structures). But once you've learned those, the applications become apparent in the following examples and you will soon fall in love with programming and python.

Also, this might be a resource of use to you.

Further, you might want to consider getting a proper IDE for your development in python, so for that I would direct you to this question on SO.

Hope this helps Good Luck

inspectorG4dget
+2  A: 

I started out with a specific application I wanted to create.

This helped me enormously, while I read about basic programming techniques I was constantly analysing where/whether each technique applied to what I was trying to achieve.

OK, this was a long time ago, but each time I've tried to learn a new language I found it particularly productive to have a small specific application that I wanted to create in that new language.

I would recommend that you define yourself a small application you wish to create, or pick an existing small app that you're familiar with and try to recreate it from scratch (e.g a simple calculator).

Python is a great language to start with, you can try so many things directly in the interpreter and see what result you will get.

Programming a GUI involves another level of understanding, I'd be tempted to start out creating my app to be command-line driven. When you've got the basics of getting the program to run properly from the command line, putting it into a GUI will be a lot of fun that offsets the pain a little.

Steve De Caux
I can't emphasise enough now important having a specific goal of the "I want a program to do thus and so..." is for learning, at any stage of one's career. Without a measurable goal you have no way to tell whether you are making progress.
Steve Gilham
+6  A: 

If you are not in a hurry, Teach Yourself Programming in Ten Years is the best answer that I have ever read to this question.

  • Get interested in programming, and do some because it is fun.
  • Talk to other programmers; read other programs.
  • Program. The best kind of learning is learning by doing.
  • If you want, put in four years at a college (or more at a graduate school).
  • Work on projects with other programmers. Be the best programmer on some projects; be the worst on some others.
  • Work on projects after other programmers. Be involved in understanding a program written by someone else.
  • Learn at least a half dozen programming languages. Include one language that supports class abstractions (like Java or C++), one that supports functional abstraction (like Lisp or ML), one that supports syntactic abstraction (like Lisp), one that supports declarative specifications (like Prolog or C++ templates), one that supports coroutines (like Icon or Scheme), and one that supports parallelism (like Sisal).
  • Remember that there is a "computer" in "computer science". Know how long it takes your computer to execute an instruction, fetch a word from memory (with and without a cache miss), read consecutive words from disk, and seek to a new location on disk.
  • Get involved in a language standardization effort.
  • Have the good sense to get off the language standardization effort as quickly as possible.

In a short term, I would say that Python is a good choice. One book that can help you learn how to program and how to apply your knowledge at the same time is Python Programming: An Introduction to Computer Science

jbochi
+1 Thought-provoking answer. Not sure how readily the original questioner will apply all the points, and after 30 years I'm only at 7/10 so feeling a bit depressed :-)
djna
+1 for the Python Book. Dr. Zelle is actually my professor and I started off programming using this book!
controlfreak123
+1  A: 

You got great answers up here already, but I will add my two cents to them. Programming is NOT something that you can just learn and do immediately. It requires a lot of commitments and experience. Hence, just go ahead with whatever you are doing and continue doing it. I personally believe that Python is a great language that covers a lot of different language features that you would see in various languages. However, remember that after all, computer languages are just languages like English, Spanish, etc. Knowing different languages does not make a good programmer; however, knowing what you want to do and how you want to do it can make you a good programmer. Just keep coding. Start with simple hello world to fibonacci sequences to some puzzles to more complex designs to more complex architectures, etc. Practice with Project Euler.

It's good to hear that you have great interest in programming.
Good Luck!

bLee
A: 

My mantra to "Learn any programming language is through Analogies" and develop small application or programs that you learn and finally integrate all the chunks into one big useful application .

Since you are learning python and apply your knowledge to anything , then i would suggest this website once finish learning python.

Python Challenge is a game in which each level can be solved by a bit of (Python) programming.

Hope this is helpful !

YetAnotherCoder
after the first couple of levels, you have to know some advanced stuff like regexp, I wouldn't recommend python challenge to programming beginners. Maybe Project Euler instead?
Gary
A: 

find a friend who is also interested in the same goal. together it is more fun, human feedback loop instant and you learn what software-development really is: "working in a team".

further learn infrastructure stuff along the line: source-control-systems (e.g. subversion), command-line (e.g. bash).

the IDE is also important. never the less start with basic tools (editor + compiler/interpreter). in my view beginners are always tempted and start to use full blown IDE from start on and have no clue about the 'behind the scenes'.

manuel aldana
+3  A: 

I think, forget about programming. Look at your life and prefer another way that makes you feel better. Programming should be your last chance :)

NetSide
+1  A: 

I'm not going to answer your questions directly, but rather would like to tell you my story, because I had quite similar experiences in the beginning.

I started programming when I was 12. Me and my friend loved video games and were curious about making our own ones. He heard somethin' of C++. So I went to the library, borrowed a book on it and read it through 5 times, until I noticed, that I didn't understand anything :-P

"My problem is that I understand what I read but I can't apply my knowledge to anything", You see, that is pretty normal in the beginning - so don't get frustrated by it.

I then started to learn easy languages like visual basic/blitz basic and slowly developed an understanding and mental model of computers (and programs).

Python sure isn't the wrong way to start. Keep it up! Show endurance!, and it will pay of!

I wish you all the best and much fun with programming.

Dave
A: 

Most of the answers above plus the following...

  1. Do what you love or at least enjoy. If you want to do a game, then do a game. Doing exercises for exercise sake won't help your motivation.

  2. Do something where you feel you are making progress in some fashion. I know this is a fuzzy statement, but if you are just spinning your wheels trying to work beyond your level that will also kill your motivation. If you are stuck in this loop, try something else. You should keep your goals realistic.

  3. Learning programming is a recursive task. In order to learn to program you need to program, but in order to program you need to know something. I find learning something out of books to be much this way. Books often don't help until you know enough to go back and get something out of the book. If a book frustrates you, put it down and pick it up later when you have learned more.

Some ideas...

If you are interested in games, try helping with an open source project rather than write one from scratch. Take an existing program and try to put your own special spin on it somewhere. You also might want to find a text based game (i.e. mud) that is recruiting developers. There are still tons of them out there believe it or not, and there is always someone recruiting. Some have horrible shlock code, and some have some pretty nice code engines.

Good luck.

Bill
A: 

Python for Software Design (How to Think Like a Computer Scientist) is aimed at beginner programmers learning with Python. Might be worth a look.

Paul D. Waite
A: 

Just make it fun !

Amazingly Scala might be the easiest language if you try Kojo

Łukasz Lew
A: 

The lowest barrier to entry for iPhone game development is Corona, it uses Lua which is very easy to learn, read, write and use. Even simpler syntax than Python in most cases.

fuzzy lollipop
+1  A: 

You want to write games for iPhone? Well, what are you doing messing around with Python? Download Xcode and start hacking away ffs!

Seriously, don't bother trying to "learn how to program". You'll get there eventually anyway. Instead focus on graphics hacks, color fading, moving pixels around, scrolling, displaying images...

Start with the 2d stuff first -- create a Snake game clone to get some idea about controlling input. Add more features to it (collision detection, food, walls). Write something akin to Pong which will give you a moment of clarity when you realize how easy you can implement the bounce! Add sound effects. Write an implementation of the Game of Life to get som kind of data structure insights. Add an CPU opponent to your Snake/Pong game, try to make it clever!

There are also lots of really cool 2d games tutorials on the net which is really fun to follow. But don't start there, explore the basics on your own, trying to have fun get some things moving on the screen!

Go now, young grasshopper, have fun!

Martin Wickman