Why C as an implementation language?
rjek at netsurf-browser.org
Sun Jul 20 13:18:50 BST 2008
On Sun, 20 Jul 2008 13:56:03 +0200 CEST
"François Revol" <revol at free.fr> wrote:
> > On Sun, 20 Jul 2008 09:22:36 +0000 (GMT)
> > "Terje Slettebø" <terjesl at broadpark.no> wrote:
> > > Unfortunately, the mailing list archive doesn't have a search
> > > function, and I can't find a FAQ for this, so I'll ask here: Does
> > > anyone know why C was chosen as an implementation language for
> > > NetSurf, and not something like C++?
> > 1) Reliability, availability, quality, performance and price of
> > compilers available at the time.
> Well, BeOS (userland at least) was written mostly in C++ and it
> worked quite well, and that was 10 years ago or more. I think it's
> more due to lack of knowledge about it. Granted they only later
> switched from mwcc to the freely available gcc.
RISC OS however, where NetSurf started, had no good C++ compiler when
we started. (The only one that could provide any sort of performance
was based on CFront, and expensive.) Thus, starting in C++ would have
been the wrong decision. We now have 100k lines of code I don't think
we want to rewrite.
> > 2) Familiarity, readability, performance and portability of C.
> Well, it's exactly the reason some head developers at Haiku chose to
> rewrite parts (in the kernel) that were written in C in BeOS as C++.
> Like OpenBFS. I don't like much C++ inside the kernel for some odd
> reason, but it has some use it seems.
> And mind you, I jumped into BeOS around 2000, and never did any C++
> before, and I fitted the gloves in a snap. That is, the Be API
> doesn't make use of templates or so, so it's very readable. OTH,
> templates are used in our kernel to simplify list managment, but that
> part can sometimes get not as readable as meant :)
C is an order of magnitude more portable than C++, which is one reason
for keeping it. There don't appear to be any C++ compilers that
support the same set of functionality, for example. You could just not
use all the functionality that's unreliable when porting, but then you
just end up with something like C except with syntatic sugar for
creating objects. NetSurf already is object orientated, we just don't
use a language that provides syntax to do it "easily" for reasons
> Well, I think Haiku proves one can write a big free software project
> in C++ with lots of contributors. I invite you to come and read the
> code by yourself and make an opinion about it:
I suspect Haiku's situation is somewhat different. It's been written
by people who like BeOS, and therefore one assumes are familiar and
competent in C++. A web browser is a completely different kettle of
fish: the only thing its developers are likely to be competent in is
HTML/CSS, and if they're anything like me, they lack even that!
> > 4) I don't know about the others, but I hate C++ almost as much as I
> > hate Perl and Ruby. It's an ugly and hideously complex language.
> Well, noone forces you to use STL...
> At least here nobody objected me putting C++ code in for BeOS (which
> is necessary because its API is C++), but I know some projects with
> people so anal about it it's a hard time just putting a single .cpp
C++ is fine when you're interfacing to something written in C++. One
of the other reasons not to use C++ that I didn't list is that it is
sometimes difficult to reuse non-C++ stuff elegantly in a C++ context -
and NetSurf got off the ground quickly because we didn't reinvent every
wheel we came to - we reused existing ones.
Anyway, this is dreadfully off-topic. I wasn't contributing to the
project when it started, but I can see a lot of very good
show-stopping reasons for not having started it in C++. Now we've got
a large amount of source code, in generally very-high quality C, it's
going to be a huge chore to move it to another language with little or
More information about the netsurf-dev