Posts in the ‘Code’ category

Open source libraries now on GitHub

Sunday, July 18th, 2010

We are excited to announce that we’ve moved all of our open source code to Github!

(more…)

Selenium client for Racket

Thursday, June 10th, 2010

Acceptance testing is a must for any developer of complex web applications. Selenium is a suite of tools to help automate acceptance by recording user actions, turning them into code, and playing them back in a remote controlled web browser.

Now, thanks to a lazy Saturday afternoon and a rather nice bottle of ginger beer, the joys of Selenium are available to the Racket community by way of our new Selenium PLT library. Check it out on our Github page and let us know how you get on!

(more…)

Formalising Bonds with the Informal

Tuesday, April 20th, 2010

There is an interesting move underway by the US Securities and Exchange Commission (SEC) to more precisely define the meaning of certain asset backed securities (like the now infamous mortgage-backed securities that were central to the recent crash). The NY times has covered the story from a high level, but what of particular interest to me is the proposal to specify the meaning of the bonds in Python. This is a step is the right direction but Python is not the answer.

The core problem here is to give a clear and unambiguous meaning to a bond. This requires the language in which it is written is precisely defined. Python is not precisely defined. There is only a prose definition of the language, which is inadequate in the same way that the prose definitions of bonds are inadequate, and of course there are differences between various versions and implementation of Python. Since Python is not precisely defined the only meaning one can give to a program in Python is whatever the particular implementation one uses does with that program.

In contrast there are languages that are formally defined, such Standard ML and Scheme. These would make a sound basis for the formal definition of bonds. In turns out that functional languages also make a good (meaning expressive and convenient) basis for the formal definition of bonds. There is a great paper on expressing contracts in Haskell and at least one company has implemented this idea in a commercial system (in O’Caml, I believe). So my advice to the SEC: use an appropriate subset of Scheme or Standard ML, or hire someone to create a formally defined DSL, but don’t use a language without a formal definition if precision is your goal.

Libraries update

Friday, June 5th, 2009

We produce a lot of open source code at Untyped, all of which is available from our Subversion repository. You can check out a read-only copy of our repository at any time. If you want to work on a branch without getting commit access to our repository, you might find git-svn or Mercurial’s Subversion integration useful. If you’d like to collaborate on development (and we’re open to all kinds of collaboration, including student/academic work) it is probably simplest to drop us an email (noel or dave at untyped dot com) to arrange things. There is a lot of stuff in there, so here’s a quick summary of the most interesting things we are currently working on.

Snooze is our flagship database abstraction layer, comparable to Hibernate or ActiveRecord. Snooze 2, which is out on PLaneT now, contains a robust query language and support for whole-model validation. Development on the version 3 of the library is underway, with emphasis on caching and inter-struct relationships.

Mirrors is our library for programmatic generation of XHTML and Javascript. It allows you to build blocks of code using a syntax similar to Scheme’s quoted lists. Rendering is done at compile-time as far as possible, so you get the convenience and compositional properties of quoted lists with the speed of PHP-style mechanisms. We intend to add support for CSS in a future release.

Delirium is our web UI testing library, similar to Selenium but with the expressive power of SchemeUnit. Versions 2 and 3, both on PLaneT, have equivalent feature sets: version 2 supports PLT 4.1.3 and earlier, while version 3 supports PLT 4.1.3 and upwards.

Smoke is our UI creation library (the partner library to Mirrors, pun definitely intended). While we have deployed this in a number of production applications, the interface is subject to constant tweaking so we haven’t published it to PLaneT. You can still get hold of the code from SVN and play with it, though!

Dispatch, our controller-to-URL mapping library, has been partly subsumed as its core features have been rolled into PLT’s web-server/dispatch library. There is still room for both systems, though, as the PLT library is built with simplicity in mind, whereas Dispatch was built to simplify web development. We plan on “rebooting” the Dispatch franchise with a version that wraps web-server/dispatch with some new features.

SchemeUnit, Noel’s excellent unit testing package, is as strong as ever. A version recently got rolled into PLT core, but you can still get the PLaneT package for the latest updates from Noel. Note that SchemeUnit’s code is hosted at Schematics.

Other points of interest:

  • Unlib is still going strong, with new shorthand require/provide syntaxes that can fetch stuff directly from SVN, a more humane version of keyword-apply, and some utilities to support dotted identifiers in our other libraries.
  • Excel, as its name suggests, is a library for creating Excel files in functional drawing style. It supports all the basics: formulae, inter-cell references, number formats, fonts, borders and fills, conditional formatting, and cell validation.
  • Autoplanet is a tool for deploying applications without having to worry about changing dependencies. It creates an application-local PLaneT cache and can be configured to download and install packages from PLaneT, SVN, or the local filesystem.

Untyped open source repository: open for business

Tuesday, January 27th, 2009

It’s been a long time coming, but we are proud to announce the launch of the Untyped open source repository!

This public Subversion repository houses the source code for our open source projects, including popular PLT Scheme packages such as DispatchSnooze and Mirrors as well as a few things you won’t find on PLaneT.  It’s all free and open source, but please make sure you agree to our terms of use before you get stuck in.

You can check out any or all the projects using command line SVN. For example:

  svn co http://svn.untyped.com/mirrors/trunk mirrors-trunk
It’s no-frills at the moment – SVN and web browser support only – but we plan to prettify things in the future. See the README file for more information.

Tests as todos

Wednesday, November 5th, 2008

Like most people I have a few projects on the go at once. To efficiently switch between them I must be able to quickly pick up where I left off. In my programming projects I’ve been using failing tests as reminders to myself. This fits in nicely with my programming workflow, and enables me to make progress before I’ve recalled all the details of the project I’m working on. Here’s how it works:

In my programming workflow I cycle between writing tests, writing code, and running tests (this is just test driven development). When I’m about to stop working on a project I write some failing tests, which act as a specification for what I should do next. At this point in time I’ve been working on the project for a while so I have recalled its structure and I’m in a good position to make this decision.

When I pick up a project after a break I enter straight into my normal workflow and run my tests. I inspect the failing tests and start implementing the functionality they specify. At this point in time I don’t even have to remember why I’m implementing this; the tests provide enough detail that I can just start coding. As I do so I invariably recall more details of the project. By the time I’ve finished the feature I’m ready to go at full speed.

This technique allows me to “hide” the time it takes to recall the project details; I still get useful work done in this period. It’s quite a simple idea and no doubt some of you are already using it, but if you haven’t tried it, give it a shot.

Commercial use articles in the Journal of Functional Programming

Saturday, September 27th, 2008

Further evidence of the increasing commercial relevance of functional programming (and just as important, the desire of the academic community for said relevance) is the announcement that the Journal of Functional Programming is now accepting Commercial Use articles.

The software engineering (SE) community and the programming language theory (PLT) community have traditionally been quite separate. This has led to much duplication of work. For example, it is well known that patterns are language features, indicating that the two communities have essentially been solving the same problems from different angles. The SE field assumes the language is fixed, and so develops abstractions (i.e. patterns) that exist above the level of code. The PLT researcher changes the language to directly express the abstraction. The SE approach is pragmatic but inelegant. The promise of the PLT approach has been retaining elegance (with associated reduction in development and maintenance cost), but the cost of adopting a new language is often seen as too high. (Incidentally, solving this problem is why you want a language with macros. I.e. Scheme.)

That the JFP is looking to publish essentially SE articles is definitely a good thing. It will, however, be interesting to see how the community adapts to members with quite different aims and values to the typical PLT researcher. For example, the PLT researcher is very focused on formality, and in particular giving precise semantics to language constructs. This leads to a style that deals with concepts in a very abstract mathematical manner. While powerful this is certainly not the best presentation for a working programmer to learn from. Consider, for example, Comprehending monads, which aims to be an easy introduction to monads. Given that this paper was published in 1992, we can see its ineffectiveness as a tutorial by considering the zillions of monad tutorials that have been written since. The problem is the abstract style of presentation. While presenting in an abstract style allows you to generalise to many different situations, people work best going from the specific to the general. Better tutorials start with a concrete example, and abstract from there. The question for the PLT community is how they will accommodate the desire for less formality and abstraction from the working programmer when one of the key differentiating factors between SE and PLT is the use of formalisms. If the right balance can be found this will be a great thing for both researchers and practitioners.

SchemeUnit 3: A New Approach to Testing

Thursday, July 31st, 2008

SchemeUnit 3 has been released. Although the interface remains compatible with version 2 the underlying philosophy of SchemeUnit has changed in a significant way. The following is extract from the SchemeUnit manual, describing the new approach.

SchemeUnit is designed to allow tests to evolve in step with
the evolution of the program under testing. SchemeUnit
scales from the unstructed checks suitable for simple
programs to the complex structure necessary for large
projects.

Simple programs, such as those in How to Design Programs,
are generally purely functional with no setup required to
obtain a context in which the function may operate.
Therefore the tests for these programs are extremely simple:
the test expressions are single checks, usually for
equality, and there are no dependencies between expressions.
For example, a HtDP student may be writing simple list
functions such as length, and the properties they are
checking are of the form:

(equal? (length null) 0)
(equal? (length '(a)) 1)
(equal? (length '(a b)) 2)

SchemeUnit directly supports this style of testing. A check
on its own is a valid test. So the above examples may be
written in SchemeUnit as:

(check-equal? (length null) 0)
(check-equal? (length '(a)) 1)
(check-equal? (length '(a b)) 2)

Simple programs now get all the benefits of SchemeUnit with
very little overhead.

There are limitations to this style of testing that more
complex programs will expose. For example, there might be
dependencies between expressions, caused by state, so that
it does not make sense to evaluate some expressions if
earlier ones have failed. This type of program needs a way
to group expressions so that a failure in one group causes
evaluation of that group to stop and immediately proceed to
the next group. In SchemeUnit all that is required is to
wrap a test-begin expression around a group of
expressions:

(test-begin
(setup-some-state!)
(check-equal? (foo! 1) 'expected-value-1)
(check-equal? (foo! 2) 'expected-value-2))

Now if any expression within the test-begin

expression fails no further expressions in that group will
be evaluated.

Notice that all the previous tests written in the simple
style are still valid. Introducing grouping is a local
change only. This is a key feature of SchemeUnit’s support
for the evolution of the program.

The programmer may wish to name a group of tests. This is
done using the test-case expression, a simple
variant on test-begin:

(test-case
"The name"
... test expressions ...)

Most programs will stick with this style. However,
programmers writing very complex programs may wish to
maintain separate groups of tests for different parts of the
program, or run their tests in different ways to the normal
SchemeUnit manner (for example, test results may be logged
for the purpose of improving software quality, or they may
be displayed on a website to indicate service quality). For
these programmers it is necessary to delay the execution of
tests so they can processed in the programmer’s chosen
manner. To do this, the programmer simply wraps a test-suite
around their tests:

(test-suite
"Suite name"
(check ...)
(test-begin ...)
(test-case ...))

The tests now change from expressions that are immediately
evaluated to objects that may be programmatically
manipulated. Note again this is a local change. Tests
outside the suite continue to evaluate as before.

2.1 Historical Context

Most testing frameworks, including earlier versions of
SchemeUnit, support only the final form of testing. This is
likely due to the influence of the SUnit testing framework,
which is the ancestor of SchemeUnit and the most widely used
frameworks in Java, .Net, Python, and Ruby, and many other
languages. That this is insufficient for all users is
apparent if one considers the proliferation of “simpler”
testing frameworks in Scheme such as SRFI-78, or the the
practice of beginner programmers. Unfortunately these
simpler methods are inadequate for testing larger
systems. To the best of my knowledge SchemeUnit is the only
testing framework that makes a conscious effort to support
the testing style of all levels of programmer.

PLT Scheme 4 is out

Friday, June 13th, 2008

PLT Scheme 4.0 is out. We’ve been using the pre-releases for months so this release isn’t particularly significant to us. However, for Universities and other institutions having an official release is important. I do think that too many individual developers stick with out-dated versions of PLT Scheme. The number of questions about 372, which is at least a year old, amazes me. Pre-releases are so much better! Go upgrade!

Science and Self-Directed Learners

Sunday, April 6th, 2008

Over on LtU I was asked how to help beginning programmers become self-directed learners. I have taught a number of students, but not in a context where I’ve been able to really make a difference in their programming practice, so I don’t have an answer to the whole question (though my instinct is that the apprenticeship method is the right way to go). However I try to teach one process that I think is an essential step towards becoming a self-directed learner. That process is the big idea called science, and I’m not talking about lab coats and chunky glasses

When working with students I always get asked what the result of evaluating some piece of code will be. What I tell the students is to ask the computer via a test case or the REPL. Testing ideas by experimentation is science in its simplest and most immediate form, and a crucial step in developing the student’s ability to solve their own problems.

Application of science to programming is not restricted to students; test-driven development is science. So what is science then? I simplify, but basically three things: a theory to test, an experiment to test it, and a standard of proof (note we can never truly prove a theory, just simply not be able to disprove it). This is exactly when a unit test is. For example, a Scheme programmer might pose the theory “the string->number function will convert strings padded with whitespace characters to numbers”, formulate the experiment (equal? (string->number “ 200”) 200), and have as the standard of proof the boolean output of this single experiment.

When most people think of the scientific method they think of the lengthy and expensive double-blind trials used in, for example, medical trials. A really important point is to realise that when you do science, you choose the standard of proof. For example, as most computer programs are deterministic a few tests can be sufficient to show a property holds. When dealing with a concurrent program, or some other non-deterministic system, you may need to be more rigourous.

So there we have it. All programmers are scientists to some extent, though they might not know it. We can extend the use of experimentation to answer other questions, such as determining if productivity is affected by changes to software development process. Doing this in a lightweight way is the intention of the Simple Improvement package, though I haven’t had the time to get that library to a really useful state. Perhaps in a later post I’ll go through the ideas behind it. In the mean time, get experimenting (lab coats optional).