Friday 13 February 2015

Good code is important

Good, clear, well structured code is key

I responded to a tweet from @CSTeachingTips  which stated 

"Loosen your requirements for style sometimes to keep students motivated to write programs."

My response was

"This just is so wrong. Good structure HELPS those who find it difficult. Motivate them with fun, side activities nt bad code"

Now first let me say that I think a lot of the tips on the site CSTeaching Tips site are great and especially so for inexperienced teachers or those lacking confidence with coding and computer science in general and I like popping in and reading them from time to time.

I also see where they are coming from with this tip. Coding can be hard work. Getting it right, typing in lines of code (although many professional coders will use libraries of code and seem to type less and less) and the inevitable bug tracking can be a pain.

But that's where I differ from the tip that the team gave. It seems to me that keeping to an accurate, well-defined style and structure when coding is one of the most important parts of helping our learners get the most from their coding experiences. Without these structures and conventions it can quickly become very difficult indeed for someone trying to help a learner with their code to track down a bug or a feature that is not working as hoped. This is especially so for the inexperienced teacher.

The key to assist engagement is to teach in creative ways, keep a good pace to a learning activity, provide a variety of experiences within the lesson and aim to make the tasks relevant and interesting. There is no reason a lesson, or series of  lessons, needs to be filled with pure coding all the time. Mix things up with some fun activities that demonstrate a particular issue, concept or outcome. Add some discussion about a topic and set some interesting 'computational thinking' problems that explore the problem solving aspects of Computer Science and there are lots more.

But please, please don't relax standards and styles, it will only make things much worse.



2 comments:

  1. Hi Alex,

    Thanks for the post!

    The tip wasn't mine, but one of our contributors -- but I've certainly had to learn that sometimes relaxing style requirements is important. I think you'll agree with how I've applied the tip in my teaching.

    When working with students one-on-one as they're first trying to master writing code that would be able to run, I've learned to bite my tongue about style. Here's an example: Students as they're learning to use booleans, if-statements, and the keyword return will often write code like this:

    public boolean foo( int x) {
    if(x == 1) {
    return true;
    } else {
    return false;
    }
    }

    When I first started teaching, right when I saw this about to happen, I would interrupt them and provide hints toward a more elegant solution:

    public boolean foo( int x) {
    return x == 1;
    }

    Now I let them write the ugly code and figure out that it works without interruption. After that I can offer my suggestion as a "cool" optimization rather than scolding them about their bad style.

    I think there are lots of examples of this where I need to loosen my style expectations. The tip also had suggestions for how to motivate students to use good style :)

    http://csteachingtips.org/tip/loosen-your-requirements-style-sometimes-keep-students-motivated-write-programs-especially

    Thanks again for your post! We can go back and make the tip clearer by explaining some of the (reasonable) examples of why loosening style requirements might be the right pedagogical decision.

    - Colleen

    ReplyDelete
  2. Colleen,

    Great reply and I agree with approach in your example but I would characterise it as more about 'code optimisation' than loose style. I think some examples like this would be great.

    Happy coding.....

    Alex

    ReplyDelete