News for hackers. Stuff that matters.
Re:Teaching C (2016) by andrepd on Tuesday October 30, 2018 @07:08AM (#18335399)
C and C++ are two completely different languages. It wouldn't cross my mind to teach both at the same time.
Re:Teaching C (2016) by kazinator on Tuesday October 30, 2018 @02:46PM (#18340064)
They are not completely different. Entire large projects can be written in C that also compile with a C++ compiler, and it is entirely practical, even easy, to maintain them that way.

My TXR language is like that:

   ./configure cc=g++
   make && make tests
The Lua people have done this too, and call this dialect "Clean C", I think.

Compiles cleanly and tests pass. I usually work with it with a C compiler. Before releases I run it through the C++ compiler to see what breaks, and fix it. (Usually very little and often nothing at all.)

Teaching them at the same time? I'm not sure I would take programming newbies and try to teach them how to program in C such that it also means the same thing as C++. That is to say, I would be confident that I could teach this in a straightforward way; however, the problem would be the lack of supporting material. For instance, there is no reference manual for the "Clean C" language; what would we use as a text book?

One approach would be just to use C resources, and cover the C and C++ differences as one chapter of the course: basically, how to port C programs to the C++ dialect.

I'd definitely teach the students how to leverage the stricter C++ type conversions while keeping the code C, including the following trick:

  #ifdef __cplusplus
  #define strip_qual(TYPE, EXPR) (const_cast<TYPE>(EXPR))
  #define convert(TYPE, EXPR) (static_cast<TYPE>(EXPR))
  #define coerce(TYPE, EXPR) (reinterpret_cast<TYPE>(EXPR))
  #else
  #define strip_qual(TYPE, EXPR) ((TYPE) (EXPR))
  #define convert(TYPE, EXPR) ((TYPE) (EXPR))
  #define coerce(TYPE, EXPR) ((TYPE) (EXPR))
  #endif
This would be a nice way to cover the preprocessor.
Re:Teaching C (2016) by pjc50 on Tuesday October 30, 2018 @08:19AM (#18335794)
People keep saying this, but the difference is comparable to Perl5/6 or Python2/3 - you can construct programs that are valid in both, and there's a big overlap of concepts and syntax.

In some ways it's easier to interlink C and C++ code than it is to interlink Python2 and Python3 code.

Re:Teaching C (2016) by geezerjay on Tuesday October 30, 2018 @08:49AM (#18335985)
> People keep saying this, but the difference is comparable to Perl5/6 or Python2/3 - you can construct programs that are valid in both, and there's a big overlap of concepts and syntax.

There's more overlap wrt mental models between C#, Java and C++ than there is betwern C and C++. Being able to compile code in both languages means close to nothing if a developer can't understand how a project is structured and how a component is supposed to work.

Re:Teaching C (2016) by kazinator on Tuesday October 30, 2018 @02:48PM (#18340095)
I would say that being able to compile code in one language means close to nothing if a developer can't understand how a project is structured and how a component is supposed to work.

Thus, the observation doesn't inform the debate about C and C++ overlap.

Re:Teaching C (2016) by geezerjay on Wednesday October 31, 2018 @06:33AM (#18344543)
Obviously it does. Sharing some common syntax means zero if a developer versed in C++ can't do anything in a C project.
Re:Teaching C (2016) by saagarjha on Tuesday October 30, 2018 @02:48PM (#18340094)
This is not true at all. C and C++ are about as similar as C and Objective-C: sure, your code is pretty much a superset (or in Objective-C's case, a strict superset) of C. But most of the time your code looks nothing like C at all.