Re: New release of the Dynace OO extension to C
bartc wrote:
"Juha Nieminen" <nospam@thanks.invalid> wrote in message
Consider this small program:
//----------------------------------------------------------------------
#include <algorithm>
int main()
{
int table1[] = { 5, 3, 10, 35, 4, 1, 40, 1, 8, 3 };
double table2[] = { 20.2, 24.6, 12, 1, -4.2, 5.5, -20, 20.2, 1,
0 }; std::sort(table1, table1 + 10);
std::sort(table2, table2 + 10);
// print the tables here, or whatever
}
//----------------------------------------------------------------------
Even though the standard C library also provides a sorting utility
(qsort), consider how much more code you have to write in order to
use it. (Also consider how much more inefficient it will be
because of that.) Exactly what is so "ghastly" and
"incomprehensible" here? To me
this looks very simple and straightforward (well, assuming you
understand what "table1 + 10" means, but that should be rather
obvious to an experienced C programmer). Definitely much simpler
than the equivalent C program.
Like I said, you make an excellent case for C++. Maybe you should
write a book.
I first came across C++ source when trying to decode MFC header
files, and decided they weren't designed to be understood by a mere
human (possibly they weren't).
That is generally considered horrible C++ code, partly because it
wants to be compatible with ancient pre-standard extensions used to
code Windows 9x and even Windows 3.x.
No-one understands that code. Not even Microsoft!
More typical C++ does still appear much more intimidating than your
simple example (some of us just can't grok classes and object
hierarchies and what-not).
I understand that much of the power of C++ is the ability to define
all these neat extensions and datatypes, and make them appear as
though they are built-in to the language.
The trouble is the language used for defining them (with the
necessary bells and whistles) is the same language used for
everyday programming, with considerable cross-over. It seems like a
language-implementation language, used as it's own language, if
that makes sense..
That's not the trouble, that's the beauty of the language. :-) It is
entirely by design that many standard features are described with a
library interface, using core language features that are available to
everyone. No magic involved!
This means that you and I can also write code like what's in the
standard library, without first having to be a compiler writer. That
is extremely useful!
Bo Persson