C Programming - good fun and a great beginners language


If you don't know C and have little interest in it then you will leave gaps in your programming education but if you are interested and want to learn C programming then a fascinating world awaits you where you will gain a real appreciation of computer systems, how they work and how they can be programmed for almost any purpose. Learning C will also get you extra kudos from fellow programmers and extra brownie points at job interviews because most people think of C Programming as a black art. The good news is that is isn't and if you are genuinely interested in how computer systems work then C is the ideal language to begin with


There are other programming languages of course such as Java and C# but these languages do not offer the same level of control over a computer system that is available to the C or C++ programmer and they also place a lot of obstacles in the front of the beginner which makes their learning curves unintuitive and difficult to grasp. C programming is leaner and by learning some of the basics you will be able to form a much better conceptual model of how computer systems work


Conceptual models are important to technical people because they act as a blueprint from which we can begin to apply our knowledge and understanding to everyday computing problems. Even if you don't become a C programming master you will at least learn what it is capable of at the systems level and the knowledge picked up along the way will give you a clear advantage over someone who chooses Java or C# as their first programming language


C is a programmers language. Learning C is well worth the effort because C code is everywhere and it will not be disappearing any time soon. It is still in the top 10 programming languages demanded by industry and languages like Java, C# and Python all borrow heavily from C making it the grandfather of all modern high level programming languages


Although C is a high level language it differs from other high level languages in that it is small and it does not have the strictness of Java or C#. There is a small collection of keywords in the C language but there are a large amount of operators that can be used in myriads of ways for solving any given computing problem no matter how simple or complex. This gives the programmer total freedom and is what makes C so flexible and powerful but with this great power comes great responsibility as far as you the programmer is concerned


C can be used for almost any programming task imaginable and will run on anything from a toy car to a supercomputer. It can be used to code anything from a user control menu in an 8-bit microcontroller application with a four line by 32 character LCD display to full blown 32 bit desktop applications complete with jazzy graphical user interfaces (GUIs) running on the Windows, Linux and Mac operating systems


C programs can be compiled to run on any microprocessor based hardware and they will run as native machine code without requiring layers of fat such as virtual machines like Java and .Net. This is also the reason why C is used to program real time control systems where no timing latency is acceptable in system performance. C code is only one level of abstraction above assembly language, which is often used by electronics engineers and other practitioners of black arts. C (and C++) programs are lean and fast yet the source code is very readable and understandable by human programmers


Just to give you an idea of how efficient a C program is compared to assembly language consider this. A simple C source file which asks the user to enter an integer and then does a test to see if the number is greater than or less that 10 takes up 375 bytes of disk space. The compiled executable version of this file takes up 7 kilobytes! An integer requires 4 bytes on a 32 bit system so as you can imagine, the C compiler creates a heck of a lot of ones and zeros, even from a very simple source file to create the machine code version of your C source file. This can be done in 5 minutes using C but if you were to attempt this using assembly language it would take ages. If you were to do it like they did in the old days by writing sequences of ones and zeros on punched cards it would take days. Well, It would take me days to do it anyway ;-)


C is the language used to write systems level software and the language allows you to gain complete control over a computer's hardware and it's operating system. The Linux operating system is written in C and it follows that the Linux operating system can also be stripped down and modified to run on any type of electronic hardware and this makes it a popular choice of operating system for use in embedded systems and mobile devices such as smart phones and portable radio sets


C is great when you get to know it because it is beautiful in it's simplicity. C programming is just you and the machine and there is no fluff like Visual Studio, C#, Visual Basic, Eclipse or Java to worry about and that is just as well because these things are all pre-built frameworks (platforms) and tools which were developed to supposedly make it simpler to create computer applications and deploy them to any operating system and even the web. Rapid Application Development (RAD) is what that is called and it is further up the chain of command and further away from where the real action lies


Frameworks use languages that owe much of their structure and semantics to the C programming language and if you first learn to C then learning them is later on is easy. The trouble with frameworks however is that you first need to learn a lot of stuff that has nothing to do with pure programming logic and from experience I know how frustrating it can be to get started and create a simple "hello world" program working in Java or C# for instance. I would never recommend these languages to anyone who wants to know how computer systems work because application development is not concerned with the inner workings of a computer system and rightly so. Application development just as much about project management, design, deadlines and customer satisfaction. The actual programming might typically be allocated around 20% -35% of the time available


If you want to quickly develop desktop applications you would use Python, VB, Java or C# because all you are required to know is how to include those external libraries you need and call the appropriate functions within them. If you know how to write loops, branches and work with variables then you are good to go. Done and dusted


Frameworks are big, ugly, cumbersome and complicated entities and the fact that they come with reams of documentation proves this case succinctly. With C all you need is a great book, some decent web links, a text editor and compiler and then you can begin to learn almost everything you need to know about programming computer systems. That is surely a sound proposition for anyone who is interested in really learning how to program. If you like logic games and puzzles then C will test you for sure and you will never get tired of it


Using a framework is akin to building a plain vanilla looking house at one location using jerry blocks whereas C programming is more akin to having the freedom and skill to build a house in beautiful and ornate red brick work at any location you like


A good C programming course will give the beginning programmer a thorough and in depth understanding of the main programming mechanisms that are commonly found across all programming languages - data types, variables and constants, looping and branching, input and output, system calls


C was designed to be a portable language and in this sense it forces a programmer to think about computer hardware and what limits are imposed on the size of data types a program can handle on different systems whereas if you are learning to program using a framework these important details are hidden away from you and taken care of by the framework. You are insulated and do not need to worry about these things and in this sense frameworks are more like black boxes that have been designed around the assumption that the programmer does not need to know anything about hardware or system level sorftware. Sometimes you need complete control however and you only get that kind of control using C or, god forbid, Assembly Language. Hopefully now you will have realised what I meant earlier when I mentioned power and responsibility


If you are coding up an application for use in an office you can just install a framework runtime on the office machines and then your program should run. For this reason you would be crazy to write desktop applications in C and you would use C#, Java, Python or Visual Basic instead. There is lots of earning potential in this type of programming and it keeps many programmers in employment


Frameworks are like boxes of pre written tools (scripts coded in C or C++) from which you import those tools you need to meet the requirements of each project. A framework is good for creating desktop applications for use in heterogeneous business environments or for commercial release software and there are tons of developers working in this area. They are called developers because that is what C#, Java and VB programmers do - they develop end user applications using frameworks whereas a language like C can be used for special purposes at the systems level


To get started with C programming all you need to do is download the GNU C compiler and start writing C scripts in a text editor, fire up a terminal, compile C programs and run them. Nothing could be simpler and there are some C tutorial links and resources at the end of the article for your enjoyment :-)


Learning C is not very difficult and after you have created the obligatory hello world application you pat yourself on the back because you have managed to get the compiler installed without any major dramas. It is a great idea to create small interactive programs such a simple menu based scripts which perform different actions in response to choices made at the command prompt


Working with a command line prompt feels like having a real dialog with a computer and once you see how easy it is to write and modify small programs and instruct them to do your bidding it can become quite addictive. It also gives you a better understanding of the gap between human logic and computer logic and the challenges which are involved in translating one into the other. If you like this type of programming then you should continue learning it because liking something is half the battle in becoming a master of it and everything you have learned could keep you in gainful employment for years to come


C allows you to make system level calls and open and save files on your hard drive. After you get bored writing small console applications then maybe you would like to spread your wings a bit and get your program talking to the hardware. This is when things get interesting because you begin to see that C is not a toy and that it is a very serious tool indeed. In fact with C you can access any addressable object on your system whether it be a byte in RAM, your screen or something that is plugged into a USB, serial or parallel port


Now that we are down at this level it feels like a world away from developing desktop applications and if you have read this far I am sure you will know what I mean. Try doing these simple little jobs with Windows 7 & and Visual Studio


If you can talk to port then you can talk to anything that is plugged into that port. It could be a small temperature semiconductor sensor soldered onto a printed circuit board and powered with an AA battery and all you would need to do is figure out how to capture the sensor output signal and get it into your C program. From your program you might want to log the sensor reading every x seconds and then open a log file and append the reading to all the others you have taken. Later you might want to create a GUI application that will call your log file and draw a graph of the sensor behaviour and save the image as a screenshot for using in presentations and user manuals. GUIs can be written in C using a toolkit like GTK


C is extensible and every C implementation comes with a built in standard library with functions for talking to the operating system kernel, performing the usual gymnastics with math and strings; data type conversions and the handling input / output tasks such as taking input from a keyboard and displaying it in the screen. You don't get lots functions for networking and creating Graphical User Interfaces (GUIs) like you get with Java and .net but with C you can seek and find pre-written libraries and GUI toolkits and include them in your program. This is still way better than throwing in all but the kitchen sink. It keeps your C applications lean and mean


This trimmed down approach is what makes C easily portable and why your code easily be compiled to run on any type of target device. Any type of hardware platform from an intel pentium 4 desktop computer to a small microcontroller chip embedded inside a washing machine can be targeted by a C compiler


Hopefully you have enjoyed this article and that is has helped you in some shape or form. Maybe you will want to try C Programming and if you do then I know you will not be disappointed in your efforts. All it takes is time and practice peppered with a little sprinkling of intellectual curiosity to become an efficient C Programmer


Personally Speaking

I first started programming in 1990 and I learned Pascal and Assembly Language on a college electronics course. I found them very interesting because their logic made sense. I designed and programmed an electronic circuit module to simulate the functionality of a washing machine controller. The design was based around a 6502 microprocessor, a timer and a ROM chip. The logic was worked out by creating flowcharts using a pencil and paper and then the flowchart logic was coded up in 6502 assembly language before being burned on to the ROM chip. I used an EEPROM which is a ROM chip that is erasable and can be programmed many times over. On a student budget you gotta be smart and save on the old pennies :-)


About 13 years later I did Visual Basic (VB6) in the first year of my degree course. I found the difference startling and while the language itself was simple the idea of graphical programming took some time to get used to. All we were expected to do was create pretty GUIs and hook up a few procedural style scripts that handled user actions via the GUI. GUI programming is pretty easy but you need to know what makes a good user interface and for that you need to read Jaboc Neilsen's notes on usability


In the second year they taught us Java using a programming tool (BlueJ) specially designed for teaching programming in colleges but BlueJ and Java encourage programmers to adopt the object oriented (OO) programming paradigm from the start and I think that this is what trips a lot of people up and turns them off programming. The class struggled and so did the instructor because there is nothing more demoralsing for both parties than attempting to teach people a subject that is clearly not sinking in. We got into the groove, eventually, but it took months for us all to feel comfortable with Java. The problem was that it takes time to get your head around the idea of objects, what they are and why you would choose to use them in the first place over the linear programming paradigm


It would have been more useful and productive to adopt C as the first year programming language because the other modules on the first year course included operating systems and computer hardware - subjects which deal a lot with computing concepts like memory, bits and bytes, input and output, etc. It would have made much more sense to teach C rather than VB6 because a C course would have consolidated the knowledge gained in the other modules and brought a degree of consistency to the proceedings. The students would have been made aware that there are such things as objects if only for the simple reason that someone would be bound to ask what the difference was between C and C++. The answer of course would have been that C++ is like C with objects and classes and that you should be reading up on them over the summer as you will be getting taught all about them in the second and third years. If you fail to plan then you plan to fail


In third year it was C# and all objects. Once you understand object oriented programming you dont forget it in a hurry and that is why I chose C# for my fourth year honours project. I also did a final year course on Artificial Intelligence (AI) using the Prolog language and it was pretty mind bending stuff which scared most the class witless. Lots of people dropped out and never made fourth year but that is bound to happen on any decent degree course because a good course will make sure that programmers program all the time and that they can't possibly achieve a pass on the theory alone. You can't bullshit your way through a programming degree and you need to put in a load of effort. Most of all programmers should love programming and do it almost every other day. It keeps the mind awake and it is a fascinating intellectual pursuit


Best of Luck


C Programming Resources

Free C/C++ Compilers

The C Standard Library

A Tutorial on Pointers and Arrays in C

All the C you need to know for GTK+ GUI Programming