Complete.Org: Mailing Lists: Archives: freeciv-dev: May 2000:
[Freeciv-Dev] Re: OO model for Freeciv?
Home

[Freeciv-Dev] Re: OO model for Freeciv?

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: ½²«íµØ <iquin@xxxxxxxxxx>
Cc: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: OO model for Freeciv?
From: Daniel Burrows <Daniel_Burrows@xxxxxxxxx>
Date: Mon, 1 May 2000 22:54:17 -0400

On Mon, May 01, 2000 at 10:13:51PM -0400, ½²«íµØ <iquin@xxxxxxxxxx> was heard 
to say:
> >s += '.';
> >
> >What is the shortest way to express this in C?
> s = strcat((char *)realloc(s , strlen(s) + 1), ".");
> Convenience sometimes makes programmers unaware of the underlying
> costs, results in less efficient codes.

  This is O(n^2) in the number of times you do it.  Any sane string
implementation will use a doubling-array approach, which is O(n) in the number
of times you do it (but would take too many lines of C to be written inline,
you'd need a library)

  Inconvenience sometimes makes programmers take shortcuts and damn the
resulting costs, results in less efficient codes.

  (Note: I also don't think rewriting Freeciv in C++ is a particularly good
idea [1], but this argument goes both ways (you can also abuse C++ in horrendous
ways to generate bad code, and I'm not very good at writing efficient code.
But I can't let a statement that that strcat call is more efficient than
the C++ construct pass :) ) )

  Daniel

  [1] If I had godlike powers and wanted to alter Freeciv, I would cause it to
     be designed with a small C kernel and all high-level logic written in
     Lisp or Scheme, a la the Sawmill window manager (to name a recent example
     of this design strategy)  This would be such a redesign of the current
     code, though, that it'd probably be better to start from scratch, which
     I have no intention of doing.



[Prev in Thread] Current Thread [Next in Thread]