C is a fantastic language. Although some people think that the only thing which one cannot do with C is to create a dynamic web page. While it is true that you cannot use C programs as scripts natively, you can use C as a web programming
language very much, and very easily. All you have to do is to find the right directory for the cgi programs, and put your compiled programs there. Of course, you can use the apache config files to alter the default directory for the same and it is not very difficult. However, a bigger question lurks - how good is C as a web programming
language? Certainly if it were just too good, PHP would not have been the most used one. On the other hand, if it was to be bad, facebook would not have been using it to serve web pages to a large extent or would not have written the HipHop project. We explore the pros and cons of C as a web programming
Beginning with the sweeter part, C is a brilliant language for the simple reason that it can create really high performance programs. Anything written in C (or C++) is going to be a lot faster than those written in any other language. The only exception is the assembly code, but then it is not of much use anyway in the day to day development (unless you are a real performance freak). So, to count as a first benefit, C provides you with the possibility of creating really high performance programs. According to facebook's engineering team, they could handle double the traffic when using C++ on the back-end when compared to PHP.
As a second advantage, C has more launguage familiarity. Most computer science courses begin with C and most programmers had C as their first programming language. With C/C++ at hand, one is familiar with the possibilities that come with C or C++. No need to go for strange ways of dealing with classes in PHP. Web programs written in C are much the same as anything else you would create in C, for example a console program. CGI takes care of outputting your printf statements to the resulting web page.
Almost every major OSS project has a API or a driver for hooking you up with C. So, you do not need to search for PHP plug-ins. In addition to this, all PHP plug-ins are written in C, so you are more likely to get benefited from that.
On the bitter side, C programs need to be compiled. So for any changes you want to make to the code, you have to recompile the program and then test it. Ctrl+S is not just enough. You cannot run C programs as scripts, the way you can do with PHP.
In addition to this, PHP is not a strongly typed language but C is. Which means that you cannot handle data you can do in PHP - easily. Taking care of the data type is something you must take care.
C code can be real tough to maintain as there is significantly more code that you will end of writing. The dynamism of PHP is not at your hands. With each new feature, you will end up adding a lot more code than you would have with C.
When to use C?
While PHP is great, it is slower than C. However, PHP is not 'dead slow'. We would recommend that you use C only to handle the parts of your application which need really higher performance compared to other parts. However, if you have more than one people working on different parts of the application, using C in parts will certainly disallow all of them to collaborate easily. In the next part, we will start exploring the code and how you can use C to create web pages.