[wplug] relevance of C for Apps

Bill Moran wmoran at potentialtech.com
Wed Oct 6 11:22:54 EDT 2004


Chris Romano <romano.chris at gmail.com> wrote:
> I don't want to start a flame war or anything and this is/can be a
> loaded question, but is C still a good language for developing Apps? 

That's too broad of a question to answer with a yes or no.  I would
say that C is still better than C++ (although that would start a flame
war)  but it really depends on what you're trying to accomplish.

> I know for things like a kernel and very low level stuff, it is still
> the number 1 choice.  But what about apps in general?  One of the
> biggest arguments that I hear for using C is that it's fast.

"Fast" is a relative term.
C is 2 - 4 times faster than Mono (C#) or Java, at least.  For many
operations, it's even faster than that.
However, C is _very_ slow to develop in.  Debugging C takes a lot longer
than debugging high level languages like C# or Java.
On the flip side, C is a lot easier to performance tune than Java or
C#.  This could start another flame war, but it's my experience.

> With
> machines becoming faster and faster and some of the security concerns
> around C, is C++

C++ doesn't really have much over C, overall.

> or Java a better choice.

Definately.  If raw speed isn't a major concern, then something like
Java, C#, Perl, Python, et al would be better.  Even if speed is a
concern, these high-level languages are often fast enough.

The only place I would say should always be written in C is server
applications that will need to scale.  These always benefit from
the speed of C.  Sometimes you can get away with something else,
but not always.

> Is C that much faster then
> C++ and Java.

I've never test C vs. C++, but the general consensus is that it's
about half as fast.  Java has a lot of problems when you're constantly
allocating/deallocating memory (i.e. creating/deleting objects) but
careful programming can mitigate this somewhat.

C will always be faster than interpreted languages that have to do
their own garbage collection, but having to manually program all the
memory allocations/deallocations in C is a common source of bugs and
memory leaks.  So it's a trade off.

If you've got the time/money/patience to develop in C, your app will
be faster and more memory efficient than you can ever make it in
Java, or any interpreted language, or any language that does automatic
GC.

> I know that some Java apps can take some time to load
> at first.  If it's already up and running, is it about the same as
> C++.  I'm not familiar with C++ or Java, although I had a class in
> C++.  The teacher was horrible and I really didn't get anything out of
> the class.  I have used C and do use it when the need comes.  I also
> hear people talking about using a scripting language like PHP, Python
> for the front-end/GUI and C for any heavy processing.

Not a bad approach.  I've done stuff like this.  Done the parts of the
app that don't need high performance in perl, and the part that requires
the highest performance in C.

> Does anyone
> have any experiences or insight on this?  I guess in the end looking
> in the future does it seem better to use C or some other language for
> app development.

It really depends on your app.

If you look at a kernel, there are parts of every kernel that are written
in assembly, because even C doesn't provide a way to make native opcode
calls to the processor (which a kernel needs).  But the time and knowledge
required to write in assembly has made it impractical for almost everything
else.

C++ has the advantage that it's compiled into native binary (just like C)
before being run, but C++ is an overcomplicated language, and that results
in binaries that are larger and slower than those generated by C.  It's
possible that improvements in compiler programs will improve this over time.

Java, C#, and other interprted (or bitcode - meaning half-interpreted)
languages are probably as fast as they're ever going to get.  The advantages
of these high-level languages tends to make up for their minor speed
problems, but I don't think it will result in them always being the right
thing to do.

As machines get faster, it will continue to be more practical to use
languages like Java and C# for desktop apps, becuase they'll be fast enough
on modern computers.  If you're running a multi-user server application,
though, you might want to consider taking the extra time/effort to write
it in C so it's as scalable as possible.

The other advantage that languages like Java, C#, and perl have is how
easily they're ported from one platform to another.  Java and C# being
the best at this.  You don't even need to recompile anything.

-- 
Bill Moran
Potential Technologies
http://www.potentialtech.com


More information about the wplug mailing list