Computer Science Teacher
Computer Science Teacher - Thoughts and Information from Alfred Thompson

October, 2011

  • Computer Science Teacher - Thoughts and Information from Alfred Thompson

    Quality of Testing and Quality of Code


    I see a good number of Tweets in my Twitter stream that just flash by without leaving any impression. Chatty comments between people I barely know (if at all), links to things that don’t really interest me, and other items that really don’t have a lifetime beyond a few minutes after they are sent. But enough them really do make me think or take action that it makes Twitter  pretty useful for me. Recently I saw the following Tweet from Eugene Wallingford.


    Student developers do “interesting” things. For example many of them try to write the whole project before starting to test. Oh they may run the compile to check for syntax errors – as if a program that compiles cleanly will automatically work correctly. And then they start to test. This seldom goes well because there is just much too much to test all at once. Especially for a beginner finding logic errors in a (theoretically) complete program is just too complicated. What makes it worse than just the quantity of code (which let’s face it is not all that much compared to a professional program) but the number of code paths (i.e.. places for things to go wrong) that is just more than a beginner can trace in their heads. Yes, in fact, a beginner writing code this way means that the quality of the code may just not be good enough for easy testing. The result is a long and painful testing process.

    Experienced programmers test small pieces of code. The fewer code paths the easier it is to design a set of test data to test them all. This, test design, is not something we tend to spend much time on in introductory courses. Or perhaps in anything other than a software engineering course which is a shame. I think we could save a lot of students a lot of heartache and perhaps reduce attrition (theory of mine) if we taught them how to test earlier.

    We ask students to do a number of things when creating their own software. I tend to start with three large items:

    1. Understand the problem
    2. Design a solution (algorithm)
    3. Code up the solution

    Many start the testing thinking during (or worse after) the code up the solution part. Not a good idea. At the latest we need to start thinking about testing no later than design a solution. In fact if we understand the problem we should already have a handle of testing. At that point we should know  - what is the right answer for various inputs? What values should be outside the range of what we want to handle and how should we deal with them? In short, testing data is all part of understanding the problem. This understanding should directly lead to test data. Much of this test data would should manually run through our algorithm before we code solutions. When we test our data with the code the results we achieved during manual testing of the algorithm should match.

    Reducing the pain of testing requires several things of which having good code is just one. It’s one important piece of course but not the whole piece. Having good, solid testing data with known expectations of results is a piece. So is testing small pieces of code so that fewer things can go wrong. The fewer the places for things to go badly the easier it is to find and repair them. By coincidence (not) breaking ones code into smaller, more manageable and testable pieces almost invariably results in better code. Sections of code that are too long and that try to do too many things in one module are the huge run-on sentences of programming. In natural language writing run-on sentences are a “bad thing” and make understanding difficult for the reader. Modules of code with too many lines make testing and understanding difficult. They also make modification, expansion, reuse, maintenance and all sorts of other things difficult if not impossible.

    The first programming course is a difficult course to design. Students have to learn a whole new way of thinking as well as a new language in which to express their ideas. That alone makes it difficult. And then there are so many things that we could make an argument belong in the first course. I could see a first course that is four years long if we tried to get it all in. So by necessity things get left out. I am thinking, at this point in my life, that testing is not one of those things we can afford to leave out though. Not that we spend forever on it of course.  I also don’t think it is a separate unit either. Rather I think it is something we talk about as we talk about other things. Include it is the discussion of understanding the problem. Include it with designing algorithms. And include it when we talk about writing the code as something more than just having the compiler check the syntax. It it means that something else waits until a second or third course so be it. On the other hand I wonder if doing better testing and including testing thinking in the whole process might just reduce the amount of time student projects take to complete. It’s a theory. What do you think?

  • Computer Science Teacher - Thoughts and Information from Alfred Thompson

    How Many Jobs Are There For Poets


    I was listening to an Internet stream of Gary Stager presenting a keynote at an education conference in Iowa the other day. The technology for this amazes me but the opportunity it provides is even more impressive. In any case, during his talk he presented a conversation that went something like this:

    "Are you suggesting every kid should learn to program?"
    "Well...we decided every kid should learn haiku..YES! why NOT programming?”

    I had a sarcastic Tweet that I followed this with - We teach school kids to write poetry but not program computers because there are so many more jobs for poets than programmers. Right?

    Now I was a student for many years and a teacher for a few as well so I know the argument that “we’re not a vocational school” or that “not everything we teach is about a job” or that “things we are teaching are part of being a fully rounded out individual.” They’re all somewhat valid arguments. So is “not every one will be a programmer.” But it seems to me that:

    • Programming today is about being a fully rounded out individual
    • Programming skills build the sort of problem solving skills people use in many jobs
    • Programming is a still growing and profitable career but when is the last time you saw an opening listed for a poet?

    Sure the arts are important but even though we don’t teach English to create professional poets (or novelists) we are seldom upset if students write poetry or novels. Likewise we should expose students to the beauty, power, and fun of software development and not be too upset if they do follow that into a career. And if they don’t become software developers they will have good life skills that will help them in what ever field they do enter.

    The late Steve Jobs called computer science a “liberal art.”

    “In my perspective … science and computer science is a liberal art, it’s something everyone should know how to use, at least, and harness in their life. It’s not something that should be relegated to 5 percent of the population over in the corner. It’s something that everybody should be exposed to and everyone should have mastery of to some extent, and that’s how we viewed computation and these computation devices.” via Steve Jobs: ‘Computer Science Is A Liberal Art’ : NPR.

    Personally, for me, a well written piece of computer code is just as cool, just as artistic and just as valid a thing to teach students as a Haiku.

  • Computer Science Teacher - Thoughts and Information from Alfred Thompson

    Be The Robot


    One of the issues with computer science is that some people would rather move atoms than pixels. That is to say that virtual objects, even if they involve images on a screen, are less compelling to some than physical objects doing actual work in the real world. Robots have long been involved in the connection between real and virtual worlds.  How do we control those robots? How much autonomy is there and how much is machines responding to direct human control? Well that all depends. Some tasks are easily programmed and easily done by “rote.” Others have too much variability or require to much in the way of functions, vision comes to mind, that are not as easily programmed. So in  many cases there is a mix. The FIRST Robotics competition includes just that sort of mix. The event starts with a short period of autonomous action followed by a period of remote human control. This works out to create some interesting software developments. The 2012 competition will be adding a new wrinkle though. Microsoft is donating a Kinect device for each team to use. The idea is to allow the robot to become more of an extension of the human player. In a sense, to allow the human to “be the robot.” Some stuff from the press release.

    In the 2012 FIRST Robotics Competition, teams will be able to control robots via Kinect. They will be able to either program their robots to respond to their own custom gestures made by their human teammates, or use default code and gestures. The added ability for teams to customize the application of the Kinect sensor data is a valuable enhancement to the FRC experience.

    This is pretty exciting. During the autonomous period team members will be able to provide some guidance to one (of the three on a team) robot by moving their bodies. Gestures of various types either from sample code that will be supplied or custom code developed by team members will be used to give direction and activity for a robot. Some interesting possibilities. An additional possibility that is not obvious to me from the press release is that a Kinect could become part of the robot as well. Oh there are power concerns, issues of weight, and a small matter of software to make it all work but FIRST students are amazingly clever. So between all the possibilities I can’t wait to see what these students come up with.

    I understand that some teams are getting early hardware so that they can take part in a beta program. FIRST usually runs some sort of beta in the fall before the regular season starts so that they can test new hardware, new software or other new ideas that will probably be part of the new season’s game. Also some software is being developed to act as a starting platform for student teams to use and build around. I don’t know yet when this software will be available though. Not that teams have to wait for this to start experimenting on their own of course. Established teams often have robots from previous competitions to experiment with. The Kinect is not an expensive device and the software to develop for it is free. The Kinect for Windows SDK is a free download and students can either use the Visual Studio Express editions in C++ or C# or Visual Basic to develop. Or high schools can sign up for DreamSpark to get students free professional development products from Microsoft.

    Related links:

Page 1 of 6 (18 items) 12345»