Home / Software / Learning c

Learning c

It’s pretty hard to have a good start with C. As a matter of fact, most experts advice AGAINST starting learning programming with C! Furthermore, most of C powers (the freedom of memory manipulation, the macro system, etc.) are scorned as bugs by people from more protective languages like Java or more type-rigid like ML. Thus, I set out to write this article to free C learners from such worries. No, this article is not about learning C, so it will not give you code or tutorial or the like. Instead, it is about how to learn C, with advices and analysis of an effective strategy to easily absorb this language.

Let’s start out with talking about what C is and why you should learn it. As well-known, C is a language developed by Dennis Ritchie in 1972. It is perceived as a pretty low-level language, especially suitable for developing systems, but also used to create just about everything. As a matter of fact, most, if not all, of the early programs are in C. Now, why should you learn such achaic things? First, because C is among the best languages ever created. The other, according to legend, is LISP. It is rumored that Great Programmers use only these two languages (although if this is possible is not checked. Oh, hey, they are Best Programmers, not you and I). Learning C would enlighten your mind with the knowledge about how your computer work. This, in turn, helps you to be a better programmer, if you are one, or use your computer more efficient, if you use one. Lastly, C is very simple. Thus, completely understanding of C can be get in the matter of months, contrast to, says, LISP or ML or Haskell, which may requires up to years (and C knowledge is more applicable, too). Thus, learning C is always worth your time.

To efficiently learn C, you need a correct platform. DON’T START WITH VISUAL STUDIO OR RAW WINDOWS. I mean it. Visual C++ is very very far from pure C/C++: it is over complicated, plagued with computer generated codes which are incomprehensible for new learners. I would recommend you to switch to a better platform such as GNU/Linux or BSD. However, I understand that it is not always possible. If you want Windows, at least please install Cywin. This will give you a standard and powerful compiler AND a POSIX-compliant environment to work with. Cywin (or GNU/Linux and BSD) will allow you to write code like copy from books, as well as simplify the use of command-line in early stages. GNU/Linux and BSD also provide more protection for your testing code (I have tried, and realize that I can access some illegal memory addresses in Windows, which is very dangerous). Thus, please, please either switch to a C-friendly (and user-friendly and safe) operating system like GNU/Linux or BSD, or install Cywin. Oh, Mac OS X should be fine, since it is actually Unix, which is extremely C-friendly.

You will need something to edit C code. You can write in Notepad, of course, but it is pretty cruel. So, if you like being beat up by people, keep Notepad. If you don’t (like me), you’d better choose something more powerful. You don’t have that much choices under Windows, but Notepad++ is a decent editor with syntax highlighter and such. Oh, Emacs (I will introduce later) can run under Windows, although not as smooth. Under GNU/Linux or BSD, you have three choices: Gedit/Kate, Emacs, and Vi/Vim. If you are a normal computer user who are curious about programming, Gedit/Kate should be sufficient. They will color syntaxes for you, as well as mark parentheses and braces. If you are, however, a programmers, you should learn either Emacs or VI/VIM. I personally prefer Emacs, for its excessive power. However, VI (or VIM, Vi IMprove) is also a powerful editor. Pick one, and study to use it to the fullest. That will aid you for your whole career.

Now, you have your environment set up (GNU/Linux or BSD or Windows+Cywin), your editor installed (Emacs or VI or VIM or Gedit/Kate or Notepad++), let’s discuss a good C book. Well, I don’t have much to say. There is something call C Bible, aka The C Programming Language. It is call THE C book. I believe that this book should be on every programmer’s bookshelves, as well as bookshelves of all intermediate computer users. Please buy it, and learn from it. Furthermore, you can always go online, to some forums, and ask for advices. There are many many tutorial online, too!

Before you sink your teeth to C, I do wish to give you some advices on the order of learning. I believe that you should start with writing small script, using only normal variables (aka variables without a sign before it when declared). Once you are comfortable with these, move onto struct, union, and enum. Once these are clear, array is the way to go. After arrays, you will want to do resizable arrays, aka simple pointers. After that, you will want to play with “real” pointers and manipulate your memory. This WILL produce at least several Segmentation Faults (you will know what it is when you are here :D), which is nothing to be scared of. After that, you will want to jump into function pointers. Along the way, you should try to utilize the power of macro to shorten your codes.

You see, C is very simple, as long as you have everything set up and ready to go. I still remember the “hello world” programs in C for Windows. It is CRUEL. The declaration for the program requires some incomprehensible inputs, with some weird concepts such as Handler, while there is no easy way to check the input/output (at early stages, input/output is always in text). Code in Notepad, as I stated above, is worst than hell. I remember the first time I code C in GNU/Linux: it was so easy! When I discovered the power and beauty of Emacs, I concluded that C would have been a breeze if I had known these things before I start learning C. Thus, I share these with you, in the hope that you will utilize them, and enjoy C as much as I have. Again, C is the ultimate power over your machine, with which you can tame even your own Operating System. Learn it, enjoy it, use it.

Happy Happy Joy Joy

About User Lin