Testing, Testing

With CS4All being the buzzword of the day we're paying a lot of attention to the fact that when we teach a CS class for all students, most of them won't end up studying CS or going directly into a tech heavy field.

Among those that do study CS though, there is another division. Those studying CS as an academic exercise or to go on to graduate studies and those who are going in to the tech sector. For those going into the tech field, it's important that they're prepared in terms of software development, design, and all those goodies not covered in CS classes.

I'm not advocating removing the good stuff currently in most colleg CS curricua, although I will say that most CS programs I've reveiwed could benefit by trimming some requriements and adding some electives. I am advocating doing more than telling your students "comment your code," - a refrain many undergrads have heard frequently with little guidance.

I'm advocating to begin by bringing in tools and practices that either don't detract from current CS classes or in fact can add to or streamline them.

Last year I wrote about using Git and GitHub in my classes. Students have to submit projects anyway and frequently have to work in teams so using Git and a Git hosting service can actually make both student's and instructor's class experiences better while introducing them to an industry best practice.

Today I want to talk about testing.

Students are always told to test their code but frequently not given tremendous guidance. The results can be:

  • projects that don't compile
  • projects that compile and run but not the way they're supposed to.
  • wonky input or interfaces
  • projects that don't work for all cases

On the instructor side, we have to evaluate the student's submissions and deal with all of this. Some teachers use auto graders to help. I have mixed feelings on them. On the one hand they can speed up grading but on the other hand it's important for me as the teacher to actually dive into the student's code. In any case, using an auto grader is actually somewhat similar to running a test suite.

Why not have the students create their own test suites? If done right, this should encourage students to evaluate their own code more carefully and also cut down on the time it takes the intructor to evaluate a given submission.

This means that we have to use a testing framework with a very low cost of entry.

I ended up finding doctest for C++. It's really simple and just a single include file. This means that students don't have to actually install anything on their machines. Here's the example from the project page:


Basically, the students can just start writing tests.

Python also has a couple of low friction testing options. One is to use the built in doctest facility. Basically you put sample runs in the doc string at the top of a function with the expected output:

def factorial(n):
    """Return the factorial of n, an exact integer >= 0.

    If the result is small enough to fit in an int, return an int.
    Else return a long.

    >>> [factorial(n) for n in range(6)]
    [1, 1, 2, 6, 24, 120]
    >>> factorial(30)

    import math
    if not n >= 0:
	raise ValueError("n must be >= 0")
    if math.floor(n) != n:
	raise ValueError("n must be exact integer")
    if n+1 == n:  # catch a value like 1e300
	raise OverflowError("n too large")
    result = 1
    factor = 2
    while factor <= n:
	result *= factor
	factor += 1
    return result

if __name__ == "__main__":
    import doctest

This might seem a little cumbersome, particularly if you look at the example at the link. It also requires the tests go on top of each function and that the tests will print out as part of the docstring.

The other easy Python option is the built in unittest module.

Here's an example of testing strings from the link above:

import unittest

class TestStringMethods(unittest.TestCase):

    def test_upper(self):
	self.assertEqual('foo'.upper(), 'FOO')

    def test_isupper(self):

    def test_split(self):
	s = 'hello world'
	self.assertEqual(s.split(), ['hello', 'world'])
	# check that s.split fails when the separator is not a string
	with self.assertRaises(TypeError):

if __name__ == '__main__':

I havn't played with Java testing in years but I'd guess there's something similarly light weight.

Tomorrow I'm hoping to finish the groundwork on using C++ doctest with my class and I'll write another post afterwards. Probably after SIGCSE since I'll be attending that from Wednesday on.

We'll see how this goes but I'm guessing it will work well. If it does, it should make my life as a grader easier and also get the kids on track to using test frameworks - something they'll need wherever they end up.

Using Emacs 42 - Git Gutter and Time Machine

One day I'll do a Magit video but since there are already some good ones out there I thought I'd share a couple of other great git related packages.

The first is Git Gutter which adds markers on the side gutter of your buffer so you know what's changed since you're last commit. I pretty much use it exclusively for that visual but it can also be used to cmmit and revert individual chunks of your changes.

The second is Git Timemachine which lets you move forward and back between commits.

The video demos both.


Using Emacs 41 Pandoc

Another Emacs quick hit today. Actually, not really Emacs. Today's video is a quick, really quick, look at Pandoc. Pandoc is a document converter.

Here are the formats that Pandoc can covert read from:

Markdown, CommonMark, PHP Markdown Extra, GitHub-Flavored Markdown, MultiMarkdown, and (subsets of) Textile, reStructuredText, HTML, LaTeX, MediaWiki markup, TWiki markup, TikiWiki markup, Creole 1.0, Haddock markup, OPML, Emacs Org mode, DocBook, JATS, Muse, txt2tags, Vimwiki, EPUB, ODT, and Word docx.

And here are the ones it can write to:

plain text, Markdown, CommonMark, PHP Markdown Extra, GitHub-Flavored Markdown, MultiMarkdown, reStructuredText, XHTML, HTML5, LaTeX (including beamer slide shows), ConTeXt, RTF, OPML, DocBook, JATS, OpenDocument, ODT, Word docx, GNU Texinfo, MediaWiki markup, DokuWiki markup, ZimWiki markup, Haddock markup, EPUB (v2 or v3), FictionBook2, Textile, groff man, groff ms, Emacs Org mode, AsciiDoc, InDesign ICML, TEI Simple, Muse, PowerPoint slide shows and Slidy, Slideous, DZSlides, reveal.js, PDF

That's pretty impressive

I was faced with an html file describing a lab for all the CSCI13500 students at Hunter. I wanted to modify it for my class and that was going to be a bear. I also wanted an easy way to have it render up on GitHub. With pandoc, it was trivial. I just typed:

pandoc -f html -t org -o lab3.org lab3.html

which converted the file to org-mode. This was trivial to edit and then I uploaded it to GitHub as the lab's Readme.org file which GitHub automatically renders on the project page.

Pandoc for the win.

I've also used pandoc to move between org-mode and word files.

If you haven't checked out pandoc, you should.

Google Sheets

I make regular use of Google's office suite. I use Google forms all the time to collect data, Google docs when I have to leave Emacs for document preparation - usually when I have to collaborate with others online and I use Google Sheets as my greadebook.

I don't do a lot of data processing using Google sheets. For that I download the data and write small scripts. On the other hand it turns out that you can do some pretty nifty things by scripting right in Google sheets.

Google sheets can be scripted using Javascript and Google's APIs. For example, adding "hello" and "world" to the two bottom leftmost cells in your active spreadsheet can be done by running a function like this:

function addHello() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();

In general, it's pretty easy to grab, modify, or otherwise manipulate cells from a spreadsheet with simple javascript.

You can also send email from a Google app script. For me this was a big win. I use it for emailing grades to students and also as a poor man's mailmerge. The key call is:

GmailApp.sendEmail(email , subject,msg);

Here's a video walking through sending emails to a list of people from a spreadsheet. The code is underneath.

function sendEmail(to,subject,msg){


function getSheetByName(name){
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheets = ss.getSheets();
  for( var n in sheets){
    if (name==sheets[n].getName()){
     return sheets[n]; 
    return sheets[0];

function prepareMessage(name){
  var sheet = getSheetByName("Msg");
  var oldSheet = SpreadsheetApp.getActiveSheet()

  var dataRange = sheet.getRange(1,1,1,1)
  data = dataRange.getValues()
  var msg = data[0][0]
  msg = msg.replace("%FIRST%",name)
  return msg

function sendGrades(){
  var sheet = getSheetByName("grades")
  var rows = sheet.getLastRow()
  var cols = sheet.getLastColumn()
  var dataRange = sheet.getRange(2,1,rows-1,cols)
  var data = dataRange.getValues();
  for (i in data){
    var name = data[i][0]
    var to = data[i][1]
    var msg = prepareMessage(name)
    sendEmail(to,"Important Grade Info",msg)


Using Emacs 40 - Atomic Chrome

Thanks to everyone who voted for topics or commented with suggestions for videos. I'll try to get to them in the coming months.

Today is just a quick hit on Atomic Chrome - an Emacs package and browser extension that allows you to edit web form inputs with Emacs.


I forgot to mention that you can set a shortcut key, at least in chrome rather than clicking on the icon. This makes things much smoother.

All you have to do is:

  1. Go to chrome://extensions
  2. On the bottom of the page you'll see a button to set keyboard shortcuts
  3. Set the shortcut for Atomic Chrome


On Textbooks

I thought I'd answer Alfred Thompson's recent post on using textbooks. Like Alfred, I've never used textbooks particularly effectively. Even when I taught math I mostly used them as a resource for problems.

I also agree with Alfred in questioning the "flipped class" model or as I like to call it "homework" for reasons similar to Alfred's.

Even back in the Pascal days of APCS getting textbooks was an ordeal in NYC. First, the book had to cover both the A and AB parts of the class since I rarely had budget to buy two books for a class, then they had to be sold by the high school division of the publishing house eliminating many college texts and finally we had to get the books on the "NYSTL list" so we could buy and pay for them.

I finally found a book I liked that covered the full year by Nance and Naps. By then I knew that I wouldn't really work it into the class but I felt that it explained things, the data structures and algorithms in particular very well.

That's one thing I always look for in a text book. If I'm not tightly integrating the text then I want the text to be a worthwhile resource for the student. If a kid doesn't get it in class I want the text book to be a second chance.

When we moved to C++ we moved to Nance and Naps for the language and Nance and Lambert for the Data Structures. Somehow I got the school to fund both books.

Everything changed when the AP class went to Java. I never found a Java based book that covered the data structures in a way I liked but finding a text was a problem even beyond that hurdle.

All of the Java based texts tightly integrated with some project or library provide by the author. It was just like the AP case study. If the case study worked well into your course and the way you taught it was great, otherwise it was a bear to deal with. I settled on Lewis and Loftus which integrated their own graphics library but always as an add on to each chapter rather than tightly integrated.

For my homebrew classes, I've never found a single textbook. The nice thing today is that there are so many resources already available. Tutorials, videos, online practice sites like codingbat and more. There are also a number of authors who make their books available online for free. I use one - Automate the Boring Stuff with Python in one of my classes but I purchased a copy for myself and encourage my students to do so as well if/when they're able to based on economic situation. Usually I can cobble together a good set of resources for the students that are both free and probably superior to any single text book out there.

All of this said, it's important that students have resources independent of the teacher. If you can get a good textbook, that can be it but fortunately, in this day and age we have many great alternatives.

Is Teaching CS Hard?

Last week, Mark Guzdial asked What does it mean for Computer Science to be harder to learn than other STEM subjects? as a follow up to his ACM Blog post this month and the ensuing discussion.

You should read both posts but here's how Mark started off the follow up:

I made an argument in my Blog@CACM Post for this month that “Learning Computer Science is Different than Learning Other STEM Disciplines,” and on Twitter, I explicitly added “It’s harder.”

When you talk about how hard or easy it is to teach a subject you can do so at many levels. college, high school, middle etc.. Since most of my career has been as a High School guy, let's focus there.

I do in fact believe that it is hard to teach CS, at least to do it well but is it harder to teach then other STEM subjects?

Let's see how we're doing in those other subjects. I took a look at the New York State Regents Exam results from 2015/2016. I'm certainly not a believer or supporter of standardized tests but they're a convenient measure for the sake of this post.

Only 58% of test takers scored 65 or higher on Integrated Algebra and only 41% scored 3 (proficient) or higher on the Common Core version with far more students taking the Common Core exam.

Higher performing schools frequently offer Algebra in 8th grade but in the lower performing districts, students frequently take it over the course of two years.

The Geometry regents boasts a passing rate of about 40%. Trig does a little better.

The science regents exams look a little better but overall, these are not terrific results, particularly on the classes that are required for graduation.

It seems that those other STEM fields aren't so easy to teach after all.

On the other hand we have CS. If you listen to all the press releases and media attention on APCS-P from this past year it would seem that CS is easy to teach and learn. We have all these high school students mastering a "college level" course and we can prepare teachers to be master CS instructions with just a bit of in-service professional development.

The truth is, of course that CS isn't easy to teach. When you're a summer or after school program or even an elective it's easy to create a fun experience using shiny tools to self selecting students but when you have to take everyone and prepare many of them to succeed in more advanced classes we have a real challenge. We really should be looking at retention in more advanced CS classes rather than just passing the intro ones. Most students won't go beyond the intro class in any given subject but the ones that do must be well prepared. Unfortunately, I fear that the people who will get the blame when kids drop CS later on will be the teachers of the more advanced classes regardless of who, if anyone, is at fault.

Teaching CS is hard. It's brand new and very open ended. When programming a solution to a problem kids start with a blank slate. They don't have the library of patterns, vocabulary or idioms needed to build solitions. There are many ways a teacher can scaffold the learning. Code tracing, analogies, Parsons problems and more but the truth is teachers strong in both content and pedagogical knowledge are still in rather short supply and as Mark wrote on his blog the body of knowledge on teaching CS is just not that mature.

On the other hand, Algebra students usually had a first look at some of the topics prior to the class and much of the class can be "learned" through memorizing relatively short procedures and patterns. This might not lead to a depth of understanding but it does get you past standardized tests. On the science side, the Living Environment exam is really just a reading test. On the other hand, we're supposed to start teaching proof to students in Geometry and that's really hard to do.

So, teaching in general is hard and teaching CS is no exception. At least it is if you're doing it right.

Enter your email address:

Delivered by FeedBurner

Google Analytics Alternative