Portability (offtopic)

David Olofson wrote:

I have seen that SDL and most games are written in C and I’d like to know
if old C is more portable than C++.

C appears to be slightly more portable than C++ in real life, but this
shouldn’t be a significant problem these days. Most C++ compilers support the
ANSI standard fully, so you should be safe as long as you stick to that.

HAH! That’s a good one.

However, despite the advantages of C++ for advanced OOP, there are quite a few reasons to stick with C, especially for Free/Open Source projects (some pure facts, some common opinions):
    * There are more hackers with a thorough knowledge of C.

Open source should be about fighting mediocrity and breaking damaging
trends, not embracing the status quo.

    * C has fewer constructs and thus fewer "low level"
      programming style options. That makes it easier to
      read anyone's C code and understand it.

Not if C is a misfit for the problem at hand. If you have to twist C to
fit a problem that would be better solved with C++, good C could easily
become as hard to understand and maintain as bad C++.

    * The above also makes it harder to break the local style
      and design of a project. Mixing programming styles can
      make the code harder to read and maintain.

Uuh? It’s just as easy to break style parameters in C as in C++. I’ve
seen some REALLY bad and inconsistent C code… And I’ve also seen the
source to CivCTP and a few other large game projects, both in C and C++.
If you get enough impatient programmers in a room with a sufficient
amount of pizza and a difficult enough deadline, you can produce you
pretty damn poor code in any language.

    * C has less abstraction than C++, which makes it harder
      to misunderstand code that deals with structures/classes
      and custom data types. (No operator overloading, for
      example.)

WHAT?? Badly written C has less abstraction than well written C++.
That’s not inherent in the language.

    * It's generally easier to write absolutely terrible C++
      code than it is to write bad C code.

If you saw some of the @#$% that the professors around here write for CS
homework assignments (as the provided code we have to work with), I
doubt you’d make any claim that bad C code is hard to write. (Geez,
you’d expect these people to be halfway competent programmers… They’re
teaching the CS classes!!)

    * In C, it's harder to see levels of abstraction that may
      slow down you code. (Ex: Virtual function calls involve
      two pointer indirections, one being a pointer table look-up,
      and you can't even see that on the code! The corresponding
      C construct is a function pointer in a struct, which is
      to spot and keep track of, even without looking at the
      struct definition.)

You’ve mixed up C and C++; I’ll assume that’s a typo.
If you know how the language works (which you should, if you aspire to
program in it), you’ll know how virtual function calls work, and how
they perform. I’ll agree that C is a simpler language, but there’s a
reason for things like virtual functions; Bjarne didn’t make them up
for fun.

    * OOP doesn't really pay off for a project of a "sane" size
      and complexity. (Note: You *can* use the C++ features for
      other programming styles than OOP.) Most games aren't big
      or complex enough to warrant the use of OOP, and thus,
      don't really need C++.

That’s a fallacy.

    * You *can* program in an object oriented fashion in C, and
      the level of OO you can achieve that way addresses most of
      the problems that people chose C++ to deal with.

If you’re going to use C like it’s C++, why not use C++ and let the
compiler’s optimizations, error checking, and the targetted syntax kick
in?

    * You can still use a C++ compiler to compile your C code,
      thus taking advantage of the stricter compile time checking
      that C++ compilers do.

-W -Wall -pedantic -Werror works nicely for C. C++ compilers are made to
compile C++.

    * OOP is not "simply better" or "superior" to all other
      programming styles, but it is indeed very useful for some
      things. However, the C++ features are basically designed
      *only* for OOP, while ignoring other programming styles.
      Thus, when you need to use a different style, you might as
      well use C, as C++ would only be able to help you with the
      syntax of some constructs, if even that.

C++ is meant for OO programming. C is not. If you want OO, use C++. If
you don’t want OO, use C.
Personally, I’d take LISP or Smalltalk over either.

-John> On Tuesday 20 February 2001 22:27, Roger D. Vargas wrote:


Underfull \account (badness 10000) has occurred while \spend is active
John R. Hall - Student, Georgia Tech - Contractor, Loki Software

David Olofson wrote:

I have seen that SDL and most games are written in C and I’d like to
know if old C is more portable than C++.

C appears to be slightly more portable than C++ in real life, but this
shouldn’t be a significant problem these days. Most C++ compilers support
the ANSI standard fully, so you should be safe as long as you stick to
that.

HAH! That’s a good one.

Yeah, I know. :slight_smile:

However, as far as the language C++ is concerned, at least there is now a
standard, and most compilers tend to follow it. That is, it used to be far
worse than it is today…

However, despite the advantages of C++ for advanced OOP, there are quite a few reasons to stick with C, especially for Free/Open Source projects (some pure facts, some common opinions):
    * There are more hackers with a thorough knowledge of C.

Open source should be about fighting mediocrity and breaking damaging
trends, not embracing the status quo.

Yes, but a new language doesn’t necessarilly have that effect, especially not
if it scares people away with it’s complexity and great variety of popular
programming styles.

    * C has fewer constructs and thus fewer "low level"
      programming style options. That makes it easier to
      read anyone's C code and understand it.

Not if C is a misfit for the problem at hand. If you have to twist C to
fit a problem that would be better solved with C++, good C could easily
become as hard to understand and maintain as bad C++.

Of course; every problem needs the right tools for an optimal solution.

However, an application isn’t just about solving one problem - and
unfortunately, C++ doesn’t support all programming styles. Actually, it
appears to address a too narrow field of problems really good, that it’s just
too complex a tool to use for the average application.

You don’t use yacc/bison or similar to parse command line switches in a
program that doesn’t need parsing for anything else, do you? Still, they’re
great tools for writing various sorts of parsers.

    * The above also makes it harder to break the local style
      and design of a project. Mixing programming styles can
      make the code harder to read and maintain.

Uuh? It’s just as easy to break style parameters in C as in C++. I’ve
seen some REALLY bad and inconsistent C code… And I’ve also seen the
source to CivCTP and a few other large game projects, both in C and C++.
If you get enough impatient programmers in a room with a sufficient
amount of pizza and a difficult enough deadline, you can produce you
pretty damn poor code in any language.

Sure. I’m just not sure it’s as easy to sort C++ mess out as sorting a C mess
out.

    * C has less abstraction than C++, which makes it harder
      to misunderstand code that deals with structures/classes
      and custom data types. (No operator overloading, for
      example.)

WHAT?? Badly written C has less abstraction than well written C++.
That’s not inherent in the language.

Right; what I mean is just that there are many more ways in C++ to fool the
reader into thinking that the code does A while it does B.

Overloading operators in illogical ways is one example. It may have looked
cool to whoever did it, but it won’t be fun for whoever tries to follow the
code…

    * It's generally easier to write absolutely terrible C++
      code than it is to write bad C code.

If you saw some of the @#$% that the professors around here write for CS
homework assignments (as the provided code we have to work with), I
doubt you’d make any claim that bad C code is hard to write. (Geez,
you’d expect these people to be halfway competent programmers… They’re
teaching the CS classes!!)

I’ve learnt not to expect any teachers regardless of grade, to have any
practical knowledge of programming style and design at all. Some do, but
all too many seem to have no hands on experience with anything biger than a
few hundred lines… It’s a strange world. :slight_smile:

    * In C, it's harder to see levels of abstraction that may
      slow down you code. (Ex: Virtual function calls involve
      two pointer indirections, one being a pointer table look-up,
      and you can't even see that on the code! The corresponding
      C construct is a function pointer in a struct, which is
      to spot and keep track of, even without looking at the
      struct definition.)

You’ve mixed up C and C++; I’ll assume that’s a typo.

Yep… heh

If you know how the language works (which you should, if you aspire to
program in it), you’ll know how virtual function calls work, and how
they perform.

Well, that’s why I studied such thing. (I come from a massive 68k assembly
background, so I could hardly help being curious about what was actually
going on. Besides, I’m generally interested in complers and that kind of
technology. :slight_smile:

However, the general attitude among high level language programmers seems to
be that they shouldn’t worry about such things! Many don’t even know enough
about machine code and low level computer technology to have any idea what
the above means.

One may of course claim that such people should stay far, far away from
anything like performance critical code, but that just doesn’t seem to work.
:wink:

I’ll agree that C is a simpler language, but there’s a
reason for things like virtual functions;

Yep, and even though they can be abused to make the code hard to read,
they’re one of the nice and clean features of C++ I’m missing in C.

The point is just that when reading some code (for example something in an
inner loop), it’s not directly obvious that it is a virtual call, rather than
a direct call.

Not a big point, though; one should study performance critical code more
carefully than that, regardless of language.

Bjarne didn’t make them up for fun.

Of course not, and he did a good job. Not a universal tool for all kinds of
problems, though, as some seem to believe.

    * OOP doesn't really pay off for a project of a "sane" size
      and complexity. (Note: You *can* use the C++ features for
      other programming styles than OOP.) Most games aren't big
      or complex enough to warrant the use of OOP, and thus,
      don't really need C++.

That’s a fallacy.

Correction: I’m thinking more about the relatively simple games that most
Free/Open Source projects are about.

I wouldn’t say that a 3D game with physics, scripting system, a heavily
optimized engine etc, etc, is too simple for C++… OTOH, it’s probably too
complex for anyone who can’t be arsed to learn C++ properly. :slight_smile:

    * You *can* program in an object oriented fashion in C, and
      the level of OO you can achieve that way addresses most of
      the problems that people chose C++ to deal with.

If you’re going to use C like it’s C++, why not use C++ and let the
compiler’s optimizations, error checking, and the targetted syntax kick
in?

Good question. :slight_smile:

First, I’m not really using C like C++… For example, I’m not implementing
inheritance like C++ intends it to be used. Instead, I usually define a
single “interface” in the form of a struct, and then plug different functions
into it to form different versions of the “class”. The other, more obvious
thing, is that I’m using a naming convention and struct/code arrangement that
resembles C++ member function call syntax and class/member arrangement.
That’s about all there is to it, at least on the “visible” code level.

Second, I like my code to be easy to read, understand and reuse, just not for
me, but for others. That includes not (ab)using abstract interfaces as a
barrier, making it hard for people to understand what my code actually does.

As you might have noticed, code is almost considered documentation in the
Free/Open Source world, and there is little time and interest in commenting
code. The rule is to make the code clean and readable enough not to need a
significant amount of comments.

Besides, comments that describe what the code should do, rather than what it
does can be very dangerous! The same applies to interfaces. (Practical
experience…)

    * You can still use a C++ compiler to compile your C code,
      thus taking advantage of the stricter compile time checking
      that C++ compilers do.

-W -Wall -pedantic -Werror works nicely for C. C++ compilers are made to
compile C++.

Yep, but C++ compilers have stricter type checking. Even with all those
switches, gcc can’t be made to detect errors that g++ catches right away.

    * OOP is not "simply better" or "superior" to all other
      programming styles, but it is indeed very useful for some
      things. However, the C++ features are basically designed
      *only* for OOP, while ignoring other programming styles.
      Thus, when you need to use a different style, you might as
      well use C, as C++ would only be able to help you with the
      syntax of some constructs, if even that.

C++ is meant for OO programming. C is not. If you want OO, use C++. If
you don’t want OO, use C.

Most languages can be programmed in a slightly more object oriented fashion
than they’re originally designed for without problems, and it really helps
keeping track of what belongs where, and making the code readable.

It worked for assembler when I tried it; reduced the number of “pointer to
wrong object” kind of errors to almost zero for me, which is why I still
think it’s a pretty good idea to do it with a weakly typed language like C.

Anyway, all that has nothing to do with inheritance, polymorphism etc…
(Some would even claim that if you don’t use those, it’s not OOP at all.)
It may just be that I’ve stepped back entirely from the programming style
generally called OOP, which would explain why C++ isn’t my favourite tool.

Maybe it’s time I went out looking for another language… :slight_smile:

Personally, I’d take LISP or Smalltalk over either.

Well, C++ has the major problem of still supporting C style code, and C isn’t
even a high level language. However, I’ve already mentioned that most
programs need to solve more than one problem…

//David

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------> http://www.linuxaudiodev.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |--------------------------------------> david at linuxdj.com -'On Wednesday 21 February 2001 03:46, John R. Hall wrote:

On Tuesday 20 February 2001 22:27, Roger D. Vargas wrote:

You know really it’s up to the coder to ensure that their compiler is
compliant. So while there are many that aren’t, the coder still has a choice
(yes, even in the proprietary world) as to whether to use the non-standard ones
or extensions or not.

So while you might not be able to say “most” C++ compilers are compliant, you
can say that you can easily find one that is.

(and you’re right, it is /much/ better today than it was! I still real from
when my old Turbo C from CP/M to DOS ports! And that was using supposedly
the same compiler!)On Tue, 20 Feb 2001, you wrote:

On Wednesday 21 February 2001 03:46, John R. Hall wrote:

David Olofson wrote:

C appears to be slightly more portable than C++ in real life, but this
shouldn’t be a significant problem these days. Most C++ compilers support
the ANSI standard fully, so you should be safe as long as you stick to
that.

HAH! That’s a good one.

Yeah, I know. :slight_smile:

However, as far as the language C++ is concerned, at least there is now a
standard, and most compilers tend to follow it. That is, it used to be far
worse than it is today…


Sam “Criswell” Hart <@Sam_Hart> AIM, Yahoo!:
Homepage: http://www.geekcomix.com/snh/
PGP Info: http://www.geekcomix.com/snh/contact/
Advogato: http://advogato.org/person/criswell/

David Olofson wrote:

I have seen that SDL and most games are written in C and I’d like to
know if old C is more portable than C++.

C appears to be slightly more portable than C++ in real life, but this
shouldn’t be a significant problem these days. Most C++ compilers support
the ANSI standard fully, so you should be safe as long as you stick to
that.

HAH! That’s a good one.

Yeah, I know. :slight_smile:

However, as far as the language C++ is concerned, at least there is now a
standard, and most compilers tend to follow it. That is, it used to be far
worse than it is today…

Personally however, I feel that C++ is a bloated language. Even Bjarne
Strostrup himself admits that “inside of C++ there is a small, clean
language struggling to get out.” We have all of these complications that
are not really necessary to add classes to C: parametrized types, operator
overloading, etc, etc, and so on ad nauseam. Recently I ran into a new OO
language called Limbo being developed at Lucent/Bell Labs by none other
than Brian W. Kernighan, Dennis Ritchie, and other people at the Computing
Sciences Research Group there, as part of their Inferno OS. I’ve had a
look at the language specification (you can see it at
http://inferno.lucent.com/inferno/limbo.html) and it seems pretty small
and clean. One of these days someone may write a GCC backend for it
provided there are none of those stupid IPR roadblocks in the way!

Sorry for adding fuel to the language war fire!On Wed, 21 Feb 2001, David Olofson wrote:

On Wednesday 21 February 2001 03:46, John R. Hall wrote:

On Tuesday 20 February 2001 22:27, Roger D. Vargas wrote:


Rafael R. Sevilla <@Rafael_R_Sevilla> +63 (2) 4342217
UP Diliman Mobile Robotics Laboratory +63 (917) 4458925
OpenPGP Key ID: 0x0E8CE481

David Olofson wrote:

I have seen that SDL and most games are written in C and I’d like
to know if old C is more portable than C++.

C appears to be slightly more portable than C++ in real life, but
this shouldn’t be a significant problem these days. Most C++
compilers support the ANSI standard fully, so you should be safe as
long as you stick to that.

HAH! That’s a good one.

Yeah, I know. :slight_smile:

However, as far as the language C++ is concerned, at least there is now
a standard, and most compilers tend to follow it. That is, it used to be
far worse than it is today…

Personally however, I feel that C++ is a bloated language. Even Bjarne
Strostrup himself admits that “inside of C++ there is a small, clean
language struggling to get out.”

That’s exactly my feeling about it!

That’s what “C+” would be; take C++ and remove the requirement that (almost)
any C program is a valid C++ program. Then forbid the constructs of both
languages that cause most of the obscure run time bugs. (Anything that can be
caught at compile time is no issue whatsoever, IMHO.)

This still doesn’t cover “exotic” programming styles outside the procedural
and OO domain, but it could be a great deal better than C, while not bringing
all the “bloat” from C++ in.

We have all of these complications that
are not really necessary to add classes to C: parametrized types, operator
overloading, etc, etc, and so on ad nauseam. Recently I ran into a new OO
language called Limbo being developed at Lucent/Bell Labs by none other
than Brian W. Kernighan, Dennis Ritchie, and other people at the Computing
Sciences Research Group there, as part of their Inferno OS. I’ve had a
look at the language specification (you can see it at
http://inferno.lucent.com/inferno/limbo.html) and it seems pretty small
and clean. One of these days someone may write a GCC backend for it
provided there are none of those stupid IPR roadblocks in the way!

Sounds interesting. However, there is always this issue with “legacy
standards” and people unwilling to accept change.

In real life, my guess would be that, at least in a short perspective (10
years or so), the best bet is to clean up C++ - not trying to get people to
learn an entirely new language. However, if it’s small, nice and easy enough
to grasp, while still providing both the low level and the high level power
of C and C++, it might stand a chance.

//David

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------> http://www.linuxaudiodev.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |--------------------------------------> david at linuxdj.com -'On Wednesday 21 February 2001 18:35, Rafael R. Sevilla wrote:

On Wed, 21 Feb 2001, David Olofson wrote:

On Wednesday 21 February 2001 03:46, John R. Hall wrote:

On Tuesday 20 February 2001 22:27, Roger D. Vargas wrote: