Sign up ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

My understanding is that C++ is usually offered as the 1st OOP language, and as the 2nd programming language (after C) in my country (Bangladesh). I've taught it several times, and the problem I've run into is that students often tend to think C++ as an extension of C, i.e. C with cin and cout! This has lead me to think about teaching Java as the first OOP language in the upcoming semester.

What is your opinion? I would like some suggestions from professional programmers as well as academics.

share|improve this question

closed as off-topic by gnat, durron597, Ixrec, MichaelT, GlenH7 Sep 5 at 13:12

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions seeking career or education advice are off topic on Programmers. They are only meaningful to the asker and do not generate lasting value for the broader programming community. Furthermore, in most cases, any answer is going to be a subjective opinion that may not take into account all the nuances of a (your) particular circumstance." – gnat, durron597, Ixrec, MichaelT, GlenH7
If this question can be reworded to fit the rules in the help center, please edit the question.

Teaching Java first will not do your students any favors. In the CS curriculum, a class in algorithms is usually right around the corner, and many algorithms assume that you have a good level of control over memory (a level of control that Java simply does not give you). Teach them C++ and let them make their own conclusions about it. – Stargazer712 Oct 25 '11 at 16:38
C++ may teach a lot of things, but OO isn't one of them. – Eric Wilson Oct 25 '11 at 17:15
@Stargazer712 Regarding 'control over memory', my students have already completed 'C' and 'Data Structures'(in C). And many of them have been practicing for Programming contests (ICPC). ... so my main concern is about the "Concept of Object-Oriented Programming". Thanks anyway. – Punter Oct 25 '11 at 17:16
@Punter, then that is the reason why your students are not understanding OO when learning C++ (the same way that those who learn C++ first tend to consider C to be just "C++ without classes"). – Stargazer712 Oct 25 '11 at 18:03

11 Answers 11

up vote 3 down vote accepted

I think, C++ suits as the first language better than C. You can think of starting the programming intro course with C++ but without OOP things. Then the curriculum will be like-

  • Introduction to Programming with C++
  • Introduction Object Oriented Programming with C++ (in the following semester)

There are several benefits-

  • This solves the main problem you mentioned- while teaching OOP with C++ to students having prior experience of C, they think that they are just learning a new language, not a paradigm(OOP). But when teaching both the courses with C++, they will know that they are going to learn something new.
  • You can use easier C++ language constructs like cin/cout, references, std::string etc. I am not saying to leave pointers though. You can still teach pointers after introducing reference without leaving C++. Then it will be much more easier to grasp IMHO.

If you start with C++, you may have to use some member functions of various library classes like std::string, File IO. But don't hesitate. Calling or using a member function of a class does not require OOP knowledge. OOP is required to design a class. And you can keep one or two classes aside in the intro course to give idea about C constructs and the differences between C and C++. Then students will know C also. And my request is- give emphasis on STL and generic programming with C++. Because people use Java for it's huge library support. But many of them doesn't know most of these also exists in C++ STL. Good luck.

share|improve this answer
Agreed. I also think that C++ should be used as the first language. But, you know, we cannot change "the system" in a day! .... Meanwhile, my students have done pretty well in "C" and "Data Structures" and have learned STL in "ACM Class". That's why I am thinking about teaching them java so that they can build some real-life projects. – Punter Oct 27 '11 at 15:01
@Punter consider developing real-life projects using C++ also. That's what most programs are developed with those we use everyday. – Gulshan Oct 27 '11 at 17:03
@downvoters I know this reply did not answered the question made by OP, but as you have seen, it tried to solve the root problem OP mentioned. And I think the first programming language taught should be python. But coming of same country, I know the condition better. So, I suggested C++. And there are people of same opinion. Check the comments of this question- And one more thing I should tell- C++ is a better language than Java. :D – Gulshan Oct 29 '11 at 11:43

If you're trying to teach (pure) OOP I would recommend against using C++ and use a pure OO language instead. One of the strengths and weaknesses of C++ is that it is a multi-paradigm language, with OOP only being a small part of it. Add its (mostly) backward compatibility with C and it's not a surprise that a lot of people familiar with C fall into the "C with cout" trap.

I would strongly recommend using a pure OO language like Smalltalk if you want to teach your students the concepts of OO. Yes, they're unlikely to get a job writing Smalltalk apps but that's not the point. If they're reasonably competent in picking up programming languages they'll learn another language easily. At this point you're not trying to make them "X programmers" but you want them to get the insights into a specific paradigm so picking a language that's a pure implementation of the paradigm and most likely unfamiliar to the students should help teaching because you'll avoid the "Oh, I know a shortcut here" moments.

share|improve this answer
"they're unlikely to get a job writing Smalltalk apps" -- I disagree: Objective-C is basically Smalltalk + C and Java is Objective-C - C + types, and both of these languages are "somewhat" :-) popular at the moment. Plus, Java code written by Smalltalkers seems to be of much higher quality than Java code written by Java programmers, at least in my experience. – Jörg W Mittag Oct 26 '11 at 9:40
Ruby also uses a Smalltalk like Object Model IIRC – World Engineer Oct 26 '11 at 15:52
@Timo Geusch - I wish C++ was used instead of Java while I was in school. I wish I could have learned more about C++ instead I was stuck with Unix/Linux C++ which really the non-OOP nature of C++. – Ramhound Nov 1 '11 at 11:52

I would say it depends on the degree.

I would teach C# or Java for CIS/MIS because this is what is used when programming real world business applications in today's market.

C++, Scala, or Smalltalk for CS students. There are many educational programming languages designed to both teach and enforce OOP.

share|improve this answer

It depends on your goal. If you want the students to come out of the program with real-world marketable skills, then C# and Java are both good candidates.

However, if you want to teach your students a language that is easy to learn, has good OO properties, and easy to teach, I strongly recommend Python. I've taught Python to people with no programming experience, and they pick it up very quickly. The syntax is simple, and very close to natural language prose. The OO capabilities are not as robust as C#, but there's enough fundamentals in there for teaching purposes.

share|improve this answer
Python could be a nice choice. It's one of my favorite language. ... but the problem is, it is not that much popular here, and people are usually resistant to accept new things :( – Punter Oct 26 '11 at 17:49
@Stephen - Who are we kidding. Even if C# is taught the knowlege these students come away from is limited. As one of those students who taught himself C# for 7 years before taking a C# course, I can tell you most of the time will be spend teaching the basics of the language, the rest will be spent TRYING to teaching advanced topic but failing to do so because half the class cannot solve a null exception with hand holding. – Ramhound Nov 1 '11 at 11:54
@Ramhound Actually, you raise an interesting point. I've noticed that learning a programming language is a lot like learning a musical instrument. Sure, you go to class once or twice a week. But the real learning takes place in the hours and hours and hours you spend practicing on your own. – Stephen Gross Nov 2 '11 at 16:06

I'd take the best of both worlds in a sense and teach them Objective-C. It's a strict superset of C so you can drop C code right in and not worry about it if it comes to that. It has a Smalltalk style object model which tends toward a slightly cleaner feel than C++ and Java. The Syntax is a bit weird and it would require Macs or the use of GNUstep but if you want a language that balances practice and purity a little better than C++ or Java, I'd pick it. It definitely helped me to learn it as far as learning Object Oriented Design.

share|improve this answer

Do not teach Java. The problem with Java is that all you can learn from it is that inheritance is a hammer and absolutely every problem is a nail. Also, the terminology of Java heavily confuses topics like object orientation and memory management- not what you want to teach poor students who'd be lucky to grok either of those things taught independently.

You want to teach OOP. Not "Objects are our Gods. Inheritance shall be our divine weapon against all programming problems. We shall not question the Garbage Collection algorithm and explore other forms of managing memory. Primitives shall be looked down upon by all. We shall exist purely within the Sacred Laws of the Virtual Machine."

The fact that your students see C++ as "C with cout" is a failure of teaching C first and then not properly upgrading to C++. The usual remedy is just to not teach C at all, as it's really quite redundant to do so and very damaging. Or you could just hire smarter teachers. But that's not very viable because it's really hard to solve this problem after it's been created.

C++ makes a great OOP language because C++ doesn't confuse object orientation with memory management, and it allows you to properly weigh a paradigm when you can use it's alternatives as well if you'd like. How can you learn when not to use OOP if that's all the language offers?

share|improve this answer
I think someone is too anti Java to give an unbiased answer. OOP and memory management are completely unrelated to the understanding of OOP and whether a language is garbage collected, has pointers, or has a VM does not matter for that course content. – Rig Oct 27 '11 at 14:08
@Rig: OOP and memory management are completely unrelated. That's the point. The point is that Java confuses them. That's very related to how you understand OOP. – DeadMG Oct 27 '11 at 19:07

I believe the choice of language is less important than the set of librariries. Let me clarify.

I had several C++ classes (1st OO language) at the Univ. This is where I was taught OO mechanisms such as inheritance and polymorphism, but a I was lacking a "working" understanding of OO. I feel I truly started understanding how to write OO programs (everything is an object, objects talk to each other, etc...) only after I started a larger java project, where I had to use the JDK libraries. In C++ it always seemed I could get away with large procedural chunks tucked away in non-objects.

I assume I would get the same effect (ie working with objects) from using the STL on the C++ side.

share|improve this answer
"In C++ it always seemed I could get away with large procedural chunks tucked away in non-objects." - that's the deficiency of C++. Otherwise, 'STL' vs. 'JDK Libraries' could be a sweet dilemma :) – Punter Oct 25 '11 at 17:09
The C++ STL will at least teach students to think about algorithms at a higher level. – kevin cline Oct 25 '11 at 19:36

It depends on your primary emphasis. If you're primarily interested in teaching programming, with some OO language as the vehicle, then C++ would be preferred. If you're primarily interested in teaching OO, with programming more or less secondary, then Java is probably preferred. Based on your comments, the latter seems to be the case.

Edit: I should add that IMO, teaching OO as a concept in itself is mostly a mistake. I think the real concept is generic programming, with OO as a special/specific case of one limited form of generic programming. From that viewpoint, C++ is clearly preferable.

share|improve this answer

C++ is often chosen as the OO language in classrooms mainly because it is one of the more useful languages to know. Lots of work for C++ programmers. But, as stated before, it can easily lead people into trap of coding in it as C, and barely touching the OO piece of it.

I believe one language that might be suitable would be Ruby, which is somewhat desirable, and highly OO. I usually recommend Python over Ruby, as I prefer it, but in this case it may be better, due to everything inherently being an object. It is useful, has quite a bit of libraries to build on, and quite a bit of activity.

I believe that if you want to avoid the C trap, you have to remove them from the world of C/C++ so they are forced to learn a new language, as well as the OO concepts that come with it.

share|improve this answer

Count me in with the Smalltalk crowd.

However, another thing that'd be useful to teach is that there are more ways than one to skin the OOP horse. For instance, I've found that a lot of people used to the C++/Java branch of the OOP family tree have a lot of trouble wrapping their heads around how R's S4 class system (itself based on the OOP system of Dylan) works.

I'm a firm believer in the notion that learning a wide range of programming language paradigms is helpful for being able to quickly pick up new technologies in the future, and being exposed to how multiple languages handle OOP concepts can only help.

Maybe the ideal way would be to speak in pure concepts first and then show how different languages implement (or not) those concepts.

share|improve this answer

I think Java is a bad idea. I hate this language so can't be objective, but learning OOP in an environment where everything is OO may be very confusing. The fact that Java has been made only for OOP does not make it the best in this domain.

In my school, we used OCaml as our first programming language (I was programming long before that but never learned it in course). Dispite the fact it teaches functional programming (which is probably not useful to you), the OO part is very clean and easy to read / understand. For me, it brings together many great things for learning purpose: high level, strongly typed, multiparadigms and a good standard library.

Saying that C++ is the best choice because it's the most useful is not relevant. Programming courses should teach how to learn programming, and not only how to program using a particular language.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.