Skip to content

Presentation on "Type-Directed TDD in Rust" for Pittsburgh Code and Supply

License

Notifications You must be signed in to change notification settings

FranklinChen/type-directed-tdd-rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Type-directed TDD in Rust

Gitter

Build Status

Info

This repository contains material for my presentation "Type-Directed TDD in Rust" given at CMU on Monday, July 21, 2014, for the Pittsburgh Code and Supply meetup.

I ported this presentation from an earlier presentation I gave at Pittsburgh TechFest 2014 that originally used the language Scala for exposition (with some Swift as an addendum). I welcomed the opportunity to create a Rust version of the presentation in order to show that the main ideas and work flow are not language-dependent, but apply to any sufficiently modern statically typed programming language with a good set of testing libraries.

Property-based testing

In particular, the type-directed TDD work flow leans heavily on property-based testing, a way of concisely specifying properties that result in automatically generated tests. The Rust code uses the QuickCheck property-based testing framework.

Code, article, and slides

Most recent code

I've made the master branch reflect the cleanest working version I have on hand of any code, independent of the presentation materials, which I am no longer modifying. So far, I have added:

  • Principled Result-based validation

As actually presented on 2014-07-21

The branch meetup will always contain the version of the materials as of the actual presentation (with only minor typos fixed).

Documents:

Important improvements after the talk!

Thanks to Alex Crichton, I created a new branch using-str that replaces my clumsy overuse of String with the type &'a str instead. The new code is much cleaner and does fewer memory allocations as well, and makes clear where new strings are allocated with to_string(). You can see the diffs in this commit.

Thanks to feedback on the Reddit discussion, I learned of another optimization: using String append(), which cleverly reuses an existing buffer and saves on memory allocations and gives linear concatenation.

I've made the without-validation branch reflect the cleanest working version I have on hand of code corresponding to the presentation materials. In particular, the code does not contain Result-based validation, which was outside the scope of the presentation.

Documents:

Caveats

Rust is still not at version 1.0 yet, and many things I wanted to do were not yet properly supported as of the date of the presentation. The type system is still being worked out. Best practices are still being worked out for how to make decisions about memory placement for all data.

The lack of the kind of closure support I wanted meant that I did not implement a compiler but instead an interpreter. I'm leaving the transformation into a compiler for later when closures are completely revamped in Rust. It does bring up questions of memory ownership and sharing.

I will update the code as various language constructs and libraries become available, and as I understand Rust better. Rust feels very much like programming in C, ironically, except that memory layout and management is exposed in the type system.

System requirements

You need to install Rust with Cargo:

$ curl https://static.rust-lang.org/rustup.sh | sudo bash

About

Presentation on "Type-Directed TDD in Rust" for Pittsburgh Code and Supply

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published