четверг, 29 октября 2015 г.

How Relevant is C in 2015

Many programming languages have come and gone since Dennis Ritchie devised C in 1972, and yet C has not only survived three major revisions, but continues to thrive. 

But aside from this incredible legacy, what keeps C atop the Tiobe Index?


One of the big reasons C will probably not be going away any time soon is there is no replacement and not much work being done on one. The higher level languages, language designers are constantly trying to redo or replace, but there is not much interest in replacing such a low level language... and the people who do use C are not interested either since they tend not to be language fetishists. And the people who do use C are not interested either since they tend not to be language fetishists.

Software is like an organ of your computer; your computer typically won't do much worthwhile if there's not a whole bunch of the things working together to make complete systems. Almost every one of the higher level languages are implemented in C at some point in the software stack. 

Some might argue that certain JVM languages like Scala and Groovy and Clojure are written in pure java, but guess what? The JVM is written in C. Almost every piece of software out in the wild is either written in C or depends on critical components written in C all the way down to the operating system. If you're running embedded, you might not have an OS, but you probably should be using C on microcontrollers and embedded systems unless there's a real good reason not to.

This is one good reason I program in C.

The other reason is portability. You can write something in C and it will run on every major platform and almost every embedded platform. Furthermore, it is portable between languages. If you write a library in C, people can call it from C#, Java, Python, TCL, Ruby, or nearly any other language. It is the lingua franca of programming.


Shoot Yourself in the Foot


C is a great language, and it gives its programmers a great deal of power and flexibility. But with that comes responsibility not to code like an idiot. If you're going to wield its power carelessly, of course you're a danger. 

Perhaps C's greatest weakness is that it places too much trust in the coder, where other languages don't. C is not a tool for the incompetent (whether temporary due to alcohol or permanently). It is an expert-only tool. There are a few of those around and they will stay around, because in the hands of somebody skilled, these tools deliver exceptional results that no more generally usable tool can match.
In C, you shoot yourself in the foot.
In C++, you accidentally create a dozen instances of yourself and shoot them all in the foot. Providing emergency medical care is impossible since you can't tell which are bitwise copies and which are just pointing at others and saying, "That's me over there."

Or alternatively,


C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off. -- Bjarne Stroustrup

Big Bad


The biggest bad reason for C being popular is that we've standardised on C as the way of defining library APIs in UNIX-land. There's no IDL that describes higher-level concepts - there are just C headers, and the language that makes it easiest to use C libraries wins. There has been some improvement in C-calling FFIs recently, and a big part of the popularity of Python is the ease with which you can use C/C++ libraries from it. Even simple things are hard when interoperating with C. It's hard for an FFI generator to know whether that char * parameter is a null-terminated string or a pointer to an arbitrary block of memory that's going to be read by the callee, a pointer to a single char that's going to be written back, or whether the callee returns a pointer to within the block and needs the original memory to persist. Lots of libraries take function pointers that have a void* context pointer, so can be mapped to closures in the caller's language, but they all put the context object in different places so you need a custom trampoline for each one.

With over 8 billion lines of open source C code (source: OpenHub.net), there's a good chance that the library that you want to use is written in C.

Комментариев нет:

Отправить комментарий