6

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.

9
  • 9
    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.
    – riwalk
    Oct 25, 2011 at 16:38
  • 8
    C++ may teach a lot of things, but OO isn't one of them. Oct 25, 2011 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, 2011 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").
    – riwalk
    Oct 25, 2011 at 18:03
  • 3

11 Answers 11

3

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.

3
  • 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, 2011 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, 2011 at 17:03
  • 1
    @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- programmers.stackexchange.com/q/116643/963 And one more thing I should tell- C++ is a better language than Java. :D
    – Gulshan
    Oct 29, 2011 at 11:43
25

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.

3
  • 1
    "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. Oct 26, 2011 at 9:40
  • Ruby also uses a Smalltalk like Object Model IIRC
    – user28988
    Oct 26, 2011 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, 2011 at 11:52
10

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.

5

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.

3
  • 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, 2011 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, 2011 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. Nov 2, 2011 at 16:06
3

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.

2

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.

2
  • "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, 2011 at 17:09
  • The C++ STL will at least teach students to think about algorithms at a higher level. Oct 25, 2011 at 19:36
2

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.

2

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.

2

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?

2
  • 2
    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, 2011 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, 2011 at 19:07
1

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.

0

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.

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