Resources for year 6 teachers on coding and programming

I have been introducing some year 6 (UK) teachers to coding by showing them how to lay out a simple web page by writing HTML. I promised I would find some links to resources for them, so here it is:

HTML and JavaScript

My examples of how to write HTML are at

There are several web sites that allow you to experiment with writing HTML and JavaScript and seeing the results immediately:

I also made some videos about how to make a snowflake animation in both JavaScript and Scratch here: Snowflake Christmas card.

Raspberry Pi

The Raspberry Pi is a cheap education-focussed computer that looks like a piece of circuit board the size of a credit card.

Their educational resources are at:

There are lots of great videos about how to do different things with the Raspberry Pi, including the ones by The Raspberry Pi Guy.

There are also my (boring, but comprehensive) videos teaching you to write a simple game in Python, from a starting point of no programming experience at all: My First Raspberry Pi Game.

Graphical programming

There are several tools and sites for learning programming by dragging and dropping blocks instead of typing code:

  • Scratch – creative, unguided, a bit old-fashined looking but tried-and-trusted
  • – fun, attractive guided tasks featuring Disney characters, Minecraft etc.
  • blockly – guided tasks with good progression
  • – I’ve not used this, but it looks like it could have potential

Other languages

Setting up a sane Maven project

Today I have spent hours trying to get wrangle Maven into letting me set up a sane Java project. The hardest parts were enforcing warnings-as-errors, and getting Maven to shut up a bit.

Some code that warns

My first problem was writing some Java code that causes the compiler to emit warnings. For some reason I can’t understand, my Java 1.8 compiler was not emitting warnings (even with -Xlint:all) for unused variables, use of deprecated methods, or unknown @SuppressWarnings types (suggestions from SO 1752607).

Instead, I had to use an unnecessary cast:

$ cat src/tast/java/
public class ExampleTest {
    public void warn() {
        String fixmePlease = (String)"Hello";

Now, finally, I got a warning:

$ javac -Xlint:all src/test/
src/test/ warning: [cast] redundant cast to String
        String s = (String) "Hello!";
1 warning

Maven compiler settings for warnings-as-errors

I tried a vast set of combinations of properties like maven.compiler.failOnWarning and maven.compiler.fork (as specified in the maven compiler plugin docs) before giving up on properties. Making a property called maven.compiler.failOnWarning seems to have no effect whatsoever, ever.

So I decided I must try the (very verbose) plugin tag containing a configuration tag, as also specified in the maven compiler plugin docs. After a lot of messing about with flags that seemed incompatible, and Maven silently ignoring things it didn’t understand, I came to a working config.

On the way, I discovered that setting the “fork” property to true is a non-starter, because Maven simply drops the compiler output in that case, meaning you can’t see what is going wrong when it does.

Finally, I had a pom file like this:

cat pom.xml
<?xml version="1.0"?>
<project xmlns="" xmlns:xsi="" xsi:schemaLocation="">

Which manages successfully to tell the compiler to show all warnings, and to fail when it sees one. (Thanks to SO 9192613, among others.)

I dare not change anything, for fear that it will stop working again without any explanation.

Quieting Maven

If you tell Maven to be quiet with -q or -e it will merrily fail the build because of a warning, but not tell you what the warning was.

Maven does not appear to have a command line option to set the log level to display warnings and errors only, but you can force it to do so by setting the environment variable MAVEN_OPTS like this:

MAVEN_OPTS=MAVEN_OPTS=-Dorg.slf4j.simpleLogger.defaultLogLevel=warn mvn clean test-compile

(Thanks to SO 4782089.)

And, with some guesswork (partly based on Configuring Maven) I found that if I put something similar in .mvn/jvm.config I didn’t have to type it every time:

$ cat .mvn/jvm.config 

Failing on warnings, and seeing them!

I don’t know whether to feel triumphant or defeated, but, it works!

$ mvn clean test-compile 
[WARNING] src/test/java/[3,20] redundant cast to java.lang.String
[ERROR] src/test/java/ warnings found and -Werror specified
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.6.0:testCompile (default-testCompile) on project unmatcheddrrepair: Compilation failure
[ERROR] src/test/java/ warnings found and -Werror specified
[ERROR] -> [Help 1]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1]

I wish I could suppress double-reporting of the error, and the extra rubbish at the end (and the super-long absolute paths of each file that push the actual errors off the side of the screen), but at this point, I must try and do what I was trying to do in the first place.

Guess how much I am liking Maven at this point.

Writing a unit test in Elm

Series: Snake in Elm, Elm makes me happy, Elm Basics, Elm Unit Test

I’ve been having fun with Elm programming recently. Elm is a replacement for JavaScript that is pure functional and highly practical.

Here’s how to go from nothing installed at all to writing a unit test that passes, in just over 10 minutes.

The source code is here:

How to write a programming language – Part 3, The Evaluator

Series: Lexer, Parser, Evaluator.

Finally, we get onto the actual magic of the little language I wrote (Cell) – the evaluator, which takes in syntax trees and finds their real value, in the context of the “environment”: the symbols that are defined around it.

Slides: How to write a programming language – Part 3, The Evaluator

If you want to, you can Support me on Patreon.

Basic Haskell project setup (unit tests, code, formatting)

To start a programming project, we need to be able to build, format code, and run unit tests.

Here’s what I have found makes a sensible starting point for a Haskell project. Full code: hunit-example.

To build and run tests, just do:

make setup
make test

I tend to use a Makefile for all the commands I need to remember. The most important part here is the “setup” target which installs the cabal-install package (Cabal is a package manager for Haskell), then uses Cabal to install hindent, and finally installs all the dependencies of our actual project (which we specify in a .cabal file, shown further down). The format target uses hindent-all, which is shown below.

Update: added “happy” as a prerequisite – needed by hindent.


all: test

test: format
	cabal test

build: format
	cabal build


	cabal clean

	sudo apt-get install cabal-install happy
        cabal update
	cabal install hindent
	cabal install --run-tests

Our production code is very simple – just two functions.


module HUnitExample where

double x = x * 2

half x = x / 2

Our tests import our production code, and use tasty (which includes HUnit) to check it works.


import HUnitExample (double, half)
import Test.Tasty (defaultMain, testGroup)
import Test.Tasty.HUnit (assertEqual, testCase)

main = defaultMain unitTests

unitTests =
    "Unit tests"
    [doublingMakesNumbersBigger, halvingMakesNumbersSmaller]

doublingMakesNumbersBigger =
  testCase "Double of 4 is 8" $ assertEqual [] 8 (double 4)

halvingMakesNumbersSmaller =
  testCase "Half of 9 is 4" $ assertEqual [] 4 (half 9)

Each test is a testCase that uses assertions like assertEqual to verify the code. HUnit also provides lots of cryptic operators for obfuscating your tests.

Many projects will want to add property-based testing with QuickCheck or SmartCheck or similar.

The magic that makes all this work is the Cabal file, which can have any name that ends in “.cabal”.


Name:               hunit-example
Version:            1.0.0
cabal-version:      >= 1.8
build-type:         Simple

  Exposed-Modules:  HUnitExample
  Build-Depends:    base >= 3 && < 5

Test-Suite test-hunit-example
  type:             exitcode-stdio-1.0
  hs-source-dirs:   tests
  Main-is:          Tests.hs
  Build-Depends:    base >= 3 && < 5
                  , tasty
                  , tasty-hunit
                  , hunit-example

You will normally want lots more properties than this, but this is what I think is a minimal example. It defines the project properties, the production library module we are building, and a test suite that tasty uses to know what to run. Note that the test suite must depend on the production code module so you are allowed to import it.

To do code formatting, I made this bash script:



# Format all .hs files in the current directory tree with hindent


function all_hs_files()
    find ./ -name dist -prune -o -name "*.hs" -print

for FILE in $(all_hs_files); do
    cat ${FILE} | ${HINDENT} > ${NEWFILE}

    if diff -q ${FILE} ${NEWFILE} >/dev/null; then
        rm ${NEWFILE}
        echo "hindent updated ${FILE}"
        mv ${NEWFILE} ${FILE}
    }; fi
}; done

I would be grateful if someone pointed out I didn't need to do that because someone has done it for me. Note: I chose not to use hfmt because it hard-codes a long line length, whereas hindent behaves how I like with no configuration.

Last but not least, ignore the directory created by Cabal.



So, when we run we see this:

$ make test
Running 1 test suites...
Test suite test-hunit-example: RUNNING...
Unit tests
  Double of 4 is 8: OK
  Half of 9 is 4:   FAIL
    expected: 4.0
     but got: 4.5

1 out of 2 tests failed (0.00s)

Looks like we've got a bug to fix...