9 Jul 2004 gnutizen   » (Journeyer)

Ah, so Advogato is back up.

I did get my hands on a Linux - I brought back one of my machines and installed Debian on it via 6 or 7 3.5" floppies and an ethernet connection to ADSL. And I ran Gnutizen on it. No major changes for Linux other than an #include <byteswap.h> for endian stuff.

I was reading the Linux Coding Style document that Linus was just mentioning on the Linux kernel mailing list. Gnutizen is my first big C project so I find such things helpful. He says comments should be put at the head of a function explaining what it does (not how it does it - he says that should be obvious from the code). I went through my code and removed most comments inside functions and put them at the head where I described what the function did.

The really big impact was his advice on functions - he says

Functions should be short and sweet, and do just one thing. They should fit on one or two screenfuls of text (the ISO/ANSI screen size is 80x24, as we all know), and do one thing and do that well.
Some of my functions were longer than 48 lines - a lot more, and unnecessarily so. I went through and broke up many of my longer functions after reading this, which took a while. In the section on functions he talks about variables.

Another measure of the function is the number of local variables. They shouldn't exceed 5-10, or you're doing something wrong. Re-think the function, and split it into smaller pieces. A human brain can generally easily keep track of about 7 different things, anything more and it gets confused. You know you're brilliant, but maybe you'd like to understand what you did 2 weeks from now.

Breaking down the functions helped me lose these variables, but I am trying to trim the functions down to 7, or at least 10 local variables. And not have global variables unless they're necessary.

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!