Re: why learn C?





Markus E Leypold <development-2006-8ecbb5cc8aREMOVETHIS@xxxxxxxxxxxxxxxxxxxxx> writes:

"kevin cline" <kevin.cline@xxxxxxxxx> writes:

On Mar 29, 10:09 pm, "Steve" <nospam_steve...@xxxxxxxxxxx> wrote:
"kevin cline" <kevin.cl...@xxxxxxxxx> wrote in message

news:1175215906.645110.217810@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx



On Mar 20, 12:37 pm, <adawo...@xxxxxxxxxxxxx> wrote:
"Marc Boyer" <Marc.Bo...@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message >

It has always seemed rather odd to me that people who are as intelligent
as programmers, rarely question the silliness of using tools such as C
and C++ for serious work.
They simply take for granted that the kind
of errors that are so common in those languages are somehow akin to
the laws of nature.

No, what actually happened is that expert C++ developers learned to
use C++ in such a way that those errors can not happen. While it is
possible to write unsafe code in C++, it is also possible to adopt
coding guidelines that makes it easy to find and eliminate unsafe
code, and for most applications, that's quite good enough. One reason
that experts choose C++ over Ada for performance-critical applications
because C++ templates allow compile-time type safety in high-level
code in a way that Ada generics do not.

Please give an example of one case where a C++ template gives more compile
time safety than an Ada generic. I have found just the opposite to be true.

Christopher Grein covered the topic thoroughly here: (http://home.t-
online.de/home/Christ-Usch.Grein/Ada/Dimension.html)

On attempts to achieve compile-time checking of physical units
computations in Ada, he wrote:

"Our attempt leads us to a plethora of overloaded functions. The
number of function definitions afforded runs into the hundreds... So
we have to confess that our attempt to let the compiler check
equations at compile time has miserably failed."

"The big difference is that C++ templates allow type checking during
compile-time, so that no overhead neither in memory space nor in
runtime is incurred. In this respect, C++ templates ARE MORE POWERFUL
than Ada generics."

Ada gives you low-level type safety out of the box, but does not
afford the tools necessary to achieve type-safety in high-level
programming.

I'm inclined to shout nonsense here: You people tend to mistake a type
system for a proof system on the correctness of your program. That are
two different things. Type safety is to avoid execution errors (once
again see Cardelli's introduction into type systems), whereas a type
system is hardly ever powerful enough to proof interesting things
about the correctness of your code -- so if you start proofing
correctness you can well start with a simple, but safe type system and
handle pre- and post-conditions completely in your proof system (that
also applies to subrange types and this kind of stuff).

(And yes that critique also applies to Ada subtyping to a certain
extend.)

Low-level C++ coding is not type safe, but C++ provides
powerful mechanisms to write high-level type-safe code.

That's a bit like saying, "I can write type safe code in C". The point
is, I might be able to write safe code in C, but type safe is an
attribute applying to a language (NOT a single instance of code) and
means that if the type checks are passed, the code is safe with regard
to execution errors (execution errors as defined in Cardelli's paper
again: That are error that bring the program into "undefined states"
or "invoke undefined behaviour" (hello, comp.std.c, can you hear me
:-)))).

The definition allow show that "this piece of code is type safe" makes

Should've been: "The definition also shows ..."

no sense, and that saying "I can write type safe code by keeping to
certain rules" makes hardly sense also, since it's the very essence of
type safety that it's the type checks that are the litmus test wether
you stuck to the rules or not.

Regards -- Markus
.



Relevant Pages

  • Re: why learn C?
    ... code in a way that Ada generics do not. ... Please give an example of one case where a C++ template gives more compile ... Ada gives you low-level type safety out of the box, ... "I can write type safe code in C". ...
    (comp.lang.ada)
  • Re: Packages private parts and protected types
    ... longer be the body (such as misspelling the name, or misspelling "body"), ... build systems don't compile random files that aren't needed. ... But the so-called "solution" in Ada 95 didn't actually solve anything. ... private part in a separate file. ...
    (comp.lang.ada)
  • Re: C++/cmake project, injecting Ada...
    ... C++ based, using cmake for building. ... throwing Ada into this mix without disrupting ... Just drop all advantages of gprbuild dependency management, and compile ... cmake projects which build many intermediate libraries. ...
    (comp.lang.ada)
  • Re: Using GNAT in a C and assembly toolchain
    ... compiled and linked with the established tool chain (GHS C, not Ada). ... variables to access the hardware abstraction layer. ... which is then passed to GHS for assembling and linking ... Would this mean I would need the compile Ada modules ...
    (comp.lang.ada)
  • Re: GdMs DOS 3d engine in Ada
    ... compile on. ... anybody can get the latest DOS 3D engine here: ... low level things like keyboard & sound drivers, data streaming, ... Linux to DJGPP cross-compiler and run into trouble with Ada. ...
    (comp.os.msdos.djgpp)