Grace is growing!

You wouldn’t know it by reading this Blog, but this has been an active summer in Gracelang. In fact, we’ve been so busy coding and editing the specification — and having fun with Grace — that we haven’t posed anything here.

Amongst other things, I’ve been working on a usable, if simple, version of GUnit — the ubiquitous unit testing framework — for Grace. It basically does what xUnit does in any other language: it let’s you write a bunch of test methods that contain assertions, and then runs them all, notifying you only of errors and failures. Grace’s blocks and exception handling find their niche here. For example, here is a test for lists:


import "GUnit" as GU
import "collections" as coll
def aList = coll.aList

class aListTest.forMethod(m) {
    inherits GU.aTestCase.forMethod(m)

    def oneToFive = aList.with(1, 2, 3, 4, 5)
    def evens = aList.with(2, 4, 6, 8)
    def empty = aList.empty
    method testFirst {
        assert{empty.first} shouldRaise (coll.boundsError)
        assert(evens.first) shouldBe (2)
        assert(oneToFive.first) shouldBe (1)
    }
}

def listTests = GU.aTestSuite.fromTestMethodsInClass(aListTest)
listTests.runAndPrintResults

The boilerplate is pretty standard for any xUnit. The only thing that needs explanation is the inherits clause: as in most implementations of xUnit, tests must be methods of a class that inherits from a framework class, which in Grace is called aTestCase.

Anyway, the nice thing is the first assertion:

assert{empty.first} shouldRaise (coll.boundsError)

Notice that the first argument is a block: it is evaluated as part of the action of the assert method, which enables the assert method to trap any exception that is raised.
So we are able to test that asking for the first element of an empty list does indeed raise the right exception — and then go on to run more tests.

The above code, when run, outputs:

1 run, 0 failed, 0 errors

and nothing else: passing tests are quiet.

If you would like to see all of the code, just drop us an email, and we will give you access to our subversion repository.

At SIGCSE

Andrew, James, and I are at SIGCSE through Saturday, March 9. We are giving a talk on Grace on Thursday at 1:45 p.m. and would be pleased to talk to anyone interested in Grace afterward.

Kim Bruce

Laissez-parlent l’Eiffel!

The Eiffel language has many features that support software engineering. One of these is a loop statement that allows programmers to specify loop variants and invariants. We hope Grace may also be used to teach about invariants, so it would be useful to write Eiffel-style loops in Grace:

The key here is the loop/invariant/until/variant control structure — which in Grace is just a method that takes Blocks as arguments. Here’s a simple implementation of this method:

Of course, in a practical Grace system, this method, like other control structures, would be defined in the system or dialect library. The key features that make this possible are not themselves complex: multi-part method names support defining every control structure (syntatically and semantically) as a method request, and then using blocks to pass code into those methods.

Grace @ SIGCSE 2013

We’ll be presenting a paper “Seeking Grace: An new object-oriented language for novices” at SIGCSE 2013 in Denver on March 7th.

We are designing a new object-oriented language, Grace, that is designed for novices. It is intended to integrate proven new ideas in programming languages into a conceptually simple language that allows the instructor and students to focus on the essential complexities of programming, while supporting a variety of approaches to teaching.

Hopefully, this opportunity will help us expose Grace to more of the CS education community.