tags:

views:

336

answers:

11

I started programming in Java and then eventually moved to C++. I then noticed that many languages use bindings to C libraries such as GTK, OpenGL, OpenAL, and many others. Also languages such as Java, Python, ADA are plentiful in bindings to C libraries... Then there is databases that have bindings to C.

I then read an article from Joel stating that all CS graduates need to learn C... So I took up that advice and so far it seems to me nearly everything is done in C; again Linux, and so on. Many things from other languages have became more clear just by picking up the C programming language book.

Why is it that the industry has moved away from C, but it is yet so stuck on the foundations of C? For example if Java is so much more better than C, why isn't everything done in Java? Why aren't libraries converted to pure Java and so on?

http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html

+9  A: 

You need to know C even if you aren't going to end up using it professionally, because it's sufficiently close to the machine for you to gain a better understanding of that machine.

The reason most don't use it professionally though is that it takes longer to write the same program in C with respect to Java/C#, which makes it look bad for business, and because many programmers do not like using it.

(For the record, my favorite language is C++ -- I'm not trying to bash C here, I'm just trying to explain what I've heard before)

Billy ONeal
I completely agree with you on a better understanding of the machine... But what I don't get is why it isn't a general requirement for programming... The 288pg book from Ritchie cleared up a lot gaps.
@m00st: You can write programs with no understanding of the machine in languages like Java and C#. That does not mean that they will be **good** programs. IMHO understanding of the underlying platform **is** a general requirement for writing software.
Billy ONeal
+4  A: 

Each and every programming language has its advantages and disadvantages. That's why.

erelender
Also, different purposes.
erelender
+3  A: 

So what would you write the Java VMs in?

There always has to be something at the bottom of the language level stack, something that operates on a low level, close to the "bare metal" and that something is almost always C.

GrahamS
Then what do you write the C compiler and runtime in? Infinite regress. In reality, nothing fundamentally prevents one from implementing a VM in the language of that VM.
Konrad Rudolph
@Konrad: Usually the C compiler is also written in C.
Billy ONeal
@Konrad; actually there is. Java relies on garbage collection, so you can't create a Java VM in Java. Or you can, but eventually there'd have to be some Java VM written in something else doing the garbage collection.
roe
@Konrad: And there is no runtime. C compilers usually generate machine code. There are, of course, runtime *libraries*, mostly written in ... C.
Marcelo Cantos
Except it isn't an infinite regress. C translates very closely to assembler. It is the end of the line. You can only really go any lower by writing directly in assembler. Whereas if you write a VM in a VM language there is still *something* below it interpreting that VM language. There is nothing really below C/Assembler.
GrahamS
Incidentally, this is why Java ought to be considered a scripting language... ;)
roe
@roe: Of course the first Java interpreter would need to be written in something else, but there's nothing preventing you from using Java to write a Java compiler. You need an initial Java runtime, sure, but the same can be said for C.
Billy ONeal
@Billy ONeal: the same can't be said for C. C has NO runtime. Its runtime support is the CPU!
GrahamS
@GrahamS: You still need the initial C compiler, and you still need the initial C runtime libraries (malloc, free and friends). Those don't get on the processor by themselves. The additional runtime required for Java makes it more difficult, but it is by no means impossible to write a Java compiler in Java.
Billy ONeal
@Billy; not only the first Java interpreter. All java interpreters. Or you CAN write a java VM in java, but that VM has to run in another VM not running on java (remember, garbage collection). The compiler can be written in java, no problem, it's just transforming data. You may also write a compiler turning java byte code to assembler/machine code, but then there's no VM anymore.
roe
@roe: Nobody says that the compiler can't embed the necessary runtime pieces into the resulting binary.
Billy ONeal
@Billy: That’s what I wanted to get at. So why not write Java in Java?
Konrad Rudolph
@roe: bootstrapping helps. Ultimately, there must always be an escape to the underlying system but take a look at Singularity, an operating system and runtime written (almost) entirely in C#. And Spec#.
Konrad Rudolph
@Marcelo Canto: exactly, there’s the C runtime (library). Java too runs directly on the CPU. Writing a JIT in Java is not a problem. Java’s garbage collector is also just another library. The only difference is that you don’t call to it explicitly.
Konrad Rudolph
@Konrad: Because there's no reason to. There are plenty of Java implementations written in C already
Billy ONeal
@Billy: of course. My point was that it’s *possible*, just as C compilers can be written in C. There is no reason that Java cannot in principle be used to bootstrap a complete Java system (compiler *and* runtime).
Konrad Rudolph
@Konrad: My comment had nothing to do with what language the compiler is written in. It's about the runtime environment. Java bytecode doesn't run on hardware. It has to be translated by a JIT compiler at runtime. A C library, in contrast can be memory-mapped into the process, then you issue a jump instruction to the appropriate offset, and away you go. You can't bootstrap most systems with Java because most hardware doesn't run Java as-is. There are some rare exceptions to this, of course, but that's another debate.
Marcelo Cantos
+11  A: 

C has some desirable properties.

It's close to the metal, and requires very little runtime. This means that C libraries can be very efficient when necessary. It also means it's a good language to teach computer basics (not necessarily Computer Science basics or programming basics).

Almost everything has a C compiler nowadays, and there's frameworks to port one if necessary. Putting a JVM on a new platform is much more work.

C has been around for a long time, and there's a generally accepted ABI. It's simple, so it's easy to have programs in most languages call C routines. It's old, so almost all language implementations have that ability.

Since C has been around for a long time, it's easy to find C programmers when you want them.

David Thornley
+1 for multiplatform point.
Billy ONeal
+1 for the ABI point, I was about to make that one myself.
roe
@roe I suspect the ABI point is critical. I know that if C++ had a well-accepted ABI(for namespaces, polymorphism, classes), without need for extern "C"{}, I'd see much less need for C.
luiscubal
+1  A: 

C is very basic, it doesn't have the usability of other languages, you could build it up to have more functionality. The problem is that YOU would have to build it.

Java and C++ and other high level languages are popular because they have tons of functionality already built in, and this makes programmers lives considerably easier. Personally I like easy :)

Shaded
Personally, I like to have full control and implement things manually. So it depends on the programmers' taste and preferences. But perhaps even more, it depends on the project you are working on. Operating system or card game?
Andreas Rejbrand
A: 

Depends. Some companies still use C. It's more about getting the most business advantage from the language used. If you are developing device driver, then sorry, you need to stick with quite low-level languages. But, if you're are to develop an 'enterprise' application, then you would probably see more Java/C# because of the high level of the language, time that it takes to get the features implemented, and also cost of development. It's all depends on the application. Now the language arena is more diverse, and everyone I believe chooses language to get the most advantage with it.

Though C is good to know as by learning it you acquire some fundamentals of computer science that are universally useful.

tdobek
Personally, I thing that every programmer should know the basics of assmebly programming.
Andreas Rejbrand
A: 

Businesses tend to use higher level languages instead of lower level ones because it takes less time to create functioning programs. And since time is money, they want to create programs very quickly to make a lot of money. Using C to create a simple program is like trying to flatten a handkerchief with one of those roller trucks. It works, but it's overdone.

Also, did you mean your title to be "To C or not to C? That is the question." ? (Hamlet geek here...)

jmont
A: 

Design of software is more important than the programming language. That said C would be a good language to start programming with. When you evolve to a be a better designer and based on the project needs and platform you mite want to switch over to languages which provide better ease of use ( I am not saying those are better than C).

As one of the posts mentions build a greater enterprise solution you may graduate to using C++, Java and C#. You can as well write a good Object oriented solution using C but the other languages provide the support for it and so you mite as well concentrate more on the design part.

Praveen S
+2  A: 

There is basically a case of choosing the right tool for the job. C/C++ is "lower level" than Java and (all else being equal) should be used for lower level tasks.

C/C++ is more appropriate when you want to write code that is "close to the metal" for maximum performance or interfacing with the hardware. Suitable for graphics-intensive games, operating system development, writing Linux/UNIX utilities, high performance computing.

Java is more appropriate when you are more interested in portability, security, convenience and development productivity. Suitable for business applications, prototyping, web applications, less graphics-intensive games.

I've coded professionally in both. I tend to use Java nowadays because most of the things I develop fall into the latter category. But I would use C/C++ if I wanted to develop anything in the former category.

mikera
A: 

Also, the TIOBE index does not measure how great a language is, how much people like a language, how many apps are written in a language, or anything like that. It measures how much people mention the name of the language. That would mean on your resume, where you will presumably only mention languages you still find to be relevant, or in postings where you claim that one language is way better than another, where again even your vanquished language will presumably be relevant to both you and the people you're talking to.

If I said that driving is faster than walking, but didn't mention using a skateboard, the TIOBE index approach would rank walking above skateboarding. Then if someone else said riding a bike is faster than walking, walking would end up top of the list. It's interesting and meaningful that people use C as the comparison language in these conversations. But the meaning it carries isn't that C is better or that all the whippersnappers should learn it. (And yes, I know C, and C++. And I once knew several assembly languages. And I really truly honestly did hand assemble assembly language into machine code and then type it into a computer my husband and I made in the apartment from a kit and a soldering iron and random bits of wire. But that was in the eighties.)

Kate Gregory
A: 

To quote the Bard:

To C or not to C - that is the question: whether 'tis nobler in the mind to suffer the syntax and obfuscation of ancient languages, or to take arms against a C++ of troubles and, by opposing, use Java.

It's an interesting question, especially if you compare C++ and C using modern compilers. There's not much between them since C++ is a superset of C, anything you can write in C will pretty much work in C++.

One reason a lot of these libraies and OSes haven't been ported to C++ is time and money. There's a lot of code in some of those examples you gave, and rewriting it all would be a colossal task. What ain't broke....

Then there's the fact that a lot of these libraries started life before C++ compilers became robust enough to be used for this kind of development, and again, porting to a different language half way through is never a god idea.

Skizz