c · programming · learning

C's not so bad

So I’m learning C using Zed Shaw’s Learn C The Hard Way. I’m enjoying it immensely. I feel like I’m getting and understanding C. A while back I learned and worked with C++ for a window manager project. It worked, and I thought it was easier than what C would have been. Eventually I ran into problems I didn’t know how to solve, I was getting a segfault, seemingly at random. I never was able to track it down. I, to my knowledge, wasn’t doing any thing funny. But, I couldn’t fix it, and I had other things I wanted to work on. So I dropped it. Fast forward to now, I’ve learned Go. Go is wonderful. It’s simple, I grasped pretty much all of the language in about a week. The other thing I like about Go is that it’s compiled. There’s just something wonderful for me when I write a program and it compiles into a binary that I can just run. No interpreters, VMs, bytecode, JITs, nothing. Believe it or not, that was what first drew me to C++. Someday I hope to be a systems programmer. C is the language of choice for systems programming. One day, I hope Go will replace it in much of the places where it isn’t quite needed, but C will not die, at least for a long time. Which is why I’m learning it. And C’s not too bad. Yeah, Python, Go, and others make it much easier and shorter to do things. C isn’t as hard as it seems. It appears as an impenetrable fortress of arcane malloc calls interspersed among pointer arithmetic with a few macros thrown in for good measure. But as you get into it, you start to see that C is actually quite simple. Learning that you could use pointers and arrays interchangeably was a revelation. Seeing that pointers were just a different way to get at a block of memory made them a lot less scary. I discovered that calloc() and realloc() made it a sinch to handle creating re-sizing arrays. Yes, lang X does it automatically, but tinkering with the actual steps that do it was exhilarating. I also understand better what I’m doing with memory now. I can get something useful out of valgrind now. I can find and fix memory leaks. I’ll readily admit I haven’t written a real program in C yet, but I’m getting there. Try C, it’s not as hard as it looks. Re-sizing an array isn’t hard either. Give it a go!

Published:
comments powered by Disqus