I started 2013 off with A Discussion on Programming Languages
and later on I talked about Java
. Java was a natural place to start with since it's the language that runs RuneScape and it's a high level language. Recall that high level languages provide the programmer with a great number of conveniences and often are based around high levels of abstraction. High level languages are often best to learn on and hide most of the gory under-workings of the computer system. This month I'm going to talk about a low level language: C.
Comparatively to modern languages C is a very low level language which enables a great many of uses for this language. C is used for programming tasks where raw hardware access is often required. C has been used for tasks such as creating operating system kernels, writing device drivers, and writing operating systems themselves. C also has a prominent use in game programming for its low level access to hardware. With this knowledge in tow you're probably asking yourself, why would a person use C when they're not programming one of these systems?
Despite having many modern languages around there are still people and places that use C when they don't require low level hardware access. There are two reasons for this, C is fast and it's a great way to learn about hardware. Aside from primitive data types (numbers and characters) C has very few constructs that modern languages have. As a result of this programmers have to create their own data types in order to effectively build applications and tools. It's this process of creating data types and data structures that teaches a person about hardware.
In order to effectively understand a string (a list of characters entwined together) in C the programmer must understand pointers. Pointers in C allow unprecedented physical access to system memory. A pointer in C can be set up to point at any memory address and that byte can be read and manipulated freely. Pointers form the backbone of many common data structures that programmers need to create: strings, dynamic arrays, linked lists, hash tables, trees, etc. With the absolute required knowledge of understanding pointers in order to understand basic data structures of programming, it's only logical that the programmer must understand how physical system memory works. This is why C is a great choice for a programmer who wants to learn about low level system hardware.
System memory management is one area where C can be used for teaching low level hardware design. C can also be used for an introduction into multithreaded programming. Multithreaded programming is simply the idea of making an application able to execute more than one task simultaneously. C allows great access to forking of processes and threading. Forking a process is the act of creating another instance of the running process (usually an application) and using it to perform another task in parallel. A thread of execution is the sequence of instructions that are performed in a process. Most operating systems allow processes (applications most often) to have numerous threads. Running multiple threads in the same process is often used in order to process two or more tasks simultaneously without creating a whole new process.
Not only can a programmer learn about system memory management and parallel processing but they can also learn about efficient resource management. The use of pointers and managing system memory in C requires a programmer to manually allocate memory for use. On the same vane the user is also responsible for freeing the memory once they are finished using the specified block. The same can be said for forking and the use of threads, these must be managed with an meticulous level of observation. If forked processes and threads are not monitored they can become defunct and take up valuable system resources. When working with low level hardware such as the network stack or graphic devices a similar level of care must be taken. The most common cause of a Windows blue screen is something going horribly wrong in a low level piece of code, care was not taken!
C is the best way for someone to learn about the practical use of system hardware as outlined above. Learning C also creates a better programmer, a programmer who is more aware of what the code they use is actually doing. The best programmers understand what their code does not only on the surface but also below the surface. Through using a language like C this level of understanding is possible. What I've talked about thus far are the definite positive aspects of C but the same positives can be negatives as well.
C is by no means a language that should be learnt first. C should be learnt only after feeling comfortable with a higher level such as Java. There should also be some complimentary learning in the direction of hardware systems and operating systems in order to truly maximize the effectiveness of C as a language. There should also be a good reason for using C rather than a different language such as C++. If these cases can be met, C is probably a decent language to use.
Before wrapping up for 2013 I just want to mention some of the negative consequences of using C while unprepared. The most obvious ramification is not being able to create anything that uses complex data types due to the lack of pointer understanding. With a basic understanding of pointers problems can still arise, data structures that are inefficient and simply don't make sense can cause problems in the long run. It's also possible to have peculiar system crashes that are hard to diagnose without an adequate system understanding. With the positive aspects of C also being the tripping points it makes sense to learn C slowly only once a core understanding of operating systems principles have been established.
That's all for 2013, we'll be back in 2014 with more of what made 2013 amazing. If you are interested in hearing about other programming languages please post on the discussion topic. After covering a basic of programming languages and a high level (Java) and low level (C) language I will leave further discussion to the readers. See you in 2014.
This was originally posted as an Informer Tech