[svlug] C/C++ flame bait
Bevan Schroeder
bevan at foo.net
Thu Nov 19 17:17:08 PST 1998
On Thu, 19 Nov 1998, Scott Deeg wrote:
> >D. Dante Lorenso wrote:
> >> I'm also fighting between developing in C or C++.
>
> Bevan Schroeder wrote:
> >For a game, C++ is a very bad choice. I would argue this in the general
> >case as well, but I don't want to start a silly flamewar
doh! I tried. :(
> Granted C++ is going to be slower, but there have to be better reasons.
> We're not talking about orders of magnitude speed differences. (are we?)
In general, nope. And I look forward to the day when OO-friendly
languages are able to actually compile to faster code than C, because the
compiler is able to get a better idea of what is going on. This can be
even more pronounced in languages like Java and ML with stricter types.
> window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
> gtk_window_set_title (GTK_WINDOW (window), "GTK Tic Tac Toe");
This is what the actual implementation of OO looks like, it's just
hidden from you in C++. So in C++ you do:
window.gtk_window_set_title ("GTK Tic Tac Toe");
and the compiler just makes "window" the first arg. Even C++ is confined
to regular stack frame calling conventions.
> you're calling an external function to modify the data in the object
> (gack). Second, you're having to cast the object to an appropriate type
> because the framework obviously doesn't understand that GTK_WINDOW_TOPLEVEL
> subclasses GTK_WINDOW (gack'). Then there's event handling with it's
> passing around of function pointers and use of (void *) blocks for data
> passing (gack'').
gack'': void *'s are pretty much necessary for any kind of data hiding in C.
gack': Typecasting is just as common in C++, and needs to be used in
most subclassing designs I've seen. Moreover, you're actually
casting a GtkWidget as a GTK_WINDOW, so it's a much more grandiose
subclass than you claim.
gack: It's only "external" because C doesn't support anything else.
> I found the basic TicTacToe example so inelegant that I have dropped even
> the consideration of learning GTK until performance becomes such an issues
> that I can't use Java. Even with all Java's flaws (and there are many) the
> standard libraries are very logical and OO, and facilitate the "use the
Actually, my biggest complaint with Java (after the fact that it's
interpreted) is the libraries. They're fine if you're writing Tic Tac
Toe, but the moment you want them to do something slightly out of the
ordinary, they're useless.
I will agree that gtk is not perfect, though. Nor necessarily even good.
But... it's better than Motif, it's very cross-platform (C source being a
strong factor in its ease of porting), and it's fast. If you don't like
coding for it, use glade to build your UI's for you.
> To compare, I recreated the TicTacToe example I found for GTK in Java. The
> Java source is less then half the size, is *much* easier to understand
> (IMHO), and implements the game better.
I thought gtk was extremely bulky when I first saw it, also, but that's
only because it refuses to sacrifice any power. If you want smaller
source, write a "GtkSimple" wrapper. I think something like this would be
very helpful. Hopefully, the Gtk bindings to interpreted languages like
Tcl/Tk and/or Python are simpler in design, since that would make quick
tic tac toe or configuration apps easy to write.
> What would be the compelling reason to use GTK/C and not a good(tm) OO/C++
> lib (if it actually existed).
To quote Dexter's Laboratory:
"I refuse to answer any hypothetical questions." :)
> It's very easy to interpret that as: the implementation of C++ in Linux
> isn't all that good so everyone develops in C so it gets all the attention
> (bug fixes) and C++ is left to flounder so C++ never gets any better so
> everyone programs in C so ... (phew). It is also likely that many senior
> engineers working in Linux prefer C because they have been using it for 15
> years. This leaves only the hardy, fanatic, and crazy using C++.
This is possibly true, but I'm not going to use a broken language in the
hopes that maybe someday the existence of my app will pressure someone
into fixing it.
_I_ don't like C++ because it's a big multicolored-chewing-gum ball of
"hey wouldn't it be neat if..." Kinda like perl, except that's what
Perl's all about, and people seem to take C++ more seriously.
I'm planning to look at Eiffel (eiffel.org) in hopes of finding a decent
OO-friendly compiled language with strict types. I think strict types
are essential to get any stable benefit (faster development time, more
efficient compiler output, garbage collection) from OO code. If anyone
has feedback on Eiffel, feel free to send it my way (off-list would
probably be best.)
Sorry for the length - the price of trying to discuss C, C++, Java, OOP,
and Gtk all in one message.
-bevan
--
echo "unsubscribe svlug" | mail majordomo at svlug.org
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ to unsubscribe
see http://www.svlug.org/mdstuff/lists.shtml for posting guidelines.
More information about the svlug
mailing list