Tuesday, December 4, 2012

Learning to Program

This last year I have finally learned to program, but I have been interested in leaning to program for years and have tried getting started several times and failed. Here's a short summary of the road, that eventually lead me to be able to write my own Android game from scratch. I hope it might help anyone reading this to get motivated and maybe avoid a few pitfalls.


First Brush with Code


Some ten years ago I first got my first real contact with programming when I started designing and writing homepages with two school friends. We were of course working in some very static HTML back then and the most we saw of programming were a few mouse-over java scripts, that we didn't really understand but used anyway. But we felt very cool and sophisticated.

Boring Books and Tutorials


Several times over the following years I tried to pick up a book or read an introductory tutorial to programming. Here is what I always found.

A Character has a size of 1bite, signed it can have the values -128 to 127, unsigned it can have the values 0 to 255.
A Short Integer has a size of 2bytes, signed it can have the values 32768 to 32767, unsigned it can have the values 0 to 65535.
An Integer has the size of ... and on it went. It would then go into excruciating details about the fundamentals about how a CPU handled binary input or the history of Object Oriented Programming or something else equally unrelated for an aspiring programmer.

There are two very big flaws with this approach.
Firstly, as a person who can now actually write a decent program or game in Java I can tell you that when I sit down to program I really don't worry or care about any of this stuff. Yeah you have to know a bit about the different variable types, but most of the time you're really only using two or three of them and when you run into a situation where you need something else you just look them up.
As to how a CPU handles actual binary input; the theory is interesting to me as I'm a bit of a hardware geek as well. But it means absolutely nothing to me when writing code, I'm 50 layers of abstraction away from the hardware. The history of OOP is probably interesting and important if your writing a term paper on programming, but again, I don't care in the least when I'm writing code.
Secondly; it's boring! When you start out programming what you want is to learn of to create something cool and fun, and there is nothing that can kill your enthusiasm quicker than 50 pages of useless information and a Hello World example.

Working in IT


Nothing to do

Two years ago I got a job at IBM. For almost three months we had almost nothing to do other than sit at our desk and look busy, while we waited for our department to be set up. I got a bunch of new friends and we talked about games and I thought it might be fun to do a text base adventure game. I seriously though about doing it only as a Windows Shell script, but that quickly got to seem impossible. Then I tried to jump back into programming, choosing to look at both C++ and Python. Well I ran into the same issues as earlier, the books and tutorials started out with long explanations about really technical stuff that didn't really interest me when all I wanted to do was write a simple text based game. I managed to do a few more Hello World programs and then gave it up.

Scripting

We finally got started on our work. I had always been technical, but I learned so much the first year about everything from printer hardware to server software. But the biggest thing I picked up was probably scripting.
We had several scripts that developers had made to solve recurring issues, these were generally all written in Windows Shell or in VBScript. Any self respecting computer nerd who has used Windows will be familiar with some Windows Shell commands and I was as well, but I got considerable better. But I cast my love on VBScript. VBScript is extremely easy to work with and you can easily get a simple UI in the form of prompts and text fields for the user to fill out. It became a wonderful challenge to build little scripts, that could make our work easier and I had a whole production network to fiddle around with. I also became a big fan of pranking my fellow workers, by making their computers open strange links or talk to them or eject their DVD-drive.
All these things had one thing in common, they had very clear and easy to obtain results and rewards. Which is really what you need when you are trying to learn something new and difficult.

Making the Decision

Around a year ago I finally made the decisions that I wanted to become a programmer. It had become quite dull to do tech support, at some point there simply wasn't much reason or encouragement to learn more and I felt like I was beginning to stagnate.
It's difficult to say what was different about trying to learn programming this time compared to earlier. Part of it was without a doubt that I had written a bunch of scripts and learned a bunch of other things, so I simple understood a lot of the ideas better. But a larger part was a willingness to spent hours reading things I didn't understand in the belief that it would make sense down the road.

Learning to Program


This time around I decided to choose to learn Java. There were several reasons for this. Java is the main programming language for Android, which I did have a plan to program a game for. I'd also realized how many things were programmed in Java and how sought after good Java programmers are. And lastly Java was part of the same Programming family as C, C++ and C#, making it very easy to expand into those languages later on.

Now that the decision was made, I needed again to find some material to teach me to program. Here I made a mistake again. Rather than getting the basics down I went for a book about game programming. Which made sense to me because I wanted to write games so why should I start anywhere else, I didn't wanna do any more Hello World programs. The problem is that all books about game programming assumes that you know all the basics, which I did not. The book that I chose was:

Beginning Java SE 6 Game Programming

I worked through this entire book, and I was not too impressed. It might have been better if my Java fundamentals were more in order, but still I would guess that there are better books about Java programming.

I began realizing that I needed my fundamentals in order, so next I went as fundamental as it gets.

Sun Certified Programmer for Java 6 Study Guide

This is a good book for making sure you know everything about Java to pass your exams, but it is not a good beginner's book. I read the first few hundred pages of this understanding only a fraction. I'm pretty confident I could read through it now and have a good understanding. It might even be a bit less mind numbingly dull now that I know a bit more, but still, this is not a book I would recommend for actually learning to program.

I did a bunch more research into good books to learn Java and finally ended up choosing:

Head First Java

It hurt my soul a bit to buy this book, as I think this is possibly the worst cover I have ever seen, but it turned out to be a great purchase. The Head First series of books try to make it fun and challenging and engaging to learn something new and it really succeeds. Head First Java was the first book in the Head First series and the only one I have read. Some people say that it's the weakest of the Head First books, but I thought it was a breath of fresh air and can warmly recommend it.

I breezed through Head First Java in a few weeks and truly felt like I understood it all.

I was also introduced to Codecademy.com which is an awesome page to learn scripting and programming and I highly recommend it to anyone interested in learning programming. The thing that's great about Codecademy is that you get immediate positive reinforcement for learning all the little things that you have to get down to move on to the cool stuff.

I had now learned enough to start doing some small test games and programs, my first one was:

Pigeon Wars
(It played about as poorly as it looks)

I was also asked to build a program at work, I never finished it, but it forced me to learn to build a real UI with swing.


I then got the idea of a game where you were crawling up three jungle vines avoiding dangerous objects and creatures. My girlfriend thought it should be a little cute mouse crawling up the vines and Jungle Crawler was born.

Here is an early edition of the game, believe it or not, it looked even crappier than this in the beginning, but I can't find that first version.

Jungle Crawler Alpha

I was feeling pretty good about my programming prowess at this point and got started on the Android version. I thought that would be quite easy. It was not. There are quite a few things that are very different about programming for Android and I didn't know any of them. I tried to fake it and made some crappy tests, but I soon realized that I needed a book on Android game programming. I had a lot of problems finding a book I liked but ended up choosing:

Beginning Android Games

I really didn't like this book at first. I think tech books should be all about being accessible and possibly a bit entertaining to make it a bit fun to learn. The beginning of this book where Mario Zechner goes through a lot of the theory both of Android and games programming in general, is both boring and high and mighty at the same time. So I was quite frustrated, but when he actually got into the programming and example projects this book turned out to be a treasure trove. The examples are great and concise and the framework he set up, made perfect sense to me. I can definitely recommend this book as well, with the caveat that the beginning of the book is less than stellar.

And here is a picture of the final product, with it's name changed to Jungle Jumper, as a bit of alliteration makes everything better:

Jungle Jumper

Your Turn


I'm not a programming guru yet, but I feel like I've come a long way. I hope some people will get something out of reading a bit about my progression as a programmer. And maybe even feel inspired to get started yourself if you have a game programmer hidden away somewhere inside you.

If anyone has any questions or thinks it would be interesting to hear about any specific part of the development process or my learning process, please leave a comment below.

3 comments:

  1. Hey,
    Nice piece of information provided . I wanted to ask a question
    i am from Electronics background and the company i m placed in is an IT company as for now i have no other option i have to join this company only but the main problem is this that they work on java and i don't know anything about java. I want to learn java online so saw many videos and even searched and came across http://www.wiziq.com/course/12145-the-6-week-complete-java-primer-with-training-certificate but i dont know how it is going to work for me. If anybody has taken this course please let me know..

    ReplyDelete
    Replies
    1. Hi John, I'm glad if you got anything out of my post. I don't know anything about the online course you found, but I would say that it is not necessary to take a course to learn the fundamentals of Java programming. I would simply buy a good primer, like Head First Java and spend a few hours a week on it. On top of that there is a lot of free learning resources online, so no need to take a paid course unless you want something very structured to keep your steam up.

      Delete
    2. This comment has been removed by a blog administrator.

      Delete