Macha

Programming Books

August 21, 2010 | categories: Programming

It used to be the case that when I wanted to learn more about programming, I would go down to the book store, buy a book about the language I was using and read it through. However, the problem with these books is that after a while, you only really want the last 5 or so chapters, detailing the bits of the standard library you are going to use. The language docs are usually a pretty good explanation of the syntax. You definitely don't need a full chapter devoted to if statements and loops, for the fiftieth time.

What you need on if statements after the first language is just a small paragraph like:

Python if statements are done like so:

if condition:
    doStuff()
elif other_condition:
    doOtherStuff()
else:
    doOtherOtherStuff()

Seven lines, not a whole chapter. Oh look, the language docs do that. Never mind then. Those chapters are now totally redundant. Spending €40+ for the last 5 chapters really doesn't make sense.

The other problem is one of quality. Several books promise to teach you everything about something, yet obviously fall far short of it. An extreme case can be seen in the two books I bought around 2-3 years ago, when I was first learning PHP.

1300 page long "Beginning PHP and MySQL", 200 page long "How to do everything with PHP & MySQL"

Which title do you think is more accurate?

Even apart from the amount of extra information in the Apress book, the quality of that information is far better. The smaller book doesn't even mention how to create a class. And it would have you believe that the only way to interact with a database is through the old mysql library, using functions like mysql_fetch_assoc(). Oh, and to really rub it in, it does actually mention MySQLi, but basically as a slightly faster version of the MySQL functions that needs to you put an i in your function calls, and nothing else. The example code in it always mixes code and markup, and then you wonder why PHP has such a bad reputation, when there are so many books like this floating around.

The problem is, many people will look at these books, and see the Apress book looking much more formal, and presume that's it's full of unnecessary detail. I did at first (hey, I was just starting out), which is why I initially bought the second book, then had to go back and buy the other one when I finished the first one, and realised I could of learned the same amount of stuff from 2 hours and an internet connection.

Of course, eventually, every programmer moves on from these books to more general ones about coding in general, rather than specific technologies and languages. The problem is, many book stores don't bother selling anything more advanced. And the only computer shop where I live, PC World, has an even more pathetic collection. So you have to wait ages for something to turn up. Or have someone recommend a book, and then buy it online. You can't browse through books, flicking through a chapter of each to see which looks better, on eBay or Amazon unfortunately, which rather limits the options for just looking around for something good.

Moving on to better books, like this one.

The first proper programming book I got was Code Complete, second edition, which I bought roughly a year ago. I'd heard a few people recommend it before, but hadn't went to buy it. I was amazed when one day, among all the copies of Excel for Dummies and iPhone for Seniors, there was a copy of Code Complete in the book store. I presume someone had ordered it in, and the store had just got a few of them, because it's sadly not the kind of book they usually get. I suppose they rather books that don't require the customer to have some knowledge already. (Which is odd, because surely they'd be able to sell two books with an offer like "Buy this book to learn how to program, and this book to learn how to program better.")

Unfortunately, even when you know what book you want, the book stores don't do themselves any favours. Around this February, I had €30 in book vouchers for the local bookstore left from Christmas, and decided to buy Design Patterns with them. I had the PDF version, but I still read best from dead trees, so I had a look. Unsurprisingly, they didn't have it there, as most of their books are of the Language x for dummies/Buzzword y in 24 hours variety. Oh, and they have Code Complete again as well, but I already have that. So, as I had expected, they would need to order it in. I had checked beforehand, and the book was €30 delivered from Amazon. I expected it might be maybe €40 in the bookshop, cheaper once you factored in the vouchers I already had. It wasn't €40. It was €82. I don't know what planet they are on in the bookstore, but needless to say it's led to Amazon being €30 richer.

A welcome development is the trend towards free online books. Examples such as Dive Into Python, Programming Ruby, Dive into HTML5 and Real World Haskell do help with their respective languages. And the fact that they tend to be more concise than the usual books on the shelf (I know they come on dead trees too, but nowhere near me sells any of them) also makes them more useful, even despite my preference for reading from a physical book.

First projects

February 05, 2010 | categories: Programming

One of my online friends has started learning programming in C++ and Python a few months ago. While he seems fairly competent in it, he was complaining that he feels he hasn't acheived anything worthwhile in it. He said he just can't think of anything useful to make.

This reminded me of when I was starting out (and again when I was starting out with Javascript, and again with PHP, and again with... you get the picture). Like him, I also struggled to think of something to make. My first trivial program was a Java clock applet when I was 13. I saw one on another site and decided to make one for my own. My first non-trivial program was a social network, written in PHP when I was 15. Two years to think of an decent idea that I could keep working on until completion.

I think the problem with beginners projects by self-learners is one of overreaching. I've certainly done it a lot. If they try to write a social network, they want to write Facebook. If they write a forum, they want to write vBulletin. If they write a game, they want to write Fallout 3. All of these were written over a significant amount of time by large groups of people.

My advice is this: Start small. Reduce whatever you plan to build to it's basics. A social network can be reduced to users who can add friends, edit profiles and leave comments on other's profiles. A forum can be reduced to users creating threads and posts. A game can be something like Pacman. Implement these basics. When you have them done, you will have enough motivation to get the rest of the stuff done (login, logout, etc.). While you can't assume designing a successful product is as simple, as the linked blog post shows, designing a beginners project to practice your coding is easier than designing a product to base a business around.

Despite not being quite that simple, many successful products are based on simplicity. Compare Twitter to Facebook, punbb to vbulletin, Google Chrome to Firefox. Simple and fully-featured are two equally valid design strategies (although I tend to favour simple products myself), but simple ones are much easier to get going.

Once you have your basic program written, you can then add features to it. You could add image uploads to your social network, bbcode to your forum or extra enemies to your game. Further again, you can add groups to your social network, tagging to your forum, and new level types to the game. Since you already have a working base to start from, it's much easier to look at it feature by feature, instead of waiting ages until you have anything that works.

Learning C++

August 26, 2009 | categories: Programming

As usual, I'm falling behind on blogging. One of the reasons for that is I am currently learning C++.

A while back, I had a brief exploration into C++, and learnt the basic syntax, then moved on and didn't do anything related to it for 6 months. The majority of my programming has been done in Javascript, Java or PHP, though I have looked into other languages. Since Java and C++ are quite similar in some respects, and I did learn the basics beforehand, I'm not starting from scratch completely, though in some ways it would be beneficial if I was. An example is this:

int array[somevar]

Perfectly legal, and quite common in Java. In C++, this shouldn't work. Except it did for me, because it is a g++ extension. Someone with no programming experience would not have tried this. This is something I hadn't expected. I had expected C++ to be more like Java, and PHP where there was one standard of the language (and the only differences were between new and old), but it seems, like Javascript, there are a few variations per implementation.

Another thing that surprised me was the small size of the standard library. Compared to the Java API, and the .NET Framework, the C++ Standard Library is tiny. No GUI code, no threads, no networking functions.

The final hurdle I encountered is there is so little information about C++ online. On the one hand, I should of expected this, as the origins of C++ predate the internet, and it's not a web language, but it means I have a lot of difficulty finding material. My local book store has only 3 shelves of computer books, with the programming catalogue nearly entirely taken up by C#, Java and PHP. As well as that, the books I found in the library are quite old and mostly aimed at people coming from C or Pascal, or a variety of other older languages.

I'm wondering what other people's experience of learning C++ is.