What so wrong about teaching "C/C++"?

V

Victor Bazarov

Stefan said:
What's so wrong about teaching "C/C++",

You mean, aside from the fact that there is no such thing as "C/C++"?
when I just found this in the web?

»French & Italian Comparative Tutorial I:
Learn Two Languages Simultaneously«

http://www.ielanguages.com/frenchitalian1.html

What's so wrong about teaching diving and sky-diving at the same time?
Is that the different equipment? Or maybe the different hand signals?
Can you say "confusion"?

The two languages are similar enough that many folks can move from one
to the other with relative ease. British English and American English
are very similar, and have a vast common subset, such that when it's
used, both AE and BE speakers can understand what's said. However,
there are cases when a BE speaker would either be understood incorrectly
by an AE speaker or simply not understood. That causes confusion.

If by <<teaching "C/C++">> you mean teaching the common subset, it's
possible. Not useful in most cases, since it excludes a huge portion of
C++, but possible. If by it you mean <<teaching C and C++>>, then I
would strongly advice against it since the contradictions between the
two languages are numerous and will interfere with learning more than
the commonalities will help.

V
 
S

Stefan Ram

Victor Bazarov said:
(...) If by it you mean <<teaching C and C++>>, then I
would strongly advice against it since the contradictions between the
two languages are numerous and will interfere with learning more than
the commonalities will help.

I agree. There is the Ranschburg phenomenon/effect:

»When people shift between two [similar - S.R.]
languages while learning at least one of them, the
neurons get "confused" while memorising
("Ranschburg-Phenomenon").«

http://active-international.org/campinformation_AI-3_09_marburg-germany.pdf

This articles gives a better description, but seems to
be available in German only:

http://de.wikipedia.org/wiki/Ranschburg-Phänomen

I just thought it was funny that someone actually tries to
teach both french and italian at the same time, and this
reminded me of books or classes claiming to teach C and C++
at the same time.
 
K

Kaz Kylheku

You mean, aside from the fact that there is no such thing as "C/C++"?

Counterexample: existence of programs that are portable to C and C++
compilers simultaneously (as a useful and easily-maintained feature).

An example is a program I've been working on:

http://git.savannah.gnu.org/cgit/txr.git

When building this program, you can pass --ccname=g++ to the configure
script, to have it built with GNU C++. By default, it builds with the C
front end. From time to time, I check for regressions by doing
a C++ build.

Compiling the code as C++ provides better diagnosis, catching
errors that C compilers let slide.

In the GNU implementation, the C++ front end provides superior
diagnostics for catching undeclared functions than the
-Wmissing-prototypes and -Wstrict-prototypes options than the C front
end. C++ has type-safe linkage, too, whereas C allows an
external declaration to mismatch the definition, resulting
in undefined behavior. C compilers and linkers even allow multiple
external definitions (which may not all be type compatible).
But switching to C++ for reasons like these sacrifices portability. We
may want to take advantage of C++ in development, but be portable to C
in deployment.

Plus, the support for C++ itself increases portability;
the code now ports to C++ compilers.

I think anyone teaching C these days owes it to the students to point
out where the C++ dialect differs in any of the areas covered.

Like for instance ``Here, class, we can assign the return value of
malloc to the pointer on the left side directly. In the C dialect
embedded in C++, we would need a cast.'' Etc. Or ``in the C++ dialect,
enumerations are treated with greater type strictness; some of these
things are we are doing here with the enumeration members are not
allowed under C++ without requesting a conversion.'' Or ``In C++,
struct is a class, and the members have a class scope; so a typedef name
or enumeration defined within a class is not introduced into the
surrounding scope, like in C; for portability it's best not to introduce
numerations and typedefs within a struct.''

If any of the students go out into the real world to do programming,
they may have to deal with C++ compilers.

My company develops a very large software suite written in C++. The
build system runs gcc with ``-x c++''. This means that all .c files are
treated as C++, must like .cc files. No exceptions. All snippets of C
code that were ever integrated into the tree are compiled as C++.
What's so wrong about teaching diving and sky-diving at the same time?
Is that the different equipment? Or maybe the different hand signals?
Can you say "confusion"?

That's ridiculous. C and C++ are closer than French and Italian.
These are mutual dialects, which French and Italian aren't.

Sky diving isn't derived from ocean diving; they are connected only
by a word (at least in English).

C and C++ are not connected by merely a letter of the alphabet.

Hyperbolic arguments don't lead to any enlightenment.
 
V

Victor Bazarov

Kaz said:
Stefan said:
What's so wrong about teaching "C/C++",
You mean, aside from the fact that there is no such thing as "C/C++"? [.."counterexample" snipped..]
when I just found this in the web?

»French & Italian Comparative Tutorial I:
Learn Two Languages Simultaneously«

http://www.ielanguages.com/frenchitalian1.html
What's so wrong about teaching diving and sky-diving at the same time?
Is that the different equipment? Or maybe the different hand signals?
Can you say "confusion"?

That's ridiculous. C and C++ are closer than French and Italian.

They are? How can you tell? What makes French and Italian so
different? The alphabets/charsets? The punctuation rules? The fact
that there are verbs/nouns/etc. in one and not the other?
These are mutual dialects, which French and Italian aren't.

C and C++ are mutual dialects, are they? Hmm
Sky diving isn't derived from ocean diving; they are connected only
by a word (at least in English).

<shrug> Ok, let's consider ice skating and roller-skating. They are
very much alike. The equipment is similar. Can you teach them at the
same time? If your course doesn't involve teaching stopping (other than
by running into an obstacle or by falling), maybe.
C and C++ are not connected by merely a letter of the alphabet.

Hyperbolic arguments don't lead to any enlightenment.

Yes, they do. They make the reader think. They provide a basis for a
lively discussion.

"Dramatize your idea" (don't remember who said that)

V
 
K

Kaz Kylheku

Kaz said:
Stefan Ram wrote:
What's so wrong about teaching "C/C++",
You mean, aside from the fact that there is no such thing as "C/C++"? [.."counterexample" snipped..]
when I just found this in the web?

»French & Italian Comparative Tutorial I:
Learn Two Languages Simultaneously«

http://www.ielanguages.com/frenchitalian1.html

What's so wrong about teaching diving and sky-diving at the same time?
Is that the different equipment? Or maybe the different hand signals?
Can you say "confusion"?

That's ridiculous. C and C++ are closer than French and Italian.

They are? How can you tell? What makes French and Italian so
different? The alphabets/charsets? The punctuation rules? The fact
that there are verbs/nouns/etc. in one and not the other?

No, the set of sentences. A language generates a set of sentences.

Two languages can have a common subset. Syntactically they can generate
some sentences which are the same. Moreover, some of these same
syntactically-same sentences can also have the same meaning(s).

I suspect that the set of such common sentences between French and Italian is
small. Thus, I don't suspect there is a common dialect which is recognized by
either French or Italian speakers as being French and Italian, respectively,
and yet is as expressive as at least one of these two. I.e. it's not the case
that the majority of Italian is embedded in French or vice versa.
C and C++ are mutual dialects, are they? Hmm

Of course. There is a common dialect in which you can write programs
that work when processed as either C or C++. That dialect is exactly
as expressive as the entire C language (or at least C90: no C99 features).

Any program I can write in C, I can write in this dialect also, without any
difficulty, and I get rewarded with portability to C++ compilers, which I can
then, in turn, use as a development tool for that code (and not merely a
porting target) to obtain better compile and link time safety. You know, maybe
we should come up with a standard-like document which codifies the portable C
dialect that is understood by C and C++ compiler. This deserves to be
documented as a language in its own right.

You could teach this dialect to students. Then they can do their homework
with C or C++ compilers (and can be encouraged to try it both ways).
 
V

Victor Bazarov

Kaz said:
Kaz said:
>>> [..comparison between C and C++ is likened to a comparison
>>>> between French and Italian languages..]
These are mutual dialects, which French and Italian aren't.
C and C++ are mutual dialects, are they? Hmm
[..]
You could teach this dialect to students. Then they can do their homework
with C or C++ compilers (and can be encouraged to try it both ways).

You *could* teach a monkey to operate a passenger aircraft. It doesn't
mean you should, though. The same thing here. Teaching a common
language subset is not teaching C++. It's probably much closer to
teaching C (and some from 'c.l.c' might disagree), but it's definitely a
waste of time if the goal is to get somebody to actually know C++ (to a
usable degree) at the end of the course. Just MO.

V
 
F

frankgerlach

Contrary to the other replies, I would argue that for real-world
programming, the corpus of C-based libraries is so enormous that any
real C++ programmer must know how to interface to them. Maybe he/she
even needs to know how to debug and extend them.
Only very few people start on a "green field" where they can use only
"proper C++" (STL containers, streams, templates, smart pointers and
other elegant mechanisms). Most people have to integrate from one to a
few dozen C libraries into their build. One can only do that
effectively by knowing about the C idioms.
Without a doubt it is good to teach people how to write more reliable
programs using C++ mechanisms, instead of regressing to C-style
programming. Still, the latter is part of any serious programmer's
reality for the forseeable future, so it must be teached. Good
teachers will compare the different approaches and tell students to
"go the C++ way" for any new code.
 
K

Kaz Kylheku

Stefan Ram ha scritto:
I agree. There is the Ranschburg phenomenon/effect:

»When people shift between two [similar - S.R.]
languages while learning at least one of them, the
neurons get "confused" while memorising
("Ranschburg-Phenomenon").«

I'm far from being an expert, but all I can say is that I've never
personally had this experience. I once studied Italian, Spanish and
French at the same time and did not feel confused at all. Quite the
contrary.

These languages are not nearly similar enough for this effect to take place.

People get confused in learning when they are presented with a morass
of things that look the same.

Your ``neural net'' has to be trained before it can recognize the distinctions
in some unfamiliar category.
However, for computer languages it may be a different story altogether.
I don't think it is very meaningful to compare human and computer
languages in the first place.

If you're learning C or C++ (properly!), you can't escape from the fact that
you are learning two similar dialects: the standard dialect, and the dialect of
your compiler.

So if you are looking for the conditions that lead to the Ranschburg effect,
there they are!

To a complete newbie, a platform-specific program and an ISO-conforming program
look like the same sort of thing. But he's expected to memorize some
distinction regarding portable versus nonportable.

The actual space in which you can write program is larger than the ISO space,
because of all the nonportable things you can do. So as a teacher, you can't
help the fact that you will be teaching a subset.

Now, there is not much difference between teaching the ISO dialect of C, and
teaching a C/C++ dialect of C. From the student's point of view. either of
these is a kind of subset of what your compiler will accept.

If you /don't/ want to have teach the students difficult concepts, like ``this
construct can be written, and your compiler will accept it, but it's not
portable'', then you can't teach the standard language! You have to teach the
language of the compiler that you are using for that class, using its reference
manual as a textbook. Then you have no problems. What the compiler accepts is
the language everyone in the class is learning.

If you're going to teach in such a way that you have to distinguish dialect
from implementation, for what reason would that be? It's to teach students
about writing /portable/ code, right? They can take their newly learned
skills and practice them in a different environment. Now if teaching
portability is your goal, then, you have to rationally admit that the common
dialect between C90 and C++98 is more portable than the either language in
full.
 
V

Vladimir Jovic

Kaz said:
Any program I can write in C, I can write in this dialect also, without any
difficulty, and I get rewarded with portability to C++ compilers, which I can
then, in turn, use as a development tool for that code (and not merely a
porting target) to obtain better compile and link time safety. You know, maybe
we should come up with a standard-like document which codifies the portable C
dialect that is understood by C and C++ compiler. This deserves to be
documented as a language in its own right.

Few months ago I had to include a C header into the c++ source file. I
couldn't because there was a structure with member named "class". This
is just one example how the C and C++ differs.

Also, the way of thinking differs in these two languages. One is
procedural, other is OO oriented.
 
N

Nick Keighley

<shrug> Ok, let's consider ice skating and roller-skating.  They are
very much alike.  The equipment is similar.  Can you teach them at the
same time?

I learned both pretty much at the same time (as an adult), yes there's
quite a bit of cross-over.
 
J

James Kanze

That's ridiculous. C and C++ are closer than French and
Italian. These are mutual dialects, which French and Italian
aren't.

I'm not sure of that. I think that you can push the analogy too
far, however. C and C++ are two very distinctive languages,
much like French and Italian. The evolution of programming
languages, however, is consciously controled, unlike that of
human languages, and in the case of C++ (and to a much lesser
degree C), there has been a conscious effort to maintain a
common subset. (Another major difference is that evolution in
programming languages is mainly driven by the need, or at least
the perceived need, to add expressivity. This is clearly not
the case of natural languages, where French and Italian are
equally expressive, just differently.)
Sky diving isn't derived from ocean diving; they are connected
only by a word (at least in English).

And the fact that you're going down:).
C and C++ are not connected by merely a letter of the
alphabet.
Hyperbolic arguments don't lead to any enlightenment.

Analogies can only be pushed so far. I do think that teaching C
and C++ simultaneously would cause confusion. But I'm not aware
of any studies which would support or invalidate this feeling.
 
J

James Kanze

Kaz said:
Kaz Kylheku wrote:
[..comparison between C and C++ is likened to a comparison
between French and Italian languages..]
These are mutual dialects, which French and Italian aren't.
C and C++ are mutual dialects, are they? Hmm
[..]
You could teach this dialect to students. Then they can do
their homework with C or C++ compilers (and can be
encouraged to try it both ways).
You *could* teach a monkey to operate a passenger aircraft.
It doesn't mean you should, though. The same thing here.
Teaching a common language subset is not teaching C++. It's
probably much closer to teaching C (and some from 'c.l.c'
might disagree),

But that's what he said. That the common subset is practically
as expressive as C, and that if you're teaching C, you should
in fact teach this common subset, since your students will
almost certainly have to deal with C++ compilers at some time in
their career.

And yes, I suspect that you'd find some, or even a lot of,
disagreement in c.l.c.
but it's definitely a waste of time if the goal is to get
somebody to actually know C++ (to a usable degree) at the end
of the course. Just MO.

If the goal is to get someone to actually know C++... I think
the original question concerned teaching both languages at once.
IMHO, Kaz's suggestion concerns a way of teaching C, without
teaching C++. I don't think it's really teaching both languages
at once. If you were teaching both languages at once, you'd
have two course units, one presenting C style arrays, and the
other std::vector, both at about the same time and stage of
learning.
 
R

Rune Allnor

C and C++ are closer than French and Italian.
These are mutual dialects, which French and Italian aren't.

Don't know about French, but *Spanish* and Italian are
similar enough that they cause problems learing. Used to
spend some time among Spanish-speaking people in Italy
a few years ago. Never learned Italian. Part of the problem
was that I heard Spanish in use in the group of friends, far
more than I heard Italian in use outside the group.

Stick with one language. Learn it well. Then deviate
towards similar stuff, be it dialiects of the base language
or similar languages.

Rune
 
K

Kaz Kylheku

Few months ago I had to include a C header into the c++ source file. I

Actually, you maybe had to do this more recently than you think. Many of the
headers in your toolchain can be used with either the C and C++ compiler.

Do you never include platform headers in your code, only the C++ standard
couldn't because there was a structure with member named "class". This
is just one example how the C and C++ differs.

See? You would not have had this problem if the programmer who prepared this
header file had been aware that he needs to work in C and C++ simultaneously.
Also, the way of thinking differs in these two languages. One is
procedural, other is OO oriented.

That's obviously not true if one is using the procedural subset of C++ which is
equivalent to C.

The OOP style in most C++ programs is procedural; C++ class member functions
are procedures, mostfrequently written in an imperative style: they modify
objects by assignment and contain iteration and selection type control flows.

You can reason about C++ OOP code at a very low level. You can nearly
visualize what the C would look like if you had a C++ compiler that worked by
compiling to C. Moreover, taking this view can actually help you to understand
and debug the code.
 

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
474,156
Messages
2,570,878
Members
47,405
Latest member
DavidCex

Latest Threads

Top