Re: C++ more efficient than C?
Erik Wikstr??m wrote:
On 2008-04-10 21:12, Richard wrote:
peter koch <peter.koch.larsen@gmail.com> writes:
On 10 Apr., 11:00, Kelsey Bjarnason <kbjarna...@gmail.com> wrote:
I take it the term "maintenance programmer" means nothing to you.
I have maintained some pretty horible code in my lifetime, with
functions that were often in the order of 500 lines and now and then
in the thousands. I dont remember having had serious problem figuring
out whether a function did or did not modify its parameters.
Much as I think the other poster is breaking records in c.l.c for being
a big headed know all, I must concur with him that the notation leaves a
lot to be desired. I for one must assume that your maintenance of other
peoples code is minimum since the C++ reference notations leaves a LOT
to be desired when reading the code. I have to agree with Kelsey - at
the top level you really have NO idea what is happening to the
variables. We wont even get into operator overloading and people abusing
that. it#s certainly nigh on impossible to read C++ code from a printout
unless you have the brain and recall abilities of a super computer.
Strange, I've always found Perl code hard to read but the Perl-
programmes does not seem to have any problem. On the other hand I can
read most C++ code just fine, and find C code harder to read. But then I
do not usually write either Perl or C, perhaps it is more a question of
getting used to it then whether one language is easier to read then
another?
Yes, that's probably the reason.
For example I personally find
void SomeClass::f(data &d)
{
Locker(*this);
do_something(d);
DBConnection c();
c.do_some_db_stuff(d);
}
much easier to read and understand than
int someclass_f(SomeClass *c, data *d)
{
int res;
DBConnection *c;
if((res = lock(c->mutex)) != 0)
return res;
if((res = someclass_do_something(c,d)) != 0) {
unlock(c->mutex);
return res;
}
if((res = get_db_connection(&conn)) != 0) {
unlock(c->mutex);
return res;
}
if((res = do_some_db_stuff(conn, d)) != 0) {
close_db_connection(c);
unlock(c->mutex);
return res;
}
close_db_connection(c);
unlock(c->mutex);
return 0;
}
or
int someclass_f(SomeClass *c, data *d)
{
int res;
DBConnection *c;
if((res = lock(c->mutex)) != 0)
return res;
if((res = someclass_do_something(c,d)) != 0)
goto out_lock;
if((res = get_db_connection(&conn)) != 0)
goto out_lock;
if((res = do_some_db_stuff(conn, d)) != 0)
goto out_db;
res = 0;
out_db:
close_db_connection(c);
out_lock:
unlock(c->mutex);
return res;
}
But I have to admit I admire everyone who can write complex applications in
C without getting insane. I know I couldn't.