Why do you not use C for your web apps?
It takes a great deal of care to get a C program correct and secure. That care means that you need to have really good people writing your programs. That means you pay more.
Also, C doesn't have the benefit of drawing from an enormous single standard library of functionality as .NET (and the other major web-centric platforms) has. So you may have to either buy components, or perform interop, or roll your own functionality which comes "for free" with a more, shall we say "web-centric" language like PHP or C# or Ruby or whatever. That means you pay more.
Add all of that to the fact that single-threaded computational speed just isn't that important on the web. If you need more scalability, most organizations can economically just throw more cores at the problem and be fine. This is not true for everyone, of course. I'd imagine that the core of Google's engine is written in C or a similar language not only for speed, but to save real money in power costs.
Hum...
It seems that I am a bit late in this discussion - but I just discovered it now. And I am grateful to all of you for so much input.
I am G-WAN's author, which makes it clear that I have seriously worked on the matter: G-WAN is both faster than all other Web Servers (no processing) and all other Web Application Servers (any processing you can imagine).
Yes, ANSI C also made it possible to process more static content - with less powerful CPUs (ANSI C is not only about making dynamic contents fly).
By the way, G-WAN uses C scripts (no C compiler and linker needed) so the compiling/linking cycle/delay does not exist.
In the process of comparing G-WAN to .NET Java and PHP, I wrote similar applications in all 4 languages: http://gwan.ch/source/
And, to my dismay, the modern scripting languages were not easier to use.
One part of the job which is especially frustrating is to desperately search for the 'magic' API call that will do what you want to do.
Think about how to do 'pretty thousands' in:
C#
String.Format("{0:n}"...
Java
new DecimalFormat("0.00"); ...
PHP
number_format($amount, 2); ...
ANSI C
sprintf("%'.2f", amount);
The "..." mean that some pre-configuration, or post processing, is necessary. ANSI C is clearly easier to use and to remember.
When PHP has more than 5900 API calls (C# and Java not far away), finding the right API call is a challenge on its own. The time wasted to find this (and then to find how badly the native API call is implemented), the time to learn by hart it for the next time you need it, all this time is depriving you from the time necessary to resolve your application problems.
I have read (above) that PHP is more concise than ANSI C? Why then use "//:: this is a comment ::"
rather than "// this is a comment"
? Why have a so stupidly complex 'pretty thousands' syntax?
The other usual argument is that Java and the like provide dedicated calls for Web applications.
I was not able to find anything to escape HTML in Java so I wrote my version of it:
// all litteral strings provided by a client must be escaped this way
// if you inject them into an HTML page
public static String escape_html(String Name) {
int len = Name.length();
StringBuffer sb = new StringBuffer(len);
boolean lastWasBlankChar = false;
int c;
for(int i=0; i<len; i++) {
c = Name.charAt(i);
if(c == ' ') sb.append(" "); else
if(c == '"') sb.append("""); else
if(c == '&') sb.append("&"); else
if(c == '<') sb.append("<"); else
if(c == '>') sb.append(">"); else
if(c == '\n') sb.append("<br/>"); else {
c = c&0xffff; // unicode
if(c < 32 || c > 127) {
sb.append("&#");
sb.append(new Integer(c).toString());
sb.append(';');
} else
sb.append(c);
}
}
return sb.toString();
//szName = sb.toString();
}
Do you really believe that the same code in ANSI C would be more complex? No, it would be both immensely simpler and faster.
Java (derived from C) is requiring programmers to link multi-line strings with a '+'
C# (derived from C) is requiring programmers to link multi-line strings with a '+'
PHP (derived from C) is requiring programmers to link multi-line strings with a '.'
ANSI C does not have this now completely stupid (obsolete) requirement.
So, were is the so obvious progress claimed by the modern languages? I am still looking for it.
Sincerely,
Pierre.
The same reason we don't use C for most programming. The benefits (which are mostly performance) don't outweigh the costs (development time, lack of automatic memory management, lack of automatic protection from buffer overflows, having a compile stage between the edit and test stages, etc).
Most network applications, especially web servers, are far more "I/O bound" - ie they are capable of pumping out data far faster than the network can accept it. Therefore something that is highly CPU efficient is not a huge win, whereas something that is scalable and maintainable is. So there is no reason to accept the drawbacks of C and lose the advantages of a managed environment like Java, .NET, Python, Perl or other languages.