Hey everyone!
Recently, I decided to learn to use the C programming language. I had a few reasons for doing so:
- A lot of very good programmers say that learning C will help you be a better programmer
- While it is not used as much as it once was, it is still a very significant language, especially used in things that touch hardware like drivers and kernels.
- It is significant historically because of its heavy use in Unix, Linux and BSD.
- It is actually a rather small language, so learning the basics can be done rather quickly. This one is pretty significant for me right now, as my second daughter was just born around 2 weeks ago.
Learning the Language
First, I looked up the best way to learn C. Keep in mind, when I was in school I did learn and use C++ (although it has been a good 5 years since I have used it) and I do use C# in my work every day. As a result, I already am fairly familiar with the syntax.
I just did a search on DuckDuckGo for places to learn C, and I found learn-c.org. This course is constructed primarily for people who already know how to program, and it quite nice. It will teach a concept like pointers, and then have you do a little exercise so you can try it out online. This course could easily be completed in an afternoon if not less, but because of my new daughter, this course took me about a week.
Trying it out
I wanted to try out something simple with C. I follow a guy named John Cricket on Twitter who runs a website called CodingChallenges. These are nice because they are somewhat guided, but not so much that the answers are spoiled. If you do need additional help, you can search GitHub or GitLab and you might even find people who are using the same language as you to solve these challenges.
The project I just finished today was a replacement for the Unix command line utility wc. At first, I was able to do pretty well, but due to it being a new language for me, I started to have some problems when dealing with āwide charactersā and reading from standard input. I eventually found a GitHub repo of someone who goes my ShellMonk who also solved it in C, and that helped. In the end, I also compared how I had solved problems with how they solved problems. If you want to see the repo for my solution you can see it here. I have also credited ShellMonk, as in the end my solution and their solution look almost exactly the same.
Overall, this project was great. No only did I have to learn how to read options, filenames, open a file and deal with standard input, but I also had to make extensive use of Cās implementation of strings. It was a great first project to learn C.
My Thoughts
C is a bit of a strange language. Many things that are hard in C or at least take some thought are taken for granted in newer languages. This is good and bad, of course. C is more efficient in terms of computer resources than those languages, but it requires more effort from the programmer in exchange. Also, in terms of memory management, C can do many things are impossible or hard in these newer languages. Which is why C is still used for applications that need efficiency over everything, like the Linux kernel.
I have heard some people recently say that everyone who learns programming should do so first with C or C++. I can definitely see where they are coming from. Those languages are very low level, and having some knowledge of them is very helpful in the long run. However, since these languages are also harder to use than many newer languages, it also threatens to scare some people away from programming. In the end, I would say learning these languages should happen after a person learns a first, newer language, to get their feet wet.
Where next?
When I have time, I might try a few more coding challenges with C. I still havenāt decided if I even really like programming in the language.
I also plan to take this course that will help with low-level programming in C.