The life of a new C programmer

For the last few months, I’ve been striving to refresh old tech skills and maybe learn some new ones. I’ve been in the IT industry, first as a student, then full time since 1997. That’s not nearly as long as some people, but enough that I feel reasonably experienced. However, due to the nature of work I do now, sometimes the raw technical skills have fallen into disuse.

So, lately, I started buying a lot of computer books (good recommendations by colleagues), and reading through basics. Some of the skills I learned years ago, and when I go back and read now, it’s interesting to see how much more sense the books make.

A good example of this is the C programming language, and the classic “K & R” book, C Programming Language. This book is written by Brian W. Kernighan and Dennis M. Ritchie, who invented the C programming language, and also were instrumental in UNIX as well. The book has been a mainstay among C programmers for many years, but in the past when I read the book, I just couldn’t make sense of it once I got about half-way. As soon as pointers came into play, I got lost. Pointers are necessary for more advanced programming, but also can break things easily if you don’t know the syntax well.

For some reason, I was at work last week, and found a copy of the K&R book (someone had bought for work, even though we don’t use C for our applications) and was flipping through it, bored. What amazed me is that I hadn’t read the book for 3-4 years, but much of the content in there made more sense than before. Having had experience in my current job with complex applications, I found that much of what the K&R book taught made more sense.

So, then, I decided to borrow the book and go through the exercises and see if I could do better this time. Almost daily, I fire up my virtual copy of FreeBSD, and try out something new based on what the book teaches. Here’s a super-basic program I wrote to demonstrate and play around with C pointers:

/* hello.c - Say hello */

#include

int main(void)
{
    char s[] = "Hi there";
    char *p;

    int x = 1;
    int *ip;

    /* Assign *ip to address of x */
    ip = &x;

    /* Technically this is p = &s[0] */
    p = s;

    printf("%s, number %d.\n", p, *ip);
    return(0);
}

The program is stupid and contrived, but it worked. That gave me more confidence, so I started doing slightly more advanced test programs. In the past when I read the K&R book, I was impatient (and inexperienced), and I didn’t read carefully. The K&R book is extremely short and dense, and you have to re-read sections (and sentences) a few times to get what they’re saying. Once you understand though, it helps streamline program design a lot.

Since then I am getting much more comfortable with pointers, arrays of pointers, use of malloc() and free() and other things I couldn’t do before. It’s a far, far cry from writing device drivers, or hacking kernel code, but it’s nice to see I am further along C programming than I was in the past, and in relatively short time. Also reading the man pages on C functions actually makes sense to me now. I couldn’t understand any of it in the past.

Although we don’t use C at work, one of the big reasons I wanted to learn it is that I feel that if I want to be a better programmer, I felt I should start with a more challenging, low-level language like C, rather than something like Perl or Python that obscures things. I do know some Perl, but I never really mastered it, and I realize that a big part of that is because I never learned to think like a programmer.

It is an important lesson in patience too. In the past, I wanted to skim through the book, and start writing “cool” things like shell programs and network apps. But to do that kind of work, you really need to take your time and ground yourself in the basics, learn good programming practices, and just re-read the same parts over until you really get it.*

So anyways, it’s nice to see an “old” system admin learn new tricks. :D

Namuamidabu


Be the first to like this post.

2 Comments on “The life of a new C programmer”

  1. Jeannie says:

    I’m so rusty I think I’d have to start all over again. That’s the problem with the I.T. business- use it or lose it.

    BTW, is today or tomorrow your big day? :D Did you get my e-card? Sometimes I don’t get a confirmation back from Hallmark.

  2. Gerald Ford says:

    Jeannie: no kidding. I knew some skills a lot better than I do now only because I used them so much. Recently, I had met someone who was quite a bit older, and was now a driving instructor, where before he was a computer technician. His problem was that he allowed himself to get comfortable, and then rusty, so when he lost his job, he couldn’t find a new one. That’s the IT industry for ‘ya. As for the card, I replied by email. :)


Leave a Reply

Gravatar
WordPress.com Logo
Twitter picture

You are commenting using your
Twitter account. (Log Out)

Facebook photo

You are commenting using your
Facebook account. (Log Out)

Connecting to %s