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

August, 2012

  • Computer Science Teacher - Thoughts and Information from Alfred Thompson

    How To Read Code


    We don’t teach students how to read code. Actually we don’t event teach them that they should read code for the most part. The closest we get is sample code in textbooks, demos, and for AP CS teachers the case study. Even there I think we could do more. One of the great learning experiences of my early learning career involved reading some code. My professor handed me a deck of cards (yes this was some time ago.) He explained that they had purchased this set of functions to help enable graphics programming but somewhere along the line the documentation had been lost making this code unusable. There were almost no comments in the code either. My task was to figure out the code and create some documentation so that other people could use these routines. With all the enthusiasm and confidence of youth I jumped in with gusto. It took a while but I accomplished the task. In the  process I learned a lot about both figuring out code and using graphics functions. Both served me well over the years. I still think about that now and again wondering if that sort of thing could be globally useful in education. Or is it just mean? Smile

    I still enjoy reading and figuring out other people’s code. In some ways that, especially when debugging is involved, is more fun for me than writing code from scratch. I’ve never really organized my thoughts about reading code before but I’ve been thinking about it lately and thought I’d put it down so you all could tell me how wrong I am. Smile Or at least tell me what else you do when studying code that is new to you.

    I like to read code on paper. Yes old fashioned and kills trees but it lets you look at more code at one time than you can see on a screen. I know that there is some discussion that any code that doesn’t fit on one screen should be broken up into smaller pieces and to some extent I agree. On the other hand some things don’t fit on one screen and more then that often you can benefit from more context than one method on one screen. Also I like to draw lines and write notes and that is easier on paper.

    In he early days code was often “ugly” with no indentation or helpful formatting. In fact we used to have special software called “prettyprint” programs that would reformat code by adding indentation, consistent use of white space and “punctuation.” I especially remember using software like this on PASCAL programs when I was teaching high school. The need for this sort of thing is less today than it used to be. IDEs like Visual Studio for example will automatically format code and even include helpful color coding. These things make looking at code, on line or on paper, a lot easier. Reading poorly formatted code is harder than you want it to be so if your code is not well formatted then fixing that is a great first step.

    Next I like to look at variables. I like to understand the names, especially any coding standards that are being used, and what they mean. Knowing that a variable is an integer as opposed to a double is important. Making sure that coding conventions (do integer variables start with an “I”) and being followed (is a variable a double but its name suggests an integer) is a good place to look for logic or runtime errors. Keeping an awareness of scope of variables is also important. Comments on variables and throughout the program can of course be very helpful. My attitude about comments is “trust but verify.” That is to say that I try to confirm that the comments describe the code that they say they describe. If they fit – great. If they are wrong – fix them.

    I like to draw lines to highlight things like the beginning and end of a loop, a module, or the actions inside a decision structure. The spacing along may be enough for some but I like that line down the side of the page. It helps me visualize the scope and the nesting of statements and variable scope. This also helps me to study the code to make sure the start and end are logical and correct. Once you have all the scopes figured out you can start from the inside and work out or from the outside and work in. In practice, if the code is at all complex, you may have to read it both ways. Take notes of what is going on. It helps.

    Equations require a close look. One has to understand both what the formula is supposed to do but that the variable types work the way the programmer intended. There is no magic “do what I mean” instruction. All too often the computer follows its own consistent logic when a programmer was hoping (or miss-assuming) some different way of doing things. It’s also important that the values that are returned are of the type that the method says will be returned. A reason that I find paper useful is to double check parameters between where a method is called and where it is created. Again modern IDEs can make that easier for you. While reading code in the IDE IntelliSense in Visual Studio or other autocompletion tools can make checking a lot easier without bouncing around the file. So a mix of online and offline reading can be very useful. Use the tool that makes the most sense at the time.

    The big gun in reading code can be a debugger. Single stepping through running code, assuming you are trying to understand code that works, can teach you a lot about what paths are taken and show you where things are not going where you think they are going. This is a lot easier today with modern IDEs compared to reading binary code in light switches back in the day. Today anyone can run a debugger. And more people should!

    So that is the basics. I’m sure I’m missing things that I do without really thinking about it. What advice do you have for someone reading code?


  • Computer Science Teacher - Thoughts and Information from Alfred Thompson

    Ten Commandments of Computer Ethics


    I ran into these Ten Commandments of Computer Ethics created by the Computer Ethics Institute while looking for something completely different. Isn’t that so often the case? I like them. I think they are useful guidelines that are worth thinking about and discussing. Ethics can be complicated though. Some complain that these rules are too simplistic and overly restrictive. This set of class notes expands on the commandments and includes a claim that the “10 commandments contradict the hacking communities constitution” EDIT: See also Stephen Downes' response at Computer Use Guidelines

    • Thou Shalt Not Use A Computer To Harm Other People.
    • Thou Shalt Not Interfere With Other People’s Computer Work.
    • Thou Shalt Not Snoop Around In Other People’s Computer Files.
    • Thou Shalt Not Use A Computer To Steal.
    • Thou Shalt Not Use A Computer To Bear False Witness.
    • Thou Shalt Not Copy Or Use Proprietary Software For Which You have Not Paid.
    • Thou Shalt Not Use Other People’s Computer Resources Without Authorization Or Proper Compensation.
    • Thou Shalt Not Appropriate Other People’s Intellectual Output.
    • Thou Shalt Think About The Social Consequences Of The Program You Are Writing Or The System You Are Designing.
    • Thou Shalt Always Use A Computer In Ways That Insure Consideration And Respect For Your Fellow Humans.

    The Ten Commandments of Computer Ethics were first presented in Dr. Ramon C. Barquin's paper, "In Pursuit of a 'Ten Commandments' for Computer Ethics."

    To some extent the commandments are a bit simplistic but that argument can be made about most lists of ethical practices. The proof is in the implementation and how the spirit of the commandment is interpreted and not just in the literal words of it.

    I have known any number of students who would ignore commandments 3 (snooping) and 7 (unauthorized use) as they see the world as their playground and believe they have rights to go anywhere and use anything that they are not physically restrained from doing.

    I’d love to hear other comments on these “commandments.” I’d also like to hear about the results of classroom discussions on them with students. If you talk about these or other sets of ethics rules in your classroom (or business) I’d love to hear about it.

    Commandment 6 (dealing with proprietary software) is anathema to people who believe that proprietary software is itself unethical. Is there middle ground on this issue? Worth some discussion for sure.

  • Computer Science Teacher - Thoughts and Information from Alfred Thompson

    Construct 2 - the HTML5 game maker


    I’ve been experimenting with Construct 2 from Scirra the last few days. Construct 2 is a program from creating HTML 5 games. What really got my interest was that there is the ability to create Windows 8 games using Construct 2 with Visual Studio 12.  The Construct 2 development environment is pretty easy to use and I find that some similarities to Visual Studio (among other tools) is helpful in finding ones way around it. The image below shows the layout of graphical objects on the screen as well as the properties box, list of images and outline of the project. Very similar to what I am used to.


    The coding involves what is called an event sheet. On an event sheet specific events (for example a mouse click) are specified and one or more actions are described to be the result of that event.


    I really like that for a single event you can easily specify different actions for different objects in the game. And of course by the nature of the IDE syntax errors are avoided which is a plus for beginners.

    Programs/games are created in the Construct 2 IDE and tested in a web browser. Once a game is completed it can be exported into several formats including the experimental Windows 8 app.


    My next step is to outline the things you’ll want to include in a game that you make with Construct 2 in order to make it fit the guidelines for inclusion in the Windows Marketplace. But in the mean time Construct 2 looks like an interesting tool for starting with game development as a way to hook studnets on to software development. Anyone else using it? What do you think of it?

    Getting started links:

Page 1 of 7 (19 items) 12345»