tags:

views:

322

answers:

12

So here i am trying to teach my friend the art of C++. He is no newbie to programming, but his area of expertise is somewhat further away from C++. He knows html, php and java fairly well, but it seems this is of no use when it comes to writing a C++ program. We already went through the basics, talked about pointers and such. He even had a course at his university about C++ but he gave up halfway through. It seems that he really understands basic theory - the problem is he fails when it comes to actually using what he knows to write programs.

So what i'm trying to do now is to give him homeworks. The task is always to write a small program, such as a primitive calculator (input two numbers and a letter which determines operation that should be performed...) etc. The idea behind this is to force him to actually use the language to solve problems, debug it and see why it fails and learn from it. But it seems it does not work, since every time i try to make it harder and give him a more complex homework, he is not able to solve it. What should I do now? I'm really running out on ideas of homeworks and i have doubts that this approach is good. Moreover, new semester starts just right now and he has to pass the C++ course this time. So there is even a deadline - the end of this year.

SO, can you help here?

A: 

Teach him to consult SO when he gets stuck. :)

Jon Rodriguez
A: 

You're doing good, you or even himself should put goals as a developer, if he's experienced in java there shouldn't be a problem with syntax.

besides, he's got the basics, and he's not a beginner, so the best you both can do is get good guides, cookbooks, and programm, put some goals and write code.

jgemedina
+3  A: 

I guess a lot depends on what he is actually having problems with. If he knows Java, I assume he should know the basic concepts of OOP, collections etc., right?

Can he solve the same tasks in Java well? If so, what is it that stops him with C++: lack of understanding of pointers (that can be difficult for many), memory management, destructors, or lack of knowledge about the class library, STL, templates, ...?

You could try sitting through a task with him to see where he has problems, and help him there, step by step.

Back then I really liked Andrew Koenig's Ruminations in C++ - it had a very different take on teaching C++ from the ground up, starting with good, real-world (albeit simple) little programs which actually did something useful, while at the same time teaching the best idioms of the time. Although it is quite outdated by now, sopme of its content might still be useful when adapted to the latest standard.

Péter Török
I think you hit jackpot here: "Can he solve the same tasks in Java well?" - that is the answer to the question of where is the problem.
Arrieta
A: 

He missed some of the basics when he started learning how to program. One of the basics is, for example, that you are responsible for all stuff you allocate - just as in real life, you have to put away what you took out like an adult, not just throw stuff on the ground and expect other people to clean up after you.

I think your approach is good, but there is damage already done, and you have to repair it before you can make progress. You'll have to back to the basics. What is a variable, really? He probably is not aware there is actual memory storage somewhere, and the variable is just an alias to the address that points there - and once you have that, you can explain arrays and pointers, and so on.

Really, go back to the basics first, I think that's what he is lacking.

foo
And while you're at it: if he wants to commute, teach him to breed his own horse.
reinierpost
I'm not relying on the "horse arse width" story here how our railway widths came to be, but knowing the basics is important to understanding. You don't have to breed horses, just to know that people once rode them.
foo
+10  A: 

The problem seems to lay elsewhere. If you need to teach a Java programmer how to program a simple calculator, the problem is not the language, the problem is the fundamental understanding of programming.

I feel that the worse way to learn programming is by writing toys that nobody uses. The best way, according to me, is to start with simple but useful tools, because that puts pressure on the programmer: the thing will actually be used by someone else; it has to work!

If the task is administrative, then have him write a disk usage utility and tell him you'll be using it. If the task is scientific, have him write a nonlinear equation solver.

Sure. C++ is a complicated language to master (I am not even remotely close, and I know only two people who I would consider professional C++ programmers). However, it is not like you are teaching him Haskell, or some completely different programming paradigm. Aside from memory management and the subtleties of actually managing the pointers, I cannot see much of a paradigm shift from programming Java and programming C++. To be sure, it is more difficult because it is a lower level language, but in the end it is an object oriented approach to software design.

D. Knuth has a witty rationale for using his own brand of assembly language to teach algorithms:

People who are more than casually interested in computers should have at least some idea of what the underlying hardware is like. Otherwise the programs they write will be pretty weird.

I think the same can be said about memory management. Even if you program in a garbage-collected language, you should at least understand that there is such a thing as memory and that an object is either passed by value or by reference. I'm not saying that it is easy to master, I'm saying one should at least understand that such a thing is happening behind scenes, and that in C++ you manage the behind the scenes.

Arrieta
`v=If you need to teach a Java programmer how to program a simple calculator, the problem is not the language, the problem is the fundamental understanding of programming.` This is true. Learning the VERY fundamentals of C++ should not be THAT difficult if you know any other language.
Falmarri
The calculator was solved by him, more complex tasks were not.
PeterK
@PeterK: well, you're better qualified than us to determine if the problem is that 1) he's not interested, 2) or that he can't really program *in any language*. A proficient Java programmer shouldn't get stuck trying to solve problems in C++. He might produce a buggy mess that leaks memory and crashes, but he shouldn't be *stuck*. If he gets stuck, then the problem is his *programming* skills, not his *C++* skills. Of course, that problem can be surmounted as well, but it helps to realize what the problem *is* before trying to solve it.
jalf
Seems we are going somewhere here. The thing is, that he probably thought "hey, no one will ever use it, so if it does not work nobody will bother me with it". Now i'm forcing him to fix his bugs and surprisingly he is able to do it!
PeterK
@PeterK exaclty. I find that I myself work 10 times faster and 2 times better when I know that my product will be used by someone else. It provides me with a concrete opportunity to demonstrate to myself (and, sure, to my team) that I can do good work.
Arrieta
+1  A: 

If he knows how to program Java, have him provide solutions in Java and C++, tell him to do it the Java way when he does not know how to do it in idiomatic c++. Then go over what the differences are in C++ to the code in Java and why is it so.

David Rodríguez - dribeas
The side effect of this is that if his problem is related to programming fundamentals, then he should have trouble with the Java solution as well. If he can get it in Java but not in C++, then it's more likely a language-oriented problem. Just make sure the solutions he's coding are largely his own code and not just stringing together a bunch of pre-made libraries.
bta
A: 

I would like to befriend you for what you are doing ;-). Anyways, I would first figure out where your friend is getting stuck. Is it in general problem solving or is it with using the C++ language constructs & idioms? Based on your findings you can either direct your friend to improve his problem solving skills or the language skills. If it is the language, I would certainly look into the C++ Primer book by Lippman, Lajoie and Moo and will advise the friend to solve the exercises. Though the book runs to 800+ pages, anyone with prior experience with programming languages & with minimal experience in C++ should be able to read the book within your suggested time line.

naivnomore
A: 

I'll just echo Truncheon's answer, but formulated in reverse. Personally I've always detested C++ (and C for that matter) because of their lack of memory management. It's so easy to do trivial everyday things like string manipulation wrong in those languages. If someone should tell me to program in C or C++, I'd oblige (as I've done before) but I wouldn't be happy until I could use libraries or a framework that resolve the basic issues I have with the language. (The same thing with JavaScript.) Your friend may (or may not) be in the same boat.

reinierpost
I was like you until I knew about C++ standard library. It is really easy to do trivial everyday things like string manipulation correctly once you learn the standard library.
naivnomore
"until I could use libraries or a framework that resolve the basic issues I have with the language" -- as @naivnomore said, you *can*. The standard library does that for you. :)
jalf
Yes, the standard library helps a lot.
reinierpost
+1  A: 

He knows html, php and java fairly well
This statement kind of gives me the idea that he hasn't done a proper programming where he had to understand/visualise the flow of his logic. Yes, he did some programming. But he probably never knew how his program 'flows'. And from the previous 'programming' experience suggests he's more attracted towards visual cues. I highly doubt he can do a full program in Java, even the same ones you asked him to do in C++.
The first programming language I learned was C++ and I had a very good teacher who made us start programming by first visualising the flow of our logic by drawing flow-charts. Once we had solid knowledge of how to visualise our logic, he started teaching us the basics of C++ and the whole class caught up pretty quickly.
So I guess trying to make him learn how to visualise his logic in paper and then making him translate that logic into a C++ program would help him better than just making him learn all the concepts of C++ without a proper context.
An example would be to first teach him about loops in flow-chart, ask him design a flow-chart for a problem, say printing numbers from 1-20. Then teach him for-loop in C++ and then ask him to write a program to do the same thing.

Vite Falcon
A: 

Learning to program with modern, highly abstracted languages such as C++ and PHP means that as you learn more about what's going on, things get more and more complex. To understand more complex programs you need to know, at least in theoretical terms, what's going on behind the scenes; modern languages are designed to hide those details. So trying to figure out what's going on means fighting the language paradigm you're using. Any low level details taken care of by the language for the programmer also means hidden from the programmer.

Now, if the programmer already understands what's involved with those low level details, and the conditions when they might make a significant difference, that programmer also knows when to break the language abstraction veil. Note that this is how programming languages developed or evolved. We started with machine code and assembler, then very low level conveniences, then some early higher level, portable languages such as FORTRAN and Lisp. (Note that was not Common Lisp and Fortran 2008).

Obviously, you can learn to become an accomplished programmer starting with PHP or C++. But while you can get some fairly complex results fairly quickly, I think it might take more effort to become a really advanced programmer.

mpez0
A: 

Hi Peter, the web is plenty of free or paid self-paced training courses on C++ (an example of free, Herb Schildt's "C++: A Beginner's Guide"; take a look to "Sams Teach Yourself C++ in One Hour a Day, Sixth Edition" for an example of paid material). There are also free and paid IDEs for making the development experience (coding, building, testing, debugging, etc) reasonably easy (!) -a widely used free IDE is Visual C++.

Teaching to somebody is as frustrating as learning (the front sidewalk). A person must be motivated to learn in the first place. I must ask here: is your friend interested in learning C++? Is he/she more interested in learning than you to make him/her learn? Understanding that will make both of you guys lives easier.

Let's asume a worst case scenario: neither you are interested in teaching nor your friend wants to learn but he/she must learn in order to, let's say, apply for a job, pass an exam or whatever (and you want to help because your friendship). So learning C++ becomes more a mean for another purpose than an end onto itself. Next comes to get a bit of background of that ultimate purpose and try to turn the learning process tailored to that goal. For instance: what if your friend is interested in a job where will have to build an app for the financial industry. It's highly probable that background on C++ math libraries will be required, and still probable that DB background is required as well (as those apps keep information about financial indexes, customers, balances, etc.) In such case, put the emphasis on those scenarios and the training course will come up backward: from the goal to the facts.

It just works: in my personal case, I learned C++ by coding a brain game. That goal made me deal with the Standard Template Library, with some UI extensions for Windows (MFC in my case, but depends on the OS as that's not standard), OOP, basic types, etc. I skipped file I/O and other things for a better opportunity. I haven't yet learned all about C/C++, I made a lot of progress for my gaming purpose, though. Does this make sense?

Diego Dagum
A: 

How about trying something a little bit unusual:

Tell him to teach you Java.

By asking him to tell you what he knows about the language he is familiar with, you can delve into his way of thinking and could probably help to see why he had a hard time understanding C++ (and he will be less provoked since he will be talking something he already knows well).

Tell him to tell you what he thinks about basic Java constructs (loops, conditionals, classes) and how those constructs works. You need to be very attentive to his every word; take note of his understandings that seems to look fishy.

Lie Ryan