I know this opinion is quite heretical in the current programming climate, but C has some serious problems as a language for anything but the most low-level code.

  • C is not memory-safe There is nothing in C that prevents a program from scribbling on random bits of memory. This is a task left to the OS, which must sandbox processes to maintain memory integrity. This works, however it makes interprocess communication much more difficult than necessary, leading to byzantine systems such as CORBA.
  • C cannot be garbage-collected efficiently Since integers can arbitrarily be casted to pointers and pointer arithmetic is possible, it is impossible to determine what areas of memory are in use by a C program. The Boehm GC can be used to a certain extent in C programs but cannot guarantee total collection. This leads to an entire class of memory bugs impossible in high-level languages.
  • C has poor support for dynamic data structures The fundamental collection type in C is the static array, leaving all higher-level data structures to be reimplemented every time one is needed.
  • C is weakly typed Typing is barely enforced in C, encouraging poor design.
  • C is difficult to optimize Due to its low-level nature, there are very few clues to the compiler as to where data structures and algorithms can be optimized or parallelized.

C++ adds dynamic data structures in the form of the STL, but does little else to correct the major flaw, which is lack of pointer safety. C *is* a useful language for low-level code such as hardware interfaces but should not be regarded as suitable for general programming.

C is not memory-safe
C assumes you know what you are doing. If you do not, go back to Pascal or Basic and learn how to program.

C cannot be garbage-collected efficiently
This is a Good Thing(TM). Garbage collectors are for lazy programmers.

C has poor support for dynamic data structures
So make them. C gives you basic, flexible data types. If you want something more complex, build it.

C is weakly typed
Another Good Thing(TM). Data is data, I should be able to do with it what I like. A programming language should not get in the way, if it does, it's little more than a toy, as Pascal is.

C is difficult to optimize
Good programmers should be able to optimize better than a compiler. As for anything else on this topic, I'll leave to those more versed in compiler design than I.
In response to ShadowNode:

C assumes you know what you are doing. If you do not, go back to Pascal or Basic and learn how to program.

Nope. C assumes that you won't make mistakes, and everybody makes mistakes. Assuming you don't is pure hubris that will bite you severely, for even the most godly hacker will still have to go through debugging.

Garbage collectors are for lazy programmers.

Garbage collectors spare you the work of manually freeing memory. But I suppose masochists dislike them...

C give you basic, flexable data types. If you want something more complex, build it.

Yeah, were would we be if we could save time by not having to reinvent the wheel all the time? A better answer would be: use any of the widespread, free libraries that provide advanced data types.

C is weakly typed. Another Good Thing(TM). Data is data, I should be able to do with it what I like. A programming language should not get in the way, if it does, it's little more than a toy, as Pascal is.

Again, see the first point. Weak typing increases the likelihood of fatal and hard-to-find bugs, and it's quite possible to retain flexibility with strong typing by using explicit casting.

Good programmers should be able to optimize better than a compiler.

Flat-out wrong. Good optimization requires intimate knowledge of processor details, and that's not something a programmer should have to worry about. Furthermore, if you put such optimizations in the source, you make it less portable.

I think one needs to size the tool for the task.

If you are writing something in which speed and control is critical, like an operating system, or a game, you will need to use a low level language. Even in this case you need to make a choice. Writing the whole program in assembly language might not be very efficient.

If, on the other hand, you are writing a simple program to retrieve some data from a database over the Internet, process it somewhat, then present it to the user, it would be foolish to waste resources on developing this in C when languages like Python and Perl lend themselves perfectly to this kind of task.

I do not use a wrench to build an entire car, and just as seldom do I assemble my IKEA furniture in a robotic assembly plant. I think this is just a matter of common sense.

The discussion of comparing C to other similar languages, however, is something completely different.

Log in or registerto write something here or to contact authors.