C vs. C++

T

Tomás Ó hÉilidhe

More is less. More complexity is less usability. More features make
complexity grow, and it is non linear. If you add <n> features, you
get <n squared> complexity increase.


My point though is that if you want to stick to the "C features", then
you're free to. If you don't like the way templates are implemented in
C++ then don't use them.

I'm more of a procedural programmer; for instance at the moment I'm
working on a network penetration testing program and I'm writing it in
C. I'm happy to say that so far I haven't wanted for any of C++'s new
features.

However about three years ago, as a little hobby project, I wrote a
program to write out a cheque's value in human-readable language. For
instance, if the check was for $7.83, then my program would give
"Seven dollars and eighty three cents". I also had it writing out
German and Irish. There came a point where I realised that some
languages had a lot of things in common. So then I built a class
hierarchy:

Languages
|
/ \
Languages_Like_English Irish
|
/ \
English German

I had code written for "Languages_Like_English", and then I had more
specific code written for "English" and "German". The more specific
code was virtual functions.

And from that I reused a lot of my code. Now of course I could have
done this in C, but the solution in C++ was way more elegant and took
way less time. Plus it was nice not to have to play around with my own
V-Tables and so forth.

But anyway, back to my networking program. Even though I was doing
procedural programming and could use a C compiler, if there came a
point where I thought hmmm it'd be handy to have a template here, it
would have been handy to be using a C++ compiler.
 
G

Guest

Apparently you are using a different version of g++.

Then, we notice that all three compilers give different errors.

whilst I broadly agree with your point that C is a simpler
language than C++ (and hence refute hEilidhe's point that
"C++ is inherently better than C"); I'm not sure this is a good
example of it. I suspect a siutably convoluted bit of C
could give widely diverging diagnostics on different compilers.
Once a compiler "looses its place" the diagnostics get more and
more odd.

I was told by one compiler implementor that some particular
bizzare behaviour of his compiler was due to "the compiler
has run out of cup hooks to hang the cups on"
 
C

Chris M. Thomasson

jacob navia said:
This is wrong.

For instance

EXHIBIT 1
---------

template<class T, int ndims>
class NFieldBase {
public: static const T max;
};

template<int ndims> const float NFieldBase<float, ndims>::max = 1.0f;

When compiled with g++, I get this error:

test.cpp:7: error: template definition of non-template ‘const float
NFieldBase<float, ndims>::max’


(1) Why do I get this error?

(2) How do I fix it?


You see?

More is less. More complexity is less usability. More features make
complexity grow, and it is non linear. If you add <n> features, you
get <n squared> complexity increase.


try something simple like:


template<typename T, int ndims>
class NFieldBase {
public: static const T max;
};

template<typename T, int ndims>
const T NFieldBase<T, ndims>::max = 1;


template<int ndims>
class NFieldBase<float, ndims> {
public: static const float max;
};

template<int ndims>
const float NFieldBase<float, ndims>::max = 1.0f;
 
R

Richard

William Hughes said:
Program in a simple language of course.

- William Hughes

I'll ask again. What can you do in C that can not be done in C++?

It's a serious question.
 
W

William Hughes

I'll ask again. What can you do in C that can not be done in C++?

It's a serious question.

Program in a simple language. It's a serious answer.
Programming in C++ but only using a subset of the features
may be similar but it is certainly not identical.

- William Hughes
 
D

Dik T. Winter

> I'll ask again. What can you do in C that can not be done in C++?
>
> It's a serious question.

Of course it is not such a serious question, because presumable both
languages are Turing complete.
 
B

Bartc

Tomás Ó hÉilidhe said:
However about three years ago, as a little hobby project, I wrote a
program to write out a cheque's value in human-readable language. For
instance, if the check was for $7.83, then my program would give
"Seven dollars and eighty three cents".

That's a nice little exercise. Took about 25 minutes (because a few bugs
crept in).

But I used my own rapid development language. C++ would be the last language
I would use. In general this sort of thing is suitable for Python or Ruby
(maybe Perl) (and in all likelihood there would already be a library
function for it).
I also had it writing out
German and Irish.

Yeah, I was going to make it write in Italian (my other language), but the
syntax for the numbers is about the same as English.
I had code written for "Languages_Like_English", and then I had more
specific code written for "English" and "German". The more specific
code was virtual functions.

And from that I reused a lot of my code. Now of course I could have
done this in C, but the solution in C++ was way more elegant and took
way less time.

Actually my code would convert effortlessly into C (once I'd already got it
working).
Plus it was nice not to have to play around with my own
V-Tables and so forth.

I would have problems with a language as full of incomprehensible jargon as
C++. (And when I find out what this stuff can do, it's what I've been doing
for years with one of my dynamically typed languages, without even thinking
about it. Although C++ can probably do it faster.)
 
R

Richard

William Hughes said:
Program in a simple language. It's a serious answer.
Programming in C++ but only using a subset of the features
may be similar but it is certainly not identical.

So which "simple" program in C can you not compile with C++? And please
don't use specific headers - that is not "simple".
 
J

jacob navia

Richard said:
So which "simple" program in C can you not compile with C++? And please
don't use specific headers - that is not "simple".

Of course you can program in C using a C++ compiler but that is not the
point.

You are not using C++ then, and we all agree. C++ CAN be simple if you
do not use it... :)

What I wanted to say with my posting is that the complexity of a
language is not a measure of a better language but of a worst
language. I presented several examples of the type of complexities
C++ programmers are confronted with, and I suggested that if some
simple constructs can't be determined as correct or wrong by
inspection by experts then the language needs a compiler to know what
is correct and not correct. The language is no longer readable.

For instance, reading the C++ specifications for matching an overloaded
operator needs a topological sort of the whole class structure to
know what will be called.

There are only a relatively small supply of people that can do the
sorting in their heads and see immediately what will be called
and what can't be called.

I think a *simplification* is needed, and this simplification
could be very well some kind of augmented C.

If you look critically into the language, it is impossible to avoid the
conclusion that C++ has been unable to set the limits to the extensions
it supports, making it a monster language nobody fully understands.
 
R

Richard

jacob navia said:
Of course you can program in C using a C++ compiler but that is not the
point.

You are not using C++ then, and we all agree. C++ CAN be simple if you
do not use it... :)

Which was my point. It is as simple to use C++ as it is C if *you so
wish*.
 
R

Richard

Laurent Deniau said:

You (and I) lost the word "Simply".

If you want to write a SIMPLE program in C, please demonstrate such that
can not be done as simply in C++.

It seems a simple enough question/request.

FWIW, I use C for most things since the "powerful" features of C++ are
not needed most of the time. And I hate C++ inheritance with a passion.

But the question remains.
 
W

William Hughes

So which "simple" program in C can you not compile with C++?

I don't know of any significant examples for new programming
(there are differences of course, serious enough to make converting
from C to C++ non-trivial). But the fact that a simple C program
can be compiled by C++ compiler does not make programming in
a subset of C++ substantially identical to programming in C
(consider e.g. errors from the compiler, format of object files,
portability, standardization of the allowed subset, etc .).

Are the problems of practical importance? Do the extra features
of C++ dominate these? I take no position. I merely note that the
argument,
"C++ is C with more features therefore it is necessarily better",
is simplistic.

- William Hughes
 
R

Richard

William Hughes said:
I don't know of any significant examples for new programming
(there are differences of course, serious enough to make converting
from C to C++ non-trivial). But the fact that a simple C program
can be compiled by C++ compiler does not make programming in
a subset of C++ substantially identical to programming in C

I never said it was identical.

The question still stands.
 
G

Guest

Which was my point. It is as simple to use C++ as it is C if *you so
wish

this approach works if you only have to read your own code.
If you have to read other people's code then you *have*
to know the whole language. This is reasonable in C,
most experienced C programmers know pretty much the whole
language[1]. It's a *lot* harder to learn nearly all
of C++ (I know I've tried).


[1] I know all of C except for C99, signal.h, setjump.h, iso646.h
locale.h, most of math.h, wchar.h and volatile.


--
Nick Keighley

"Programming languages should be designed not by piling feature
on top of feature, but by removing the weaknesses and
restrictions that make additional features appear necessary."
The revised... report on Scheme
 
W

William Hughes

I never said it was identical.

I.e. progamming in a subset of C++ is not programming in a
simple language.
The question still stands.

Question: What can you do in C that can not be done in C++?

Answer: Program in a simple language.

Note, you have agreed that programming in a subset of C++ is not
programming in a simple language.

- William Hughes
 
R

Richard

this approach works if you only have to read your own code.
If you have to read other people's code then you *have*
to know the whole language. This is reasonable in C,

I don't know what you are talking about here to be honest. Since
something simple I am assuming we are writing in C and then compiling
withe C++ compiler. Sure there might be some tinkering but was is not
"simple" about it?

The question is "What can you do in C that you can not do as simply in
C++". It is not "can one compile the same code".

e.g

write a reverse string function

Now, can that be done more simple in C than in legal C++?
most experienced C programmers know pretty much the whole
language[1]. It's a *lot* harder to learn nearly all
of C++ (I know I've tried).

And that language is pretty much a subset of C++.

The question remains. Keeping in mind that most C will "just compile"
with a C++ compiler too and not take that tangent.

What features of C are "simpler" than the equivalent in C++?
[1] I know all of C except for C99, signal.h, setjump.h, iso646.h
locale.h, most of math.h, wchar.h and volatile.


--
Nick Keighley

"Programming languages should be designed not by piling feature
on top of feature, but by removing the weaknesses and
restrictions that make additional features appear necessary."
The revised... report on Scheme
 
R

Richard

William Hughes said:
I.e. progamming in a subset of C++ is not programming in a
simple language.

You seem intent in rewriting the question. I never said the complete C++
was a simple language. Sigh. I need to repeat the question to you again:

What can you program in C that you can not program as simply in C++?
Question: What can you do in C that can not be done in C++?

Answer: Program in a simple language.

Note, you have agreed that programming in a subset of C++ is not
programming in a simple language.

I have? You have moved the goalposts to apply "simple" to the entire
language. Not me.

You seem intent in throwing spanners in here so I will quote what I
wrote above once more:

,----
| >> >> So which "simple" program in C can you not compile with C++?
`----

or, to clarify once more, which program can you write in C that you can
not write as simply in C++?
 
W

William Hughes

I have? You have moved the goalposts to apply "simple" to the entire
language.

Indeed, that is precisely the point. The entire language exists,
and if you program in it its features
have effects, even if you do not use them. You can write a simple
program in C++, you cannot program in C++ and program in a simple
language.

- William Hughes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,200
Latest member
LaraHunley

Latest Threads

Top