Programming – the stuff you can’t learn from books

Posted by on Jul 03 2009, in Programming - the stuff you can’t learn from books, zegarkus

This is old post that was originally found here: http://zegarkus.com/2006/10/01/programming-the-stuff-you-cant-learn-from-books/


 

Programming is something you learn by doing. And doing over it again. And over yet again. It is not something you can master in 21 days. Which brings me to my point – its can be very difficult to learn even if you have good books to teach you. Now this is not to say learning from examples is bad. I’ve pretty much self taught everything I know about programming through examples. The problem is that examples are the end result – you do not see the process it took to get there.

When I started to teach myself python programming, I saw immediately why learning programming via example is somewhat flawed. The example shown in the book is usually a perfect working model – but its quite deceptive; it doesn’t show the numerious revisions and blood sweat and tears the programmer has put into the code. Large chunks of code may have beend added, substracted, tweak, abused and optimised during for the final result.

When learning python, I decided to write a little game for battle ship with a command line script. A very simple script got more and more complex as I continued to build it. This is the stuff they seldom show you computer books. Whenever I made a revision I saved the script with a number after it. Here is an example of this process with the total lines of code* after each effort:

  • bs.py lines of code: 88
  • battleship.py. lines of code: 175
  • battleship2.py. lines of code: 137
  • battleship3.py. lines of code: 149
  • battleship4.py. lines of code: 184
  • battleship5.py. lines of code: 177
  • battleship6.py. lines of code: 219
  • battleship7.py. lines of code: 187
  • battleship8.py. lines of code: 242
  • battleship9.py. lines of code: 237
  • battleship10.py. lines of code: 235
  • battleship11.py. lines of code: 250
  • battleship12.py. lines of code: 249
  • battleship13.py. lines of code: 266
  • battleship14.py. lines of code: 277
  • battleship15.py. lines of code: 286
  • battleship16.py. lines of code: 276
  • battleship17.py. lines of code: 289
  • battleship18.py. lines of code: 295
  • battleship19.py. lines of code: 308
  • battleship20.py. lines of code: 334
  • battleship21.py. lines of code: 363
  • battleship22.py. lines of code: 353
  • battleship23.py. lines of code: 362
  • battleship24.py. lines of code: 354

*I include all comments as lines of code here – though the lines might not do any actual work they keep me sane 🙂

As you can see the code grows, shrinks and grow again several times. You can examine the code by clicking on the hyperlinked filename. Don’t expect this to be world class code – hey I was learning python during this process! If a book (god forbid!) were to use my final script as an example, probably would not show evolutionary process of how I got there. This is just as important as the final product, you learn most of the real life stuff through this learning curve!