# Difficulties with teaching and learning programming

It’s no secret that learning programming is – at least for some of us – an obstacle course. Personally, it took me years to grasp the skills to be a some-what good programmer. For the last 3 or 4 years I’ve been involved in teaching programming basics for freshmen in my university. I started with helping fellow students, then started as a mentor for department and nowadays in addition to previous, I work as a part-time teacher on our courses.

I’ve come to conclusion that one of the reasons for it being so difficult is, that one needs to learn a huge amount of different things at the same time for being able to move forward.

I think that there are three important subtopics that students need to learn at the same time: programming language syntax, what can be done with programming languages and problem-solving. For many students, it seems that they don’t really realize that there is more in the classes than just learning the syntax: most of our exercises and problems don’t arise from that need but from learning problem-solving. Too often do I hear the sentence “This has not been taught to us” while assisting students with their exercises. True, they have not been told the solution but they have been given all the tools to code but they need to come up with the solution themselves.

One of the hardest parts in teaching is to remain on the level of solving everything with basic structures: we often tend to know trick or two to easily solve the problem on a one-liner which once again raise the statement “but they haven’t taught us this”. I’ll take an example from our course and how it can be solved quite differently.

We use Java as teaching language, so bear with me.

The exercise is: “Given a string that contains a binary presentation of a number, calculate and print the 10-base value.”

`public static void binaryToInteger(String binarystring) {`

int tenBase = Integer.parseInt(binarystring, 2);

System.out.println(tenBase);

}

This is of course a valid, quick and smart way of doing it. But I think we all can agree that it doesn’t really teach you anything – maybe besides finding the solution on Google. Well, let’s use a for loop:

`public static void binaryToInteger(String binarystring) {`

int sum = 0;

int exponent = 0;

for(int i = binarystring.length() -1; i >= 0; i--) {

if(binarystring.charAt(i) == '1') {

sum += Math.pow(2, exponent);

}

exponent++;

}

System.out.println(sum);

}

Here, it seems like now it’s more like a rookie version. And this is what is often showed to students. “But we haven’t been taught to use Math library” and yes, they have not. At this point, we could argue if teaching reading the API and googling for what it has to offer is what we should teach at this point. But often it might be too early and here we are not just trying to solve a problem but also to practice basic structures. So usually at this point student finally gets bit sad to see that oh, even the more experienced coders can’t solve this. That’s because we often don’t need to go down to the lowest level of implementing the pow()-function.

So:

`public static void binaryToInt(String binarystring) {`

int sum = 0;

int exponent = 0;

for(int i = binarystring.length() -1; i >= 0; i--) {

if(binarystring.charAt(i) == '1') {

int power = 1;

for(int j = 0; j < exponent; j++) {

power *= 2;

}

sum += power;

}

exponent++;

}

System.out.println(sum);

}

After implementing the power function ourself, we have reached a solution which is done with basic structures that have been taught. That is the difficulty of assisting and helping students: how to keep everything down to the very lowest level that they have been taught.

Another issue is what student really has to know and learn to be able to deal with situations like this. Remember that the students I’m talking about, are people who have very little programming experience. Basically 3-4 weeks of our Java course.

So students have to have a strong feel on basics. Ideally, they would have been tinkering around with programming for those weeks. Usually, the truth is closer to students having only done compulsory exercises. Luckily we have quite a lot of those exercises so they have done more than we used to couple of years ago. Next comes the tricky part. Student needs to start breaking the problem into smaller, computer-understandable pieces. For most, this is the most important and most difficult part.

Ability to break problems into smaller, computer-understandable pieces is something that obviously comes only with experience: once you know what is possible, you know how the problem needs to be formulated. And it is something, that cannot be directly taught. If we tell people direct approaches to solving problems, the exercises become insignificant. We can only point the way.

In the end of the day, it’s all about attitude towards learning that counts. If you have an open-minded approach and willingness to learn, you will learn to program, no questions asked. But for most of us, it won’t be easy and it will take time. But in the end, it’s worth it.

(For my students who reached the end, please do not be offended. I still love you and I still continue to help you every way possible.)