Thursday, September 25, 2014

C++ and Java Together in CS2: Will it Be Great or a Disaster?

I've been trying something a little bit different for our CS2 class this semester.  The course typically covers object-oriented programming in Java along with topics like recursion.  In fact, students becoming proficient in Java is one of the hard requirements of the course.  But students who have recently passed the course did not seem sufficiently prepared for what came next: systems programming with C.  In fact, some students (barely) passing the course seemed not to be able to program sufficiently well on their own at all.

I knew there was an appetite to try something new, and I thought I had the perfect book to try out: Think Like a Programmer.  Only problem was that the book uses C++, and as I said above, we need to use Java.  I ended up chatting with a member of our curriculum committee about it, and we realized that maybe, just maybe, we could do both.  We could teach just a bit of C++ so students would understand the book, and do our major examples and assignments in Java.  So that's what I'm doing.  The question is, will it turn out well, or end in disaster?


In some ways, it seems like trying to cover two languages in a course where many students can't grasp even one is a really bad idea.  But hear me out.  I am not trying to teach them how to be proficient C++ programmers.  My goal is only to show enough C++ so that students can understand Think Like a Programmer, and even more importantly, so that I can more explicitly illustrate some key concepts in Java that are normally hidden away.

For example, C++ makes you choose whether you are passing by reference.  With some simple examples, I can illustrate the difference between pass-by-reference and pass-by-value more clearly. When we get to Java, I can easily explain what gets passed by reference automatically.  Understanding dynamic memory can also be made more explicit in C++, then applied to topics like creating linked lists in Java.  Even the fact that C++ allows me to build up to objects without needing to have a dummy class in the meantime is quite helpful.

We're only in our third full week of class so far, and we're just getting started on Java.  So I don't know yet how well this experiment will work once we have the two languages going side by side.  But I can say that it has been very beneficial to be able to approach the course using the problem-solving perspective of Think Like a Programmer and the slightly lower level view that C++ allows for things like how variables and arrays are stored in memory.  If this continues working well, I think this could be a winner.

I'll be soliciting anonymous feedback after a couple of weeks of using both languages, and hope to report back after I get some data from students.  Eventually I'll also share more details about the course design itself.

In the meantime, I wold love to hear your opinion - does this approach have potential, or do you see it as a disaster waiting to happen?

2 comments:

  1. does this approach have potential, or do you see it as a disaster waiting to happen?

    Yes, to both. I think that working up from low-level to high-level concepts can work well, and C followed by C++ provides a better route for that than Java, which deliberately hides a lot of the low-level stuff (like memory management). But both C++ and Java have a lot of details in them that need to be learned to be able to read programs (much less write them), and you may confuse students more than enlighten them trying to do both languages at once.

    A Java-first curriculum is deliberately top-down, teaching rather abstract notional machines before getting down to concepts like dynamic memory and pass-by-value vs. pass-by-reference. That can work well also.

    Trying to mix a top-down and a bottom-up curriculum in the same course is likely to result in confusion. You may have a clear view of the concepts at different levels of abstraction, but unless the material is all review for the students, they are likely to be only able to work at one or two levels of abstraction at a time, and giving them multiple views of a concept is more likely to muddy their thinking than clarify it.

    ReplyDelete
  2. It might be worth outlining the progression I have planned:
    - simple C-like programs (C++ without objects)
    - arrays with a mid-level view of a memory model (e.g. extending the variable-as-a-box analogy, with a brief glimpse of a memory map showing actual addresses
    - structs, memory model similar to arrays, pass-by-reference
    [transition to overlapping between C++ and Java]
    - extend structs into objects (not much difference anyway), objects in Java
    - OOP basics
    - dynamic memory (really basic in C++, extend to idea of references / memory model in Java)
    - classes with other classes, dynamic data structures
    [probably transition to just Java at this point]
    - advanced OOP
    [a few other topics not really relevant to this outline]

    So I guess it really amounts to C > C++ > Java, always building up to a higher level as we go. Would you consider this mixing the top-down / bottom-up approaches? I tried to make it a gradual build-up to the higher level view.

    Note: This is a second course. In the first course, they should have experience with the basics as well as using objects at least without (and possibly a bit with) behaviour. They should have a small amount of a high level view of things up to this point.

    ReplyDelete

Comments are moderated - please be patient while I approve yours.

Note: Only a member of this blog may post a comment.