Teaching C++ to students that know Java

Course Queries Syllabus Queries . 2 years ago

  0   2   0   0   0 tuteeHUB earn credit +10 pts

5 Star Rating 5 Rating

Posted on 16 Aug 2022, this text provides information on Syllabus Queries related to Course Queries. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Write Your Comments or Explanations to Help Others



Tuteehub forum answer Answers (2)


profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago


I am now teaching an OOP course to 2nd year undergrads. This is actually a course in advanced programming in Java. In the next semester, I am going to teach the same students, a C++ course. From what I know, C++ and Java are quite similar - there are differences, but they can be covered in 2-3 hours, which are one week of teaching. This leaves me 12 more weeks, and I wonder what else to teach.

I looked at the syllabus from previous year and it looks quite similar to my current Java course: OOP, overloading, generics, unit-testing, software design, etc. I don't want to teach the same course twice in different languages...

One idea that I had is to focus, not on teaching the language itself but on teaching specific practical applications in which C++ has a clear competitive advantage. For example, if game-programming is usually done in C++, then I can focus on game-programming. So my first question is: what kind of applications are written in C++ substantially more than in Java?

And my second question: what other new topics can I include in this C++ course?

[NOTE: in case this is relevant, the same students currently take a course in C].

0 views   0 shares
profilepic.png
manpreet 2 years ago

Actually, the similarities between C++ and Java are fairly shallow and the differences are very deep. The syntax of both is derived from C, but the underlying ideas are very different.

The biggest difference is that an "object" in C++ is built on the stack, like a struct, not on the heap. It takes additional work and a lot of understanding to become comfortable with the differences. If you do create objects on the heap (with new) you need to understand the differences between pointers and references and these can be the source of hard to debug errors. And you need to be absolutely pure with deallocation. Every object needs a known lifetime to the programmer, whereas Java handles all of that automatically.

C++ has no garbage collector for heap objects, so the memory management problem needs to be solved for every application, unlike Java where it is solved once by the run-time system automatically. Smart pointers in C++ can help a bit with this but are not a complete solution. Memory leakage for non-trivial applications is a serious issue.

The visibility of things is also fundamentally different, with "friend" classes complicating the mental models of complex systems.

Don't underestimate the difficulties. You will likely have a lot of work to do to get the students comfortable with quite different mental models and with practices and idioms that keep them safe.

James Gosling once described Java as C++ without the guns, knives and clubs. You will be trying to program with all of those pitfalls, when the students, coming from Java, have little experience with them.

Their experience with C, if deep enough, will help with the memory management issue, but not with the complex (i.e. dual) object model of C++. You should become familiar with good memory management tools and practices if you want to do non-trivial things in C++.

I was once stopped dead in a C++ project by a deallocation error for 24 hours. The solution required a 1 character change in a file. One character of progress per day is very bad, though I was an experienced programmer and actually knew why it was failing.

Your own experience with C++ seems shallow from the statement of your question. I'd suggest that you work hard on that before you attempt to teach such a course. Especially, build something that requires sophisticated memory management and test everything as you go. You can't think of C++ as just mis-spelled Java, nor Java as just mis-spelled C++. The conceptual differences are many and deep.

My own experience as a programmer (and author)` is that Java helps me program correctly, but C++ fights me constantly for every inch of ground. I could build some beautiful things, but the fight was constant and brutal.


0 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.

tuteehub community

Join Our Community Today

Ready to take your education and career to the next level? Register today and join our growing community of learners and professionals.

tuteehub community