aspose file tools*
The moose likes C / C++ and the fly likes do you recommend C++ for an introductory programming course? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Languages » C / C++
Bookmark "do you recommend C++ for an introductory programming course?" Watch "do you recommend C++ for an introductory programming course?" New topic
Author

do you recommend C++ for an introductory programming course?

Leandro Coutinho
Ranch Hand

Joined: Mar 04, 2009
Posts: 417
I think Ruby and Python are better for the job. Their syntax is easier and they have an interactive shell.

The benefit to learn a more low level language first is that it will be much easier to learn the other languages.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39435
    
  28
We used C++ for our freshers' programming until about two years ago at Teesside.
Luis Espinal
Greenhorn

Joined: Mar 06, 2009
Posts: 9
Leandro Coutinho wrote:I think Ruby and Python are better for the job. Their syntax is easier and they have an interactive shell.

The benefit to learn a more low level language first is that it will be much easier to learn the other languages.


I would pick Python or Ruby over C++, but not for the reasons you mentioned. I think C++, and Java, are horrible languages from a pedagogical point of view. Python, Ruby (these two with a focus on procedural programming first), BASIC, Pascal or C would serve better as a first programming language. For me, my freshman/sophomore trajectory was BASIC, Turbo Pascal (with Object Orientation), C, C++ and, then Assembly. I think it was a good trajectory.

Notice that I mentioned C as a first-language candidate. For all the low-level gotchas in it, it is much simpler than C++, to the point of having a bare-bones elegance to it. Pascal is another language I would put next to C. Not nearly as low-level as C, but with enough power to do low-level programming.

Regarding Python and Ruby, I do not believe their simpler syntax is easier (and whether their syntax is easier is debatable), nor having an interactive shell is all that crucial. What is excellent about these languages (like BASIC) is that it lets you program procedurally. That is, unlike Java, it does not force a OO paradigm down your throat. OO is great for solving and modeling problems of a certain scale, but not everything can be modeled from a OO pov.

A student should first learn how to think algorithmically and how to do function decomposition, because everything down to object methods breaks down into sequential procedures. People do not learn to do this correctly if all they know is objects, objects, objects (as in Java.) That is the main problem with Java.

And with C++, the main problem is the complexity of the language. Like Java, a person needs to have a certain amount of programming dexterity to learn how to use it well.

I think it is also a matter of quality of teaching. So assuming a good professor, Python, Ruby, BASIC, Pascal or C would be good choices for a first programming language. C++ or Java, not so much. These two are languages for work, not for teaching, and a person learning them should have enough man-hours doing programming (both procedural and object-oriented) to better understand and utilize these beasts.
Leandro Coutinho
Ranch Hand

Joined: Mar 04, 2009
Posts: 417
Luis Espinal wrote:Notice that I mentioned C as a first-language candidate. For all the low-level gotchas in it, it is much simpler than C++, to the point of having a bare-bones elegance to it.
C++ has more features, but it is simpler than C. You don't need to teach all C++ stuff from the start, and you can do almost anything in a C style. Also, you cannot put a language where string is not a basic type as a first-candidate!
Luis Espinal wrote:... or Java, not so much. These two are languages for work, not for teaching, and a person learning them should have enough man-hours doing programming (both procedural and object-oriented) to better understand and utilize these beasts.
Maybe with Java 7 and 8, it will become a beast. But now Java is not a beast at all.
Angus Comber
Ranch Hand

Joined: Jul 16, 2011
Posts: 90
In what way is C++ simpler than C? C is one of the simplest programming languages. That does not mean it is the simple to learn.

When learning a new language it is important NOT to bring all old ways of thinking to the new language. you should learn to program in the paradigm of the new language you are learning. The paradigm of C and C++ is very different. As it is of course between most languages.

Java I think could be a good starter language to learn.

One view is that you should start from 'simple' and move upwards just as you could learn say how a computer works. Learn the simplest most fundamental bits first then move to more advanced from there. That approach would suggest you learn assembler, then C then maybe C++ or Java, then say a functional language, etc.
But learning assembler as a beginner is going to be a struggle.

The opposite approach would be to learn a much higher level language. eg Ruby or Python.

I agree with previous poster about learning to write algorithmically.

At the end of the day, you can really start with any language.
Luis Espinal
Greenhorn

Joined: Mar 06, 2009
Posts: 9
Leandro Coutinho wrote:
Luis Espinal wrote:Notice that I mentioned C as a first-language candidate. For all the low-level gotchas in it, it is much simpler than C++, to the point of having a bare-bones elegance to it.
C++ has more features, but it is simpler than C.


How is it simpler? I work with both (and Java), and I cannot imagine how C++ is simpler, even if you stick to its most simpler features. C++ introduces subtleties in how structs, unions and classes are initialized, for instance, things that you do not have to worry in C. You have to ponder whether to use iostreams or the old printf-like functions for input and output. You have to wonder whether to use C-like strings (which is an anachronism onto itself), or create a custom String class (a good pedagogical exercise, but still an anachronism), or introduce the std::String. And if you do the later now you have consider whether to explain what the STL is, what '::' is, and whether to explain that std::String is a typedef of basic_string<char>... and now you have to consider how and when to introduce template meta-programing... and so forth and so forth.

Leandro Coutinho wrote:You don't need to teach all C++ stuff from the start, and you can do almost anything in a C style.


I used to believe in that, but quickly forego of the idea as I've had to update my C++ knowledge to meet current demands. Teaching C++ with a C style - akin to the old 'C with Classes style' of the early 80's - doesn't do students any favors. Even if one uses a stripped-down form of C++ typically used in embedded systems, the modern style is so far removed from the old C-like style that it defeats the entire pedagogical purpose of teaching the language.

Leandro Coutinho wrote: Also, you cannot put a language where string is not a basic type as a first-candidate!


Why not? It has been done before, and it is being done now at many universities with varied degrees of success. Besides, a string is just an array of characters with a null-terminating flag, a basic concept that any freshman should be able to handle right of the bat (yes, he/she should, we are not talking about arrays to pointers to functions or anything like that.) And the treatment of string functions in C is in many ways parallel to what one would do in classical BASIC - in both languages you call functions on strings for comparison, length calculation, etc (as opposed to calling equivalent methods in String objects.)

The only thing that is difficult with C strings is that you cannot do dynamic concatenation... at least not without *thinking* before hand. And that is one hell of an advantage (or hurdle depending on how you see it.) So you have an earlier intro to memory management, great! And I'd argue that string formatting a-la printf is extremely versatile and easy (like BASIC's PRINT USING statement).

Leandro Coutinho wrote:
Luis Espinal wrote:... or Java, not so much. These two are languages for work, not for teaching, and a person learning them should have enough man-hours doing programming (both procedural and object-oriented) to better understand and utilize these beasts.
Maybe with Java 7 and 8, it will become a beast. But now Java is not a beast at all.


No. I'm not referring to the functionality being added to the language when I refer to it as a 'beast'. I'm referring to more innate, basal syntactic characteristics present since Java 1.0. Also, I would argue that Java 5 introduced a great deal of functionality of a bestial size. Great functionality mind you (java.util.concurrent, generics, auto boxing, etc) but nothing that actually has to be dealt with on an early intro to the language. Similarly with whatever being introduced Java 7 or 8 (with the exceptions of lambdas and strings in switch statements.) But that's a different argument altogether...

Again, I'm referring to the signal-to-noise ratio one must deal with when teaching the most basic concepts. Consider the following. Compare the effort I need to do to write the following BASIC program



into equivalent Ruby, Python or even C or Pascal, and the compare that to the same effort involved with Java. If I go the Java route, I would have to teach

1. that I need to call System.out.println to print it (what is System.out.println? why not println? why does everything has to be within objects, what is an 'object')?
2. that such a statement must be in a static method (what is 'static'?)
3. that it must be encapsulated in a class (what is a 'class'? isn't that the same as an 'object'?)
4. that the class must be public (what is 'public'?)
5. that a public class (whatever that is) must be in its own file, and that the file must match the name of the class.
6. when I execute it, I got to invoke the interpreter just with the class name (but not with the .java or .class extension)... why?
7. oh wait, and let's not get into having to teach about the classpath, which can be obviated if we use an IDE... and then now we have to deal with IDE selection, setup, etc, etc.

Not even C has so much ceremony for such a pitiful trivial pedagogical task. Either I deal with this and teach it, or I wave my hands and claim that is all hocus-pocus that will be explained in due time. Neither is satisfactory. Pascal would be the #2 language with the most ceremonious boilerplate after Java (and with a lot less boilerplate). With C, all I have to explain is that I need to have a main function, and that I need to include <stdio.h> to call printf. With Ruby or Python, the task of teaching is trivial.

And that's what make Java, among other reasons, unsuitable as a first-programming language (let alone as the only programming language as sadly being done in many Java Schools.)

Java, and any language that forces a complete and absolute noun-centric OO paradigm suffers from a problem of tying functionality and characteristics to identity. This was identified as early as 1993 in Harrison and Ossher's paper "Subject-Oriented Programming - A Critique of Pure Objects, Proceedings of 1993 Conference on Object-Oriented Programming Systems, Languages, and Applications, September 1993, and humorously covered in Steve Yegge's parody of the Kingdom of Nouns (both good reads for anyone serious about working in software.)

This is a problem that has fundamentally plagued Java since its inception (for a pedagogical function, since it is a somewhat decent language to do work as I previously stated.) The amount of collateral information that needs to be introduced to fully explain basic concepts is way too large compared to other languages, even C.
Leandro Coutinho
Ranch Hand

Joined: Mar 04, 2009
Posts: 417
Angus Comber wrote:In what way is C++ simpler than C?

Luis Espinal wrote:How is it simpler?

The logic of a program written in C++ is simpler than in C, and therefore easier to get right.

"C++'s better support of libraries, better notational support, and better type checking are decisive against a "C first" approach." Bjarne Stroustrup

"My favorite approach is to start teaching the basic language concepts such as variables, declarations, loops, etc. together with a good library. The library is essential to enable students to concentrate on programming rather than the intricacies of, say C-style strings." Bjarne Stroustrup

http://www2.research.att.com/~bs/new_learning.pdf
John M Morrison
Greenhorn

Joined: Jul 25, 2005
Posts: 21

I have taught Java, C++ and Python to beginners. My preference is Python. Here are some of my reasons.




  • Python syntax is straightforward. Hello World is short and sweet. I don't have to explain "plumbing."

  • Python supports OO, procedural and functional programming.

  • It is easy and free to get Python running on all platforms.

  • Python is <em>not</em> a free-format language. Students who first learn Python have nice formatting habits.
    They understand that good formatting is your firend.

  • Python's interactive shell is a great teaching tool.

  • Python pads C's sharp corners. When I teach C, we re-examine Python and learn what happens underneath. Then the
    whole shebang is plausible and natural.



I also expose my students to programming at the UNIX command line. This course has been quite successful.



Luis Espinal
Greenhorn

Joined: Mar 06, 2009
Posts: 9
Leandro Coutinho wrote:
Angus Comber wrote:In what way is C++ simpler than C?

Luis Espinal wrote:How is it simpler?

The logic of a program written in C++ is simpler than in C, and therefore easier to get right.


A concrete example or two would be in order. Otherwise, a statement of the form "X is easier than Y" without substantiating, qualitative or quantitative evidence or samples is not a convincing argument, in particular in technical matters such as this.

Leandro Coutinho wrote:"C++'s better support of libraries, better notational support, and better type checking are decisive against a "C first" approach." Bjarne Stroustrup

"My favorite approach is to start teaching the basic language concepts such as variables, declarations, loops, etc. together with a good library. The library is essential to enable students to concentrate on programming rather than the intricacies of, say C-style strings." Bjarne Stroustrup

http://www2.research.att.com/~bs/new_learning.pdf


Quoting Stroustrup (much respect to his work) does not necessarily translate his words into facts. After all, Stroustrup is the father of C++, and obviously he's going to have that opinion. This is similar to Gosling's ideas regarding exclusion of operator overloading and any mechanisms of multiple implementation inheritance, and, above all, checked exceptions. Specially the later is one of the worst ideas ever and Java will forever be damned by the inevitable boilerplate code that comes with checked exceptions.

Those were terrible ideas that sounded great in paper, but did not deliver in practice. Same with a lot of things about C++, or with Stroustrup's position on C++ (in great part the result of what was known at the time about compiler and language design.) There are some interesting and, at the time, revolutionary ideas in C++, like const functions and references, but thing of the convolution involved in making const functions be actually "const" (in particular when the same method is overloaded for const-ness and non-const-ness.)

In C, I don't have to worry about the semantics of const-ness, or throw declarations (which really never worked as intended), or whether I need to inherit as public, protected or private, whether I inherit virtual, whether my default and copy constructors and assignment operators are done right, that I'm not calling copy constructors accidentally. And so on and so on.

Yes, I have to put a lot more elbow grease in C to get many of the benefits of C++, but that's manual labor over very clear semantics. Your only gotchas are your pointers, and that's it.

C++ provides superior mechanisms over C for handling large bodies of code compared to C, but the body of knowledge required to learn and use C++ well is not trivial at all. It is far larger than C's.

Any attempt to teach some stripped-down, C-like "lite" C++ version is a terrible disservice to anyone trying to learn that powerful and complex language. And that is why, IMO, a student needs to have more programming elbow grease, more programming credit/hours under his/her belt to really tackle the language. I would also make the same argument against Java as a first-language, or against introducing OOP without having some practice in procedural programming from a purely algorithmic/modular point of view.

Paul Santa Maria
Ranch Hand

Joined: Feb 24, 2004
Posts: 236
I completely disagree:

C++ has more features, but it is simpler than C. You don't need to teach all C++ stuff from the start, and you can do almost anything in a C style.


This is exactly *why* I disagree:
the body of knowledge required to learn and use C++ well is not trivial at all.
...
Any attempt to teach some stripped-down, C-like "lite" C++ version is a terrible disservice to anyone trying to learn that powerful and complex language.


I do agree that Python or Java would be good choices.

I would argue that Pascal or Ada would also be good choices.

IMHO .. PSM


Paul M. Santa Maria, SCJP
Leandro Coutinho
Ranch Hand

Joined: Mar 04, 2009
Posts: 417
Luis Espinal wrote:A concrete example or two would be in order. Otherwise, a statement of the form "X is easier than Y" without substantiating, qualitative or quantitative evidence or samples is not a convincing argument, in particular in technical matters such as this.

There are some examples in the link I posted. Hey man. you really like to write. =) and this is cool. Thanks a lot for your replies!
Brian Overland
author
Ranch Hand

Joined: Sep 09, 2011
Posts: 36
Hi. Author of C++ Without Fear here.

Obviously I'm a little biased, but I have a strong opinion, as I stated elsewhere: Ruby, LISP, etc. are very interesting and I have nothing against them...

But if you learn C/C++, you are learning the core of the C family of languages, which has come to dominate the world. You will be well prepared to learn the basic syntax of Java, C#, etc., as their basic syntax is mostly the same.

With those other languages you would be starting over completely if you first learned LISP for example.

== Brian Overland
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: do you recommend C++ for an introductory programming course?