Re: [LAU] OT: C or C++?

From: Erik de Castro Lopo <mle+la@email-addr-hidden-nerd.com>
Date: Thu Oct 14 2010 - 07:17:06 EEST

Josh Lawrence wrote:

> hi Erik, I'm glad you asked this question...I've always felt like a
> sub-par Linux user because I could not program. I've also noticed
> that a lot of programs I've run across in my limited experience with
> Linux are written in C. therefore, learning C could only help my
> understanding of my computer.

This is an interesting point. Yes, the vast majority of the small
useful utilities that run on a Linux machine have historically
been written in C. In addition, OS kernels, device drivers and
speed critical tasks are usually written in C. That means that
any professional programmer or dilligent amateur programmer
should know C.

However, for the small user space utilities, C is not the only
game in town. As part of my day job I ocassionally write similar
small utilities to run on our kiosk style linux systems. However,
I rarely write these utilities in C; C is way too flawed and
unsafe a language.

Instead, I write these utilities in strict statically typed
functional languages like Ocaml and (more recently) Haskell.
These languages are higher level so I don't have to worry about
things like memory allocation and buffer overflows. They also
have safe strings which makes string processing far easier than
in C or C++. The standard libraries of these languages have
simple, easy and guaranteed safe handling of high level data
structures like lists and dictionaries so I don't have the
write them from scratch.

However, most of the features above are also shared by languages
such as Ruby and Python. The big difference is that Ocaml and
Haskell programs compile to native binaries (like C and C++) and
that the compilers for these languages have a much more strict
type checkers (ie they find coding errors) than C or C++. This
means that many classes of bugs are found at compile time rather
than at run time like they would be for Ruby/Python/etc. The
native binaries produced from Ocaml and Haskell programs also
tend to run siginificantly faster than byte code interpretted
programs written in Ruby/Python/etc.

> also, I've noticed that at my local school most of the computer
> science majors use C, so I figure that if I learn C, I can at least
> understand that course material on some level.

As you might guess from what I've written in this thread, I am
quite interested in programming langauge research. From what I
have seen of this feild, the vast majority of programming
language centered computer science research (ie PhD research
and papers in reviewed journals) is done around Haskell and to
a lesser extent Ocaml.

In summary, since your interest seems to be in improving your
knowledge about Linux and how your machine works, C is definitely
the language to look at. However, C has many traps, requires
strict attention to detail and can be rather unforgiving. Higher
level langauges like Python, Ruby, Ocaml and Haskell allow you
to concentrate more on the problem than on the details.

Good luck.

Cheers,
Erik

-- 
----------------------------------------------------------------------
Erik de Castro Lopo
http://www.mega-nerd.com/
_______________________________________________
Linux-audio-user mailing list
Linux-audio-user@email-addr-hidden
http://lists.linuxaudio.org/listinfo/linux-audio-user
Received on Thu Oct 14 08:15:01 2010

This archive was generated by hypermail 2.1.8 : Thu Oct 14 2010 - 08:15:02 EEST