Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 18 Apr 2006 08:56:18 -0400
From:      John Baldwin <jhb@freebsd.org>
To:        Benjamin Lutz <benlutz@datacomm.ch>
Cc:        freebsd-chat@freebsd.org
Subject:   Re: Why is not more FreeBSD software written in C++?
Message-ID:  <200604180856.19017.jhb@freebsd.org>
In-Reply-To: <200604172306.44838.benlutz@datacomm.ch>
References:  <200604151313.32519.benlutz@datacomm.ch> <200604171047.30753.jhb@freebsd.org> <200604172306.44838.benlutz@datacomm.ch>

next in thread | previous in thread | raw e-mail | index | archive | help
On Monday 17 April 2006 05:06 pm, Benjamin Lutz wrote:
> On Monday 17 April 2006 16:47, John Baldwin wrote:
> > To be honest, if you want a "safer" language, I'd prefer going from C to
> > C# or Java.  C++'s syntax is, quite frankly, clunky in several places.
>
> I perceive the syntax of C++, C# and Java to be very similar. The
> differences are minor. What about C++ is clunky that isn't also clunky in
> C# and Java? One thing that comes to mind is that you can't use >> with
> nested templates, but then that's not one of the most common things a C++
> programmer writes anyway. The things that bug me about C++ are mostly
> semantic in nature (no uniform access or read-only vars, requiring you to
> manually create accessor functions for everything, for example. Or no
> contracts, but then none of the mentioned languages offer that.)

C++ allows things like multiple inheritance and operator overloading which
can often be used to create some really confusing code.  C# and Java both
have a notion of interfaces and only allow single inheritance but additional
extensions via interfaces.  In my experience, this restriction actually
results in a cleaner and more robust design.  Similarly with operator
overloading.  Also, look at the difference in:

=46oo.{cs,java}:

class Foo {

	public void Bar()
	{
		...
	}
}

vs.

=46oo.hpp:

class Foo {

	public void Bar();

};

=46oo.cpp:

void Foo::Bar()
{
	...
}

Having to respecify all the namespaces again for each non-trivial
function is clunky.  With nested namespaces it can get even worse
(void Foo::Bar::Baz::Qux::Quux(), etc.)

> > At work I recently described C# generics as "C++ templates that don't
> > suck" for example. :)
>
> But C# templates offer little over the C++ ones (well, ok, there is one
> thing, template type specification, that's nice), but have severe
> limitations. Why do you like them better?

Because they are more limited. :)  There is such a thing as too much=20
flexibility, and I prefer C# and Java's more limited syntax to C++ as I thi=
nk=20
C++ is the "kitchen sink" language.  Also, having the type specification is
_very_ helpful.  The difference between "class X does not implement IFooabl=
e"
and some 8-line error from gcc that has all the templates expanded complain=
ing
about a missing foo() method is just painful.

> > Also, many of the bugs I either have myself or run into in other people=
's
> > code come from the programmer not taking into account all of the
> > conditions (i.e. missing an edge case in implementation or design), and
> > those type of bugs are not something a language is going to solve.
>
> Sure, there won't ever be a dwim language. But every mechanism that
> prevents a class of bugs categorically is a step in the right direction,
> imo (that'd be the direction of correctness). I'm aware that C++ isn't mu=
ch
> of an improvement over C when it comes to providing such mechanisms.
> However, it does make writing code more comfortable (well, if you know it,
> and like OOP), and it is actually shipped with the FreeBSD base system.

What I would like is a very basic C with classes to make the syntax for
all the struct's with function pointers cleaner in the kernel.  For the
kernel it would have to avoid the pitfalls common with many OOP languages:
all sorts of crap goes on in the background that you have to be aware of,
which is a royal pain.  For example, does 'a =3D b' result in memory being
allocated due to a copy constructor or some operator overload somewhere?
Operator overloading can be the worst for making code very obfuscated to
all but the person who just wrote it 5 minutes ago.  (And they'll be
confused when the come back to it in 2 months for some new feature or
bugfix.)

=2D-=20
John Baldwin <jhb@FreeBSD.org> =A0<>< =A0http://www.FreeBSD.org/~jhb/
"Power Users Use the Power to Serve" =A0=3D =A0http://www.FreeBSD.org



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200604180856.19017.jhb>