Teaching Computer Science Bottom-Up

When I started teaching the new batch of Computer Applications students this year (class 9), I had it in my mind to do it bottom up, to try and give them a good sense of how computers actually work, how the 0’s and 1’s get so many things done. I wanted them to not only be able to write java programs in the prescribed IDE, but also have a good command over the machine, visualize what happens when they run a java program and easily learn other programming languages, work with microcontrollers and so on.

I started with teaching them how to use the GNU/Linux command line interface, to carry out the various tasks they normally do by clicking, dragging and dropping. Typing commands and making things happen turned out to be an exciting thing for them to learn. I had soon taught them to navigate the file system, copy and move files and folders, find out and change file permissions, open files using appropriate applications etc. It helped that I have just 4 students, all of whom are quite excited learning about computers and working on them.

Making them open files of different types with different applications gave me a context to introduce binary numbers and the different ways in which binary digit sequences can be interpreted. Usually it’s just stated that computers can work with only 0’s and 1’s, and that the 0’s and 1’s refer to different voltage levels etc. Then the focus turns to learning the binary number system, and the procedures to convert decimal numbers to binary and back, and some binary arithmetic.

But I saw the whole world of binary numbers in a new way, for the first time. What struck me was that computers interpret binary digit sequences in a variety of ways, not just as numbers. We want the computer to interpret binary numbers in several ways, as different kinds of data- text, numbers, images, audio- and instructions. I felt it would be exciting to try and pass on this understanding to the students.

I gave them a simple introduction to the binary number system, and then went on to making them edit text files and bitmap images using a hex editor. This gave them an idea of how the same set of bytes can be interpreted differently. As a project they even drew a 10×10 pixel image and typed in the hex code referring to the bitmap file format and saw the picture in an image viewer!

I then spent a few classes discussing the different kinds of numerical interpretations of binary numbers- unsigned integers, signed integers, fixed point numbers and floating point numbers. They also learnt about the problem of overflow because of the limited range of numbers. To illustrate overflow I wrote a few programs in C and made them run the executable from the terminal. That also gave me a context to talk to them about source code, compilation and the executable. (I was able to even explain to them the difference between proprietary and free software.) This was very useful, because the next interpretation of binary numbers I wanted to show them was that of instructions. I could easily tell them that the executable file contained bytes which the processor interprets as instructions.

And to actually show them this, I used the Hack CPU emulator developed by the authors of the book/course “The Elements of Computing Systems”. It uses a-simple-to-understand-yet-fully-functional hypothetical processor. I explained the architecture and instruction set to them, and even made them write an assembly program to add two numbers, to compare two numbers and to multiply two numbers by repeated addition. This made them learn important concepts like sequential execution of instructions, memory access, usage of registers, rudimentary arithmetic and logical operations, conditional and unconditional jumps- together they cover most of the concepts in elementary programming. And for each assembly program, I kept showing them the equivalent C program, and they were exclaiming how easy and intuitive the C programs are!

I’ll write in more detail about each of these later. But it’s been exciting for me to discover how children of 14 can learn computers at a level of detail that one would normally think is too advanced. And I strongly believe that this what’s-under-the-hood understanding will stand them in good stead whatever they learn in computers.

11 thoughts on “Teaching Computer Science Bottom-Up

  1. Quite an interesting and innovative approach. I’m sure I would have been super interested in the subject after this. Then again, I got interested in computers after learning that they were ” High speed electronic devices that convert raw data into meaningful information”; so I’m not a good judge. Just a few things I wanted to ask. Did the students have any difficulty with what you were teaching? If so, what did that have difficulty with? Also do you think there would be problems scaling this up to a classroom of about 20 students? How long did you take on each of these topics? Would be interesting if you could give specifics of the number of teaching hours on each topic and stuff.

    p.s. I like these kinds of posts. So please keep them coming 🙂

    1. Did the students have any difficulty with what you were teaching? If so, what did that have difficulty with?

      With almost all the topics, I think, the students were kind of pushed to focus completely on the task at hand. And there were times when they switched off, and seemed to be lost. I remember especially the class when we were analysing the instruction set of the Hack processor, and the way binary instructions are interpreted.

      But more than any inherent difficulty in the topic, I think a lot depends on the specific examples you use to introduce it, and which direction you approach it from. With some examples, you can think through the questions it could trigger and have a good enough picture of that hinterland before you start teaching. Sometimes, especially when you are teaching something for the first time but it keeps happening, you don’t have a rich enough picture of that hinterland, and it’s quite likely that the examples you give trigger questions that you’ve not really thought about- this can lead to confusion in the students mind, if the questions are not dealt with properly.

      So part of my preparation for teaching these topics was in dissecting from the point of view of a student the examples that I presented, or the assignments I gave them beforehand.

      Also do you think there would be problems scaling this up to a classroom of about 20 students?

      Since I had only four students, I had the luxury of keeping a close watch on their progress when they were doing the projects and assignments. I think it should be possible to scale it up, with some thought.

      How long did you take on each of these topics? Would be interesting if you could give specifics of the number of teaching hours on each topic and stuff.

      Command Line Interface – 80 mins x 2
      Binary numbers, editing text and image files in hex editor – 80 mins x 3
      Types of binary numbers – unsigned and signed int, fixed point, floating point – 80 mins x 3
      Hack architecture and instruction set – 80 mins x 2
      Assignment on add, compare and multiply – 80 mins x 2

      I have two 80 mins sessions with them per week.

  2. A few more comments. Programming is about solving problems and doing this by abstracting away as much of the details as you can so that you can look at it from a higher level and solve the problem. What most preliminary courses do is teach students to solve problems in an interactive way first and then learn some basic programming from this. And only after this (if ever) at some point do they learn about the whole 0s and 1s business.

    From a philosophical point of view, it could be argued that the fact that everything is stored as 0s and 1s is not a necessity but a consequence of engineering concerns and stuff. In theory, you could have a computing system with a completely different sort of machine language.

    Anyway, my point is that theoretically, it is not necessary or essential to know all this to program. In a way, one might find it difficult to think abstractly about solving a problem with all this information. Would it be more interesting (and maybe practical) for the student to learn to solve problems first and think computationally before going into such basics? What thoughts?

    1. I see what you are saying. To be honest I haven’t done any serious programming, beyond the simple scripts I write now and then. Perhaps it’s an unexamined assumption on my part that this low-level understanding will help them in other areas. Maybe not.

      But I don’t think it would be a hindrance to think abstractly. As I mentioned in my post, even when they were writing the assembly programs, I kept showing them the corresponding C programs, and told them that later on they’ll be coding at that level, not at the level of registers and jumps.

      Given my closer relation to hardware and electronics, this is something I just find exciting to share with students.

  3. It seems Python would be a better choice to start teaching programming. I believe students will find interactive programming more interesting where the functions can be defined on the fly.

    1. Python would have been my first choice in teaching programming. But the syllabus specifies java as the programming language. 😦

      But my approach, going bottom up, would probably have been the same even if I were teaching python.

  4. What you have said you are teaching those kids, I do not understand them even now after completing four years of B. Tech Engineering. I strive to be teacher, seeking teachers to be inspired by. I guess I have found one such person here.

    I would like to meet you in person and talk with you about what motivates you and inspired you to take this up.

  5. In my very first job, I was assigned to assist a training in VMS (an operating system from DEC). My role was to keep the environment ready for participants to work on, while the lead will take sessions.

    The participants were senior officials from a public sector firm in Kerala. Naturally they were happy to find me among the faculty.

    One of the exercises was to restrict the login of participants (to show the power of superuser). After we disabled logins of participants, they were asked to login, which of course they were unable to.

    The lead was full of enthusiasm and explained about the capabilities of the superuser. The participants hardly noticed the excitement in his voice, as they were irritated that the system was not accepting their passwords, and they did not understand the reason!!! Often that is what happens if the session is post-lunch and the participants are a little old while faculty is relatively young 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s