C or C++ something else....

W

Walter Bright

Greg said:
My experience is that that is not always the case.

That's an extraordinary claim, especially since C++ is a superset of C.
How could it take less time?
Probably neither of us can prove either way though.

Providing proof and being convincing are two different things said:
For those who don't realize, probably still won't realize
under other, probably more by-hand involved, alternatives.

I've always figured out how languages worked by figuring out what needed
to happen under the hood. I admit to having a hard time seeing how one
can effectively use them without such knowledge.
 
K

Kai-Uwe Bux

Walter said:
That's an extraordinary claim, especially since C++ is a superset of C.
How could it take less time?

One mechanism at work is idioms: for many things, C++ offers a different
approach. To master C++, you do not need to know what the best way of doing
X in the C subset is.


[snip]

Best

Kai-Uwe Bux
 
W

Walter Bright

Kai-Uwe Bux said:
One mechanism at work is idioms: for many things, C++ offers a different
approach. To master C++, you do not need to know what the best way of doing
X in the C subset is.

You might be able to get a C++ program working, but you haven't mastered
C++ if you haven't mastered C. For one thing, writing C++ in the real
world also means working with C: C libraries, C system interfaces, etc.

Maybe we're talking different things, here. I know lots of people who
have mastered C - they rarely if ever need to consult the spec, they
know the entire language including corners and nasty surprises. How many
people know C++ that well? Heck, I wrote a C++ compiler and I still have
to go and check the spec, and I still get surprised. I get emails from
well known C++ experts sending me snippets of code wondering if they are
valid C++ code or not. I don't get those for C. Some people, like Scott
Meyers, have made a career out of helping people understand C++. Where
are the equivalent C gurus if C is as difficult?

It's reasonable to master C code in a year or two. Give it 5 years at
least for C++.
 
I

Ivan Vecerina

: Walter Bright wrote:
: > Greg Comeau wrote:
: >> Walter Bright wrote:

: >>> It takes many more years to master C++ than C.

: >> My experience is that that is not always the case.
: >
: > That's an extraordinary claim, especially since C++ is a superset of
C.
[ NB: not quite a superset, but let's not go back to this ]
: > How could it take less time?
:
: One mechanism at work is idioms: for many things, C++ offers
: a different approach. To master C++, you do not need to know
: what the best way of doing X in the C subset is.

Agreed.
Yet the list of things a proficient C++ developer needs to learn
to proficiently write C code is probably not too long.

Just out of personal curiosity, as a "native" C++ developer,
here's the list of things I find I need to do differently
when writing pure C code:
- "syntactic" differences (struct namespace, void*-to-T* conv.).
- learning "stdio.h" in-depth (formatted input & output especially),
and other library functions (e.g. the <math.h> "overloads").
- malloc+memset, encapsulation using handles/hidden pointers,
and conventions for transfer of object/pointer ownership.
- error handling without scoped resource management:
return codes, benefits of SESE. (Hoping I won't need longjmp!)
- Features brought by C99: _Bool, runtime-sized arrays, init-lists,...
- preprocessor tricks to simulate templates etc ?

For my own education, I'd be interested in hearing what others
have to say about what a good C++ developer needs to learn when
switching to writing C code.

Any advice or recommendations from C gurus ?

Ivan


NB: I took the liberty to cross-post comp.lang.c. But this is not
about comparing the values of the languages -- no flames please !!
 
K

kwikius

Ivan said:
For my own education, I'd be interested in hearing what others
have to say about what a good C++ developer needs to learn when
switching to writing C code.

How to ride a unicycle :)

And for C++ how to drive a Formula 1 car.

Vroom, Vroom :)

regards
Andy Little
 
R

Richard Heathfield

kwikius said:
How to ride a unicycle :)

Why? What possible advantage does it confer?

No, when switching to C, a good C++ developer needs to learn all about how
to re-use code. That is the heart of C.

And for C++ how to drive a Formula 1 car.

C++ programmers don't drive; they derive.

Whoever cross-posted this was asking for trouble, whether they realised it
or not.
 
K

kwikius

Richard said:
kwikius said:


Why? What possible advantage does it confer?

No, when switching to C, a good C++ developer needs to learn all about how
to re-use code. That is the heart of C.



C++ programmers don't drive; they derive.

Whoever cross-posted this was asking for trouble, whether they realised it
or not.

hmmm.... better add: lose your sense of humour, to the list of
attributes a C++ developer needs when switching to C I guess!

:)

regards
Andy Little
 
R

Richard Heathfield

kwikius said:
hmmm.... better add: lose your sense of humour, to the list of
attributes a C++ developer needs when switching to C I guess!

If you didn't find my reply amusing, you've already lost it. Read it again,
this time with your brain switched on.
 
K

kwikius

Richard said:
kwikius said:


If you didn't find my reply amusing, you've already lost it. Read it again,
this time with your brain switched on.

The most amusing thought I had was of all the C programmers cycling to
work. :)

regards
Andy Little
 
K

kwikius

kwikius said:
The most amusing thought I had was of all the C programmers cycling to
work. :)

And you should appreciate that there is a great deal of skill involved
in riding a unicycle.

but I guess I'd better leave it at that .

Its always a mystery to me why some people prefer C over C++, but they
obviously do, and I have no problem with that. Live and let live I say.

regards
Andy Little
 
I

Ivan Vecerina

: Its always a mystery to me why some people prefer C over C++, but they
: obviously do, and I have no problem with that. Live and let live I
say.

You may once need to provide a stable and portable ABI, and realize
that, on most platforms, it is not possible to do so with a C++
interface.
Of course I would then still implement the library in C++, and provide
a thin C-style interface wrapper (with opaque handles etc).

You may want to contribute code to a project (such as the Linux
kernel) that does not leave you the option of using C++.

You may be developing code for a small embedded microcontroller
with 4k of RAM, for which only a C compiler is available.


I am not in any of these situations right now,
yet I thought this could be a legitimate question...

Ivan
 
B

Bo Persson

Ivan said:
You may want to contribute code to a project (such as the Linux
kernel) that does not leave you the option of using C++.

You may be developing code for a small embedded microcontroller
with 4k of RAM, for which only a C compiler is available.

That's not "prefer to", that's being "forced to" use C.

If I have to chose between C and C++, and there is only a C compiler
available, C is my first choice. Otherwise it is not.


Bo Persson
 
K

kwikius

Ivan said:
: Its always a mystery to me why some people prefer C over C++, but they
: obviously do, and I have no problem with that. Live and let live I
say.

You may once need to provide a stable and portable ABI, and realize
that, on most platforms, it is not possible to do so with a C++
interface.
Of course I would then still implement the library in C++, and provide
a thin C-style interface wrapper (with opaque handles etc).

You may want to contribute code to a project (such as the Linux
kernel) that does not leave you the option of using C++.

You may be developing code for a small embedded microcontroller
with 4k of RAM, for which only a C compiler is available.

But all these reasons are because you have no choice.

Actually the unicycle analogy is quite apt:

- You have to concentrate on all the details all the time.
- It's very esay to fall off.
- You take a long time to get anywhere.

regards
Andy Little
 
S

Steve Pope

Phlip said:
Walter Bright wrote:
That suggestion works both ways. C makes an endless range of trivial
operations (string copy, polymorphic collections, callbacks) absurdly hard.
So the more C++ techniques you use, the easier your code gets, and the more
crew you can use.

I've heard estimates that it takes 6 months for a typical C
programmer to come up to speed on C++, and 12 months to be
any sort of expert.

However, some of the most basic features of C++ -- plain classes,
namespaces, overloading, basic STL features like vector and map, and
(perhaps) references -- can be learned in a matter of weeks and make
the language vastly more usable than C. Stroustrap's advice was
to not try to learn the whole language before starting to use
it productively. (And he said this back when the language was
smaller than it is now...)

Steve
 
G

Greg Comeau

You might be able to get a C++ program working, but you haven't mastered
C++ if you haven't mastered C. For one thing, writing C++ in the real
world also means working with C: C libraries, C system interfaces, etc.

Maybe we're talking different things, here. I know lots of people who
have mastered C - they rarely if ever need to consult the spec, they
know the entire language including corners and nasty surprises. How many
people know C++ that well? Heck, I wrote a C++ compiler and I still have
to go and check the spec, and I still get surprised. I get emails from
well known C++ experts sending me snippets of code wondering if they are
valid C++ code or not. I don't get those for C. Some people, like Scott
Meyers, have made a career out of helping people understand C++. Where
are the equivalent C gurus if C is as difficult?

It's reasonable to master C code in a year or two. Give it 5 years at
least for C++.

Well, I could claim that about what you've said, but won't.

I know people who have claimed to learn C and other to learn
C++ "in a day". Of course, no such thing occurred.

Furthermore, IMO, nobody ever learns all of both languages.
Both you and I are in the C and C++ compiler business and
I bet both of us don't know all of C or C++. I will even
say that I bet you do not know all of D even though it is
your baby (for instance, I'll bet people send you code that
you either go Ugh to or Wow to because you never thought of
it before, etc). But I don't think that's what we're talking about.

I also personally believe that programming take a lifetime.
I certainly learn more about it each year. But I also think
that's different mastering than being discussed, although it
is in line for it.

Those things said:
In my experience it takes the average C beginner about 6 months
to *start* to be able to move with a swagger. And that it
takes about 9 months for C++. Also, as that is the average,
it might take some C programmers a year, and some C++ programmers
5 months, and so on. Also, it does not have to continue at
that same pace.

It also depends upon whether they are a complete newbie to
programming or not. For instance, somebody who already knows
Ada would not have some of the same concerns as somebody
who already knows COBOL, or against somebody who knows nothing
at all.

Intuition tells us what I've claimed makes no sense. But it's
not much different from some of the original claims about C++:
for instance, that because it was bigger than C, that it HAD
to be slower. That's not a generalism because the sum of the
parts is not always the same as the sum of the whole. I think
that we have a similar situation here.

Many claim that C++ is not a superset of C, and so many find
your claim that that is the case to be an extraordinary claim.
Personally if I had to choose I would say it is, but I also
acknowledge that there is some wiggle room here (actually more
than that, there is common ancestry but there is also different
approaches even on some of the so-called common parts).
And either way, the overlap becomes critital.
IOWs, a C++ programmer does not always learn "the C part of C++"
in isolation. Often it occurs in unison.

And no, that does not necessarily make them a C programmer too
in the end. Ironically though (again, intuition tells us otherwise,
often wrongly), many C++ programmers find that it makes them
better C programmers (not necessarily on the same issues).
Whatever it is about the culture and mindset I think is significant
here. For instance, I believe that many C++ programmers end
up understanding pointers better. I also believe that many
C++ educational approaches (for instance books) do a better job
at explaining concepts and techniques than their "equivalent"
C approaches which focus more on language. This also ripples
into other areas because although one can do many of the
techniques in C, there are not direct constructs through which
to do them with that are naturally supported by C. This lends
to a reverse learning kind of situation which the knowledge
becomes leaked in the C++ programmers case to the C++ side.

Also, despite C being around longer, and on more platforms,
it still has a limited and too low level standard library.
I find both C and C++s libraries daunting but at the same time
always expect that more can be added (which normally goes
against my default design constraints). This can pretty much
puts lots upside down when C++'s more high level library can
come into play.

On a personal level, I knew many languages before I knew C.
And I've always said I've had to learn C 3 times.
Against many other larger languages, I think I had the hardest
time with C. And I think some of the same issues fall out when
C++ is considered even though it is clearly larger and more
complicated. And certainly many of C++ problems are shared
not only by C but literally with C.

BTW, I also think there is biased picked up with people learn
programming languages. For instance many C programmer's style
might be influeced by K&R, and contrary issues might be influenced
by Stroustrup, and so on. I don't think that's just a neutral
issue or even just language cultural issue.

Re master C programmers, most of the master C programmers
I know do consult the spec. And I think saying they know all
corners, the entire language, and all nasty surpriseds would
be extraordinary. I think I know C well, but probably would
not make that claim about myself so maybe we are talking about
different things somehow. I agree many people know many of
the issues though, but probably not enough.

Despite being in the C++ compiler and other related businesses
I too find myself checking the C++ standard often, and as well
often being surprised. But despite being in the C compiler and
other related businesses, I also find that I need to check the
C standard too, and that often I'm surprised with it too.

So, in conclusion, it's reasonable to master both in about
the same time. There's too many issues on the table to say
otherwise anyway. I know in my own case that I knew an awful
lot about C in a year, and had written 100s of KLOC and large
apps in C and other languages at that point, but I think I would
be kidding myself to say I was a master C programmer at that point,
even though I probably thought I was.
 
G

Greg Comeau

You may be developing code for a small embedded microcontroller
with 4k of RAM, for which only a C compiler is available.

Well, it ain't C99 and not C90 either, so usually,
that's actually some subset of C with extensions.
 
G

Greg Comeau

That's not "prefer to", that's being "forced to" use C.

If I have to chose between C and C++, and there is only a C compiler
available, C is my first choice. Otherwise it is not.

I think an underlying point being made was that C is available for
more platforms etc, but that's not the way it came out.
 
G

Greg Comeau

I've heard estimates that it takes 6 months for a typical C
programmer to come up to speed on C++, and 12 months to be
any sort of expert.

However, some of the most basic features of C++ -- plain classes,
namespaces, overloading, basic STL features like vector and map, and
(perhaps) references -- can be learned in a matter of weeks and make
the language vastly more usable than C. Stroustrap's advice was
to not try to learn the whole language before starting to use
it productively. (And he said this back when the language was
smaller than it is now...)

The early estimates (see my post) could be reasonable,
but the master one need more time for both languages
and at that point it's a leapfrogging situation for both
languages anyway.
 
?

=?ISO-8859-15?Q?Juli=E1n?= Albo

Greg said:
I know people who have claimed to learn C and other to learn
C++ "in a day". Of course, no such thing occurred.

#include <stdio.h>
int main ()
{
puts ("Hello");
}

#include <iostream>
int main ()
{
std::cout << "Hello\n";
}

I did it! And both at the same time!

I don't learned all features of the languages, but many people that uses it
habitually also don't know all. Then it's just a quantitative difference,
not qualitative ;-)
 
G

Greg Comeau

BTW, this is not what my original remark necessarily pertained
to, but I think it's also worth pointing out that some people
can spend whole careers and not need to know every nook and
crazy of C or C++. For instance, embedded programmers were
mentioned in this thread.

There is far too often this sense that a programmer needs to
know everything, but in reality most programmers are going
to only be good at certain things.

For instance, designing, debugging, writing fast code,
writing maintainable code, fixing bugs, abstracting,
library writing, QA, systems programming, etc. Again, lots
of overlap but also lots of points that have nothing much
to do with each other at other levels. So you may have
somebody who can program circle around somebody else for
an embedded system, but switch to say a business app
with a user interface and they may be at a loss. And
there may or may not be language neutral issues at hand.

So master is not a sole term IMO. It's also not how much
of each standard can they recite, but also and perhaps more
importantly what can they do with it.
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top