Programming books

I meet a lot of people who claim that they want to learn how to program. That’s really great, but why they tell me this instead of just getting on with it, is beyond me. The follow-up is usually a question about which programming books I recommend. Since I get asked this with annoying regularity, I will post my recommendations here for everybody to read.

The one most important programming book you can ever read is K&R’s classic “The C Programming Language”. I could end it all here, but with only one book it wouldn’t be much of a list, would it? So I’m going to add one other book, and that is Jonathan Bartlett’s not-quite-as-good-but-still-excellent “Programming from the Ground Up”.

Any of those two books should give you a solid foundation in programming. After that, you don’t need books. You need to download and mess around with code.

Published in: on 2006.11.10 at 13:15  Leave a Comment  

Ruby weekend

I had a really great weekend. We had lights, and because of the rains I couldn’t really go anywhere. So I stayed at home and programmed.

I’ve been working on a forum server lately. My idea is to create a forum application that does not run in the browser. Well, point of correction: you can (or will be able to) a front-end that runs in a browser. But, as my friends know, I really don’t like applications that run in a document reader. So I intend to write a client in Qt4.

So far the server allows you to manage members and forums. It also does session management. You can’t create threads or write posts quite yet, but I’m getting there. I’m currently using XML-RPC for client/server communication and PostgreSQL as the database backend. Once the server is working I can think about abstracting the database layer.

One other thing I’ve been working on for quite some time now is a project I’ve simply called “Source Lab”. As most programmers, I’ve written a large number of small programs, or maybe I should call them code snippets, usually to test new features. Since I always used to keep these snippets in obscure directories under ~/tmp, they tend to get lost everytime I do a major clean-up.

I wanted to make sure all my small programs and snippets don’t get lost, so I created Source Lab. My first and currently only Source Lab is the Ruby Source Lab. It’s started off a just a collection of Ruby scripts organized in directories. Then I got the idea to have a system for navigation through the mess. So I started creating HTML documents.

But, being lazy, all the typing quickly got on my nerves. So I wrote some more Ruby, this time to help me manage my documents. I wanted to insert my Ruby scripts in the HTML pages I created, and of course I wanted them to be syntax highlighted and line-numbered. I also wanted to be able to capture the output of running the programs, and stick that in the pages as well. In many cases the programs are interactive, that is, the program will prompt the user to enter some information.

Thanks to Ruby, and various other tools, such as GNU source-highlight, this turned out to be a breeze. For interactive scripts I just use Ruby’s PTY module, and I managed to create a generic script that seems to work well so far. Now all I have to do is create a small HTML skeleton, with macros at the places where I want to insert a Ruby script or command output, and the make utility will generate all the pages for me.

One other thing I managed to do this weekend was to compile the Qt4 bindings for Ruby. Haven’t had a chance to play around with them much yet, but at least the samples ran well. Hopefully, I’ll get some time during the week to start tinkering with Qt4 in Ruby!

Published in: on 2006.09.11 at 08:02  Leave a Comment  

Multi-column constraints

Imagine that you have a table in which two columns together form a constraint. For example, you have a category table that has a reference to a section (a different table) and a name. Now, you want that category names should be unique within a section. You can insert any section multiple times, and you can use any name multiple times. But you can not have insert the same section and name multiple times.

How do you about it? Simple, use constraints on a group of columns, of course. It’s just that I didn’t have a clue that this worked until today. I had seen something like UNIQUE(a, b) some time back, but I thought it was just a short-hand for setting unique constraints on multiple columns in one go.

Well, I was wrong. It actually sets up a constraint on the columns as a group. That is so cool! Since my database server assures that I cannot insert a duplicate name within a section, I don’t have write loads of code to do it. In fact, I can trim down my code a bit this evening.

I think I am just about the only person in the whole world who didn’t know about this already. Of course, if I had taken my time to RTFM, I would also have known..

Published in: on 2006.08.31 at 16:04  Leave a Comment  

Ruby vs. Python == WAR!

Now that I have your attention..

There are an increasing number of “Ruby is better than Python” and “Python is better than Ruby” posts all over the Internet. It reminds me of the old KDE vs. Gnome, Vi vs. Emacs, Amiga vs. Atari, C64 vs. Spectrum and many other flamewars of days gone by. I wonder why so many people find it so necessary to criticize things they don’t like. Because at the end of it all, that’s all it is: matters of opinion.

I personally prefer Ruby over Python. But at least I know it’s a personal bias. I spent many years with Perl, and Ruby just feels right for me. But I also love Python. I do program in Python as well, and for certain types of problems I think Python may be a better solution than Ruby, at least for me.

There are good Python programmers who are building excellent solutions in their language of choice. There are good Ruby programmers solving interesting problems in their language of choice. So obviously, neither language is “flawed”, although claims are made from both camps about the “other language” being just that.

To the Ruby crowd: so Python’s OO is “bolted-on” is it? Okay, even if we assume that is true, who cares? The fact is that people are using Python’s OO to do great stuff, bolted-on or not. You don’t like indentation being a part of the syntax? Many people do like it that way. And there is a rationale behind it. To tell you the truth, I’ve never really had a problem with it. Vim auto-indents very well, so I usually don’t worry about it.

To the Python crowd: you don’t like $_? You’re not forced to use it, and many people don’t. You think Ruby allows you to write messy code? Sure it does, but it allows you to write clean code as well. It all depends on the skills of the individual programmer.

If you really want to show off what a great programming language you are using, then use it to build good solutions to interesting problems. Constantly complaining about how some other language is less pure, more difficult, less maintainable, less readable doesn’t really say much about the benefits of your own choice.

Published in: on 2006.08.31 at 12:05  Comments (2)