Successfully reported this slideshow.
Your SlideShare is downloading. ×

Age is not an int

Age is not an int

Download to read offline

Slides for a talk given as part of the Imperial College London "Applications of Computing in Industry" lectures. 14th Jan 2015

Slides for a talk given as part of the Imperial College London "Applications of Computing in Industry" lectures. 14th Jan 2015

More Related Content

Related Books

Free with a 30 day trial from Scribd

See all

Age is not an int

  1. 1. Name Chris Marshall @oxbow_lakes GSA Capital Partners LLP Jan 2015 Private & Confidential. Not for distribution. GSA Capital Partners LLP is authorised and regulated by the Financial Services Authority. Registered in England & Wales. Stratton House, 5 Stratton Street, London, W1J 8LA. Number OC309261
  2. 2. Age is not an Int
  3. 3. Mathematics Degree Working in financial software since 1999 • Smalltalk for ~6 months • Java thereafter • Scala since Dec 2008 JP Morgan for 6 years • ~200,000 employees GSA Capital for 8+ years • Quant hedge fund • ~130 employees Background who am i Private & Confidential. Not for distribution. GSA Capital Partners LLP is authorised and regulated by the Financial Services Authority. Registered in England & Wales. Stratton House, 5 Stratton Street, London, W1J 8LA. Number OC309261 3
  4. 4. Low-latency links & feeds • Up to 2,000,000 trades /day • 108 market events / day Historic / Current Market Data • Listing changes (e.g. SUNW.O becomes JAVA.O becomes ORCL.O) • News Events Backtesting / Execution Framework Everything Else • This is where CORE come in • What are our positions? What is our P&L? What is our VaR? • Are our trades reconciled? • Reporting (brokers, regulators, administrators) GSA What do we do? Roughly half the company are technologists Private & Confidential. Not for distribution. GSA Capital Partners LLP is authorised and regulated by the Financial Services Authority. Registered in England & Wales. Stratton House, 5 Stratton Street, London, W1J 8LA. Number OC309261 4
  5. 5.  GSA are not a software company 5 This talk Private & Confidential. Not for distribution. GSA Capital Partners LLP is authorised and regulated by the Financial Services Authority. Registered in England & Wales. Stratton House, 5 Stratton Street, London, W1J 8LA. Number OC309261
  6. 6. <dibblego> this question generalises to "use types" <dibblego> how do I know my Int is a valid age? <dibblego> well how indeed? how did you even come to that conclusion? <dibblego> well, because age returns Int <dibblego> stop doing that! <dibblego> Age returns a value between 0 and MAX_AGE <dibblego> oh, then you want a type for that <dibblego> but what about my Int! <dibblego> there was never an Int <dibblego> but I want to use it as an Int! <dibblego> so do that <dibblego> but it is clumsy and annoying to convert all the time! <dibblego> so use libraries <dibblego> which library? <dibblego> well, in this case, lenses 6 #scalaz IRC channel Private & Confidential. Not for distribution. GSA Capital Partners LLP is authorised and regulated by the Financial Services Authority. Registered in England & Wales. Stratton House, 5 Stratton Street, London, W1J 8LA. Number OC309261
  7. 7.  Want to talk about the use of types in the programs we write  For those of us who work in statically-typed languages  Types  which we write ourselves  provided by the language itself  That the structure of our entire program can be constructed as a type 7 This talk Private & Confidential. Not for distribution. GSA Capital Partners LLP is authorised and regulated by the Financial Services Authority. Registered in England & Wales. Stratton House, 5 Stratton Street, London, W1J 8LA. Number OC309261
  8. 8. public interface Comparable<T> { public int compareTo(T o); }  Representing a 3-valued type with a 232 valued one 8 In java.lang: not a good start Private & Confidential. Not for distribution. GSA Capital Partners LLP is authorised and regulated by the Financial Services Authority. Registered in England & Wales. Stratton House, 5 Stratton Street, London, W1J 8LA. Number OC309261
  9. 9. /** * Returns the percentage tracking error between * this portfolio and the reference portfolio */ public double getTrackingError(String ref) /** * Returns the price that this trade was executed at */ public BigDecimal getPrice() 9 So you go away and write this... Private & Confidential. Not for distribution. GSA Capital Partners LLP is authorised and regulated by the Financial Services Authority. Registered in England & Wales. Stratton House, 5 Stratton Street, London, W1J 8LA. Number OC309261
  10. 10.  Originally devised as a way of making code which was wrong look wrong  http://www.joelonsoftware.com/articles/Wrong.html  That is: “if you see xl = cb, well, blow the Bad Code Whistle, that is obviously wrong code, because even though xl and cb are both integers, it’s completely crazy to set a horizontal offset in pixels to a count of bytes.”  Why not make code which was wrong NOT EVEN COMPILE?  WHY NOT USE TYPES? 10 Hungarian notation Private & Confidential. Not for distribution. GSA Capital Partners LLP is authorised and regulated by the Financial Services Authority. Registered in England & Wales. Stratton House, 5 Stratton Street, London, W1J 8LA. Number OC309261
  11. 11. class LimitOrder(stock: String, price: Double, quantity: Int) val cf = Double.compare(o1.price, o2.quantity) //OH NOES! class LimitOrder(stock: Stock, price: Price, quantity: Quantity) 11 Stringly typed Private & Confidential. Not for distribution. GSA Capital Partners LLP is authorised and regulated by the Financial Services Authority. Registered in England & Wales. Stratton House, 5 Stratton Street, London, W1J 8LA. Number OC309261
  12. 12. case class Percentage(units: BigDecimal) /** * Returns the percentage tracking error between this * portfolio and the reference portfolio */ public Percentage getTrackingError(Portfolio ref) 12 So: write some types Private & Confidential. Not for distribution. GSA Capital Partners LLP is authorised and regulated by the Financial Services Authority. Registered in England & Wales. Stratton House, 5 Stratton Street, London, W1J 8LA. Number OC309261
  13. 13. case class Money(currency: Currency, amount: BigDecimal) /** * Returns the price that this trade was executed at */ public Money getPrice() 13 ...and some more Private & Confidential. Not for distribution. GSA Capital Partners LLP is authorised and regulated by the Financial Services Authority. Registered in England & Wales. Stratton House, 5 Stratton Street, London, W1J 8LA. Number OC309261
  14. 14.  Java has failed us  This is not meant to be a rant about Java  The same is true of plenty of languages out there  4 different type systems  Primitive types  Reference types  Exception types  Annotation types  Creating classes is expensive and painful  Creating TYPES is expensive and painful 14 Java Private & Confidential. Not for distribution. GSA Capital Partners LLP is authorised and regulated by the Financial Services Authority. Registered in England & Wales. Stratton House, 5 Stratton Street, London, W1J 8LA. Number OC309261
  15. 15. public final class Money { private final Currency currency; private final BigDecimal amount; private Money(Currency currency, BigDecimal monetaryAmount) { currency_ = currency; amount = monetaryAmount; } public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } final Money money = (Money) o; if (!currency.equals(money.currency)) { return false; } if (!amount.equals(money.amount)) { return false; } return true; } public int hashCode() { int result; result = currency.hashCode(); result = 29 * result + amount.hashCode(); return result; } } 15 Compare Private & Confidential. Not for distribution. GSA Capital Partners LLP is authorised and regulated by the Financial Services Authority. Registered in England & Wales. Stratton House, 5 Stratton Street, London, W1J 8LA. Number OC309261 case class Money ( currency: Currency, amount: BigDecimal )
  16. 16.  A modern IDE takes away the task of writing all those lines of code!  I counter-counter-thrust  It’s unreadable  It’s brittle (when you modify the class, you need to remember to change the equals/hashCode)  If it’s a public class, you need to go & create a file for it  It’s a rubbish counter-argument 16 Counter-arguments Private & Confidential. Not for distribution. GSA Capital Partners LLP is authorised and regulated by the Financial Services Authority. Registered in England & Wales. Stratton House, 5 Stratton Street, London, W1J 8LA. Number OC309261
  17. 17. public class Price { private final Money value public Price(Money value) { this.value = value; } public boolean equals(Object o) { ...  I lost the will to live at this point case class Price(val value: Money) extends AnyVal sealed trait Price Money @@ Price 17 A type wrapping a single value! Private & Confidential. Not for distribution. GSA Capital Partners LLP is authorised and regulated by the Financial Services Authority. Registered in England & Wales. Stratton House, 5 Stratton Street, London, W1J 8LA. Number OC309261
  18. 18. type SessionStarts = Instant type SessionEnds = Instant case class MultipleSessions(sessions: SortedMap[SessionStarts, SessionEnds] { def afterFirstOpen(i: Instant) = if (sessions.isEmpty) false else i >= sessions(sessions.firstKey) } case class SessionStarts(val i: Instant) extends AnyVal case class SessionEnds(val i: Instant) extends AnyVal case class MultipleSessions(sessions: SortedMap[SessionStarts, SessionEnds] { def afterFirstOpen(i: Instant) = if (sessions.isEmpty) false else SessionStarts(i) >= sessions(sessions.firstKey) //DOES NOT COMPILE = if (sessions.isEmpty) false else SessionStarts(i) >= sessions.firstKey o/ o/ o/ } 18 Fails to follow own advice Private & Confidential. Not for distribution. GSA Capital Partners LLP is authorised and regulated by the Financial Services Authority. Registered in England & Wales. Stratton House, 5 Stratton Street, London, W1J 8LA. Number OC309261
  19. 19.  Java 8 has added Optional<T> to indicate the possible absence of a value  Haskell Maybe  Scala Option[T]  Except they have totally hobbled it as a type  It is not serializable – you cannot use it in your domain model  It does not have Optional<T> orElse(Optional<T> that) 19 Nullability Private & Confidential. Not for distribution. GSA Capital Partners LLP is authorised and regulated by the Financial Services Authority. Registered in England & Wales. Stratton House, 5 Stratton Street, London, W1J 8LA. Number OC309261
  20. 20.  Scalaz has a disjunction type def function(in: Input): Exception / Output 20 Exceptions Private & Confidential. Not for distribution. GSA Capital Partners LLP is authorised and regulated by the Financial Services Authority. Registered in England & Wales. Stratton House, 5 Stratton Street, London, W1J 8LA. Number OC309261
  21. 21.  The lack of basic types: Pair<A, B>  This means that you don’t see methods in Java interfaces like this: interface Collection<T> { Pair<Collection<T>, Collection<T>> partition(Predicate<? super T> p) ... } • ...or you see them represented terribly public class BigDecimal { public BigDecimal[] divideAndRemainder(BigDecimal d) ... } 21 Hobbled APIs Private & Confidential. Not for distribution. GSA Capital Partners LLP is authorised and regulated by the Financial Services Authority. Registered in England & Wales. Stratton House, 5 Stratton Street, London, W1J 8LA. Number OC309261
  22. 22.  Can we construct our whole program as a type?  What does our program do?  It handles errors  It reads from some configuration  It writes to some log  It manages state transitions  It produces a result  It performs side-effects  ReaderWriterStateT and EitherT 22 Where are we going next? Private & Confidential. Not for distribution. GSA Capital Partners LLP is authorised and regulated by the Financial Services Authority. Registered in England & Wales. Stratton House, 5 Stratton Street, London, W1J 8LA. Number OC309261
  23. 23. type R = MyProps; type W = Unit; type S = MyState; type E = MyError type RWST_[A] = RWST[IO, R, W, S, A] type Program[A] = EitherT[RWST_, E, A] def pure[A](a: => A): Program[A] = EitherT.right(RWST[IO, R, W, S, A]((r, s) => (s, (), a))) def asks[A](f: R => A): Program[A] = EitherT.right(RWST[IO, R, W, S, A]((r, s) => (s, (), f(r)))) def log(msg: => String): Program[Unit] = EitherT.right(RWST[IO, R, W, S, Unit]( (r, s) => (s, println(msg), ()))) 23 Monad transformer stacks Private & Confidential. Not for distribution. GSA Capital Partners LLP is authorised and regulated by the Financial Services Authority. Registered in England & Wales. Stratton House, 5 Stratton Street, London, W1J 8LA. Number OC309261
  24. 24. for { txnsGsa <- queryGsaTransactions(global.date).map(_.values.toStream) rates <- fxRates(global.date) results <- global.configs.toStream traverseU { implicit config => for { txnsPB <- queryAggregatePBDropCopies gsaAgg = aggregateGsaTransactions(txnsGsa) gsaTotal = gsaAgg.aggregate alerts <- thresholdBreaches(txnsPB, gsaTotal) } yield (alerts, gsaTotal - txnsPB.total) } } yield results 24 Non Farm Payrolls Private & Confidential. Not for distribution. GSA Capital Partners LLP is authorised and regulated by the Financial Services Authority. Registered in England & Wales. Stratton House, 5 Stratton Street, London, W1J 8LA. Number OC309261
  25. 25.  Immutability  we have no mutation anywhere  Referential transparency  Easy to reason about our functions and re-use them  We can see at a glance what is going on  is there IO happening in order to get hold of this value?  Could an error occur?  Surprisingly readable  Please don’t attempt to read it though!  This talk is on SlideShare if you want to look in detail later 25 Example Private & Confidential. Not for distribution. GSA Capital Partners LLP is authorised and regulated by the Financial Services Authority. Registered in England & Wales. Stratton House, 5 Stratton Street, London, W1J 8LA. Number OC309261
  26. 26. 26Private & Confidential. Not for distribution. GSA Capital Partners LLP is authorised and regulated by the Financial Services Authority. Registered in England & Wales. Stratton House, 5 Stratton Street, London, W1J 8LA. Number OC309261 lazy val program = for { _ <- fromTryCatch(ProductUniverse.setUniverseProvider(new CoreUniverseProvider)) _ <- log(s"About to run the program with: [${args mkString " "}]") dd <- date _ <- log(s"Running for carry date [$dd]") ps <- positions(dd) _ <- log(f"Found ${ps.size}%,d positions in DI1 futures") cc <- //Only try and get marks and D1 if there *are* positions ps.nonEmpty ?? (for { ms <- marks(dd) _ <- log(f"Found ${ms.size}%,d marks on DI1 futures") d1 <- d1Rate(dd) _ <- log(s"D1 rate is $d1") xx <- either(costs(dd, ps.values.toStream, ms)(d1)) } yield xx) _ <- log(s"Costs for positions are: $cc") fs <- //Must run the furnace section regardless of whether we now have costs furnaceInsertOrUpdate(cc, dd) rs <- { import scala.concurrent.duration._ fromTryCatch(Await.result(fs, atMost = 5.minutes)) } _ <- log(f"Created ${rs.size} furnace events") } yield ()
  27. 27.  “Programming is not math”  When you start thinking about types you should start thinking about how you can PROVE things about your program  For example, you might prove that it is impossible to compare a price with a quantity  You might prove that it is impossible to create a trade from two orders to buy a stock 27 Curry Howard Private & Confidential. Not for distribution. GSA Capital Partners LLP is authorised and regulated by the Financial Services Authority. Registered in England & Wales. Stratton House, 5 Stratton Street, London, W1J 8LA. Number OC309261
  28. 28.  Make use of types at the low-level  To make certain classes of error impossible  To make your intent clearer  That Java puts barriers in the way for this purpose  But that is not a reason not to do it  Nor a reason to eschew Java  That general types are important too  The lack of them will affect the programs you can write  That a language can affect how you think about types  Type parameters are not the enemy  Abstractions are only possible/useful if the language is rich enough to support their use  That if you let types pervade your programs  Your programs can be better! 28 Epilogue Private & Confidential. Not for distribution. GSA Capital Partners LLP is authorised and regulated by the Financial Services Authority. Registered in England & Wales. Stratton House, 5 Stratton Street, London, W1J 8LA. Number OC309261
  29. 29.  It’s not just scala  C C++ C# Scala Matlab Python Java Q FPGA  Plenty of dissenting voices! 29 Technology at GSA Private & Confidential. Not for distribution. GSA Capital Partners LLP is authorised and regulated by the Financial Services Authority. Registered in England & Wales. Stratton House, 5 Stratton Street, London, W1J 8LA. Number OC309261
  30. 30. 30Private & Confidential. Not for distribution. GSA Capital Partners LLP is authorised and regulated by the Financial Services Authority. Registered in England & Wales. Stratton House, 5 Stratton Street, London, W1J 8LA. Number OC309261
  31. 31. Contact us Private & Confidential. Not for distribution. GSA Capital Partners LLP is authorised and regulated by the Financial Services Authority. Registered in England & Wales. Stratton House, 5 Stratton Street, London, W1J 8LA. Number OC309261 31 GSA Capital Partners LLP investor.relations@gsacapital.com T +44 (0)20 7959 8850 London Office Stratton House 5 Stratton Street London W1J 8LA T +44 (0)20 7959 8800 F +44 (0)20 7959 8845 New York Office 1140 Ave of the Americas 9th Floor New York NY 10036

Editor's Notes

  • CLICK!
  • This talk is going to be about the building of financial systems in Scala – I’ll give a brief overview of what I think is the “state of the industry” at the moment and why a lot of people are looking beyond Java. Then I want to take a short look at a couple of the language features of scala which should hopefully whet the appetite to a deeper-dive to what a decent type system can do for you

    CLICK!
  • OK, so this is my background
    1 minute

    CLICK!
  • Essentially we are a technology-driven quant hedge fund. Practically every piece of software used in the company, and this amounts to hundreds of systems, we have built ourselves. I work in the CORE technology group, which is a lot more business-focused than it sounds – my “speciality” is on the post-trade execution side of GSA. Particularly reconciliation, allocation and P&L.

    2 minute

    CLICK!
  • Looking at these ACI talks, I note that many of them are very product-focused and directly relatable to what the companies do. And this means that we have a bit of a problem because GSA are not a software company – I can’t imagine that a half hour talk on our stockloan system would be very popular.

    I was considering a talk on how we track our realtime positions and P&L using an actor-based system built on the Akka library, which consists of tens of thousands of actors sending billions upon billions of messages to remote clients but (and a colleage summed this up really well): “this turns out to be a really hard problem for a lot of very boring reasons”, so I didn’t do that either

    3 minutes
  • The title of this talk is inspired by a short transcript from the #scalaz IRC channel about how to do validity checks on numeric values. It got me thinking rather a lot ...

    Anyway, as part of the GSA recruitment process, we set a practical exercise and I mark most of these. Over the years I’ve seen not far off a hundred different solutions – taking this together with the accumulated work of colleagues over the years and I think it’s not unreasonable for me to make the claim that everyone, everyone could do with listening to this talk. No matter how smart you think you are (or how experienced for that matter)

    4 minutes
  • Misuse of types is everywhere. It is really not at all surprising that you probably write functions which take email addresses as Strings or similar when the authors of programming languages are representing a type which should have 3 values by a type which has 4 billion. We can all see the history here but just because it was so doesn’t mean it must be in perpetuity!

    Anyway, I’d argue that this kind of stuff just sinks in via osmosis

    5 minutes
  • Is a value of 1 100%, or a value of 100, or what? CLICK

    So – a trade was done at a price of 13.4. 13.4 what? Bananas?

    7 minutes
  • There’s a very interesting blog post by Joel Spolsky where he talks about the origins of Hungarian notation (and how it’s come to be mis-used). I assume that everyone here knows what I mean by hungarian notation: generally it means giving variables names prefixed/suffixed with letters and other things indicating what they are. Are they parameters, are they instance variables? Are they strings?

    I’m very happy to say that Java eschewed this –and a decent IDE with semantic highlighting means that it’s now complete,y unnecessary – in fact it serves to obfuscate code rather than illuminate it. Anyway – the original idea was more than this. For example, indicating whether a specific Int was a measure of screen width, or a count of bytes. This is not (of course) a bad idea. CLICK But why stop at the code looking wrong? Why not have it actually *be* wrong?

    9 minutes
  • Going back to the practical, I have literally *never* seen a solution where the price is disambiguated from the quantity using types. It’s quite possible to write a comparator where you accidentally do this. Why not prevent that possibility from ever happening?

    10 minutes
  • 11 minutes
  • There may of course be certain scenarios where it is not feasible to use anything other than the primitive type. That using an object (possibly constructing and throwing it away on each access) is expensive and causes garbage collection. But – THINK! These situations are not the rule. They are the exception. Construct he correct API first and worry about performance when you have proved it is an issue.

    12 minutes
  • You might notice a few things about the previous slides. My type declarations were not in Java – they were in scala

    13 minutes
  • Note – I’m using scala here because that’s the language I’m most familiar with. Many other languages offer the sorts of easy type-creation techniques that programmers absolutely should have at their disposal. Haskell is one

    Now you might argue here that this is grossly unfair: a modern IDE can take away a lot of the pain of writing this stuff

    15 minutes
  • 17 minutes
  • Just making a single value into a type is painful. It needn’t be like this – scala offers two mechanism to do it without incurring any runtime overhead – the first, something called value classes – secondly the ability to “attach” a type to another one

    19 minutes
  • In my last talk here, 3 years ago – I showed how using monoids allowed me to do something under time pressure

    For what I’m talking about here, it’s more a case of “look at what I couldn’t do” than “look at what I can do”

    No sooner had I given my talk internally as practice when ...

    Other examples of this abound in GSA ; our head of research technology was telling me about an instance where he was using a wrongly-scaled price and submitted an internal order using a price that was 8 orders of magnitude out. This never made it past our internal reference price checks, and he is at pains to point out that it was a sell order, and had it been filled, would have resulted in GSA making millions of dollars but – you get the point!


    22 minutes
  • So: what other ways has Java failed us? We come to the famous null – only after 15 years has Java finally added a type to represent the possible absence of a value. Other languages, for example Ceylon use union types to represent this – but they don’t offer (in my opinion) the benefit of the scala implementation. We’ll come to that later

    23 minutes
  • New(er) languages are eschewing checked exceptions whilst keeping exceptions (Sscala, ceylon etc): less type safety
    Disjunction type: can be anything on left-hand side – it encodes possibility of error
    Validation type: for error accumulation (e.g. Validating a web-form, can switch between them)
    Library/language must provide nice way of dealing with chaining such function calls


    24 minutes
  • So – the lack of some basic types has quite profound effects on what sort of APIs you can offer. I spoke here in 2012 and talked about how the lack of traits (i.e. Interfaces with implementation) meant that Java interfaces tended to be very minimal. That is, java.util.Collection has only around 13 methods. The equivalent in scala has over a hundred. This might change a bit now Java 8 has default implementations – but the point stands for other reasons too.

    Java has no Pair type – hence you will find that we don’t find things like “partition” in collection libraries (or extended libraries)


    26 minutes
  • 28 minutes
  • With higher kinds come abstractions at higher levels. We wish to encode everything into our types and have functions which work only on input and produce output.

    We must therefore forgo side effects (both external, IO and internal, mutation), dependency injection etc. We must stop throwing exceptions – we want to encapsulate all of this in our types.

    I don;t expect everyone to follow what is going on in this slide: suffice to say that I am constructing a type to represent my entire program. This type enables me to control state transitions, represent error conditions, access external resources (i.e. Side effects) in a referentially-transparent way. Because it is a monad, if my language of choice provides syntactic sugar for monadic comprehensions, I can write a program (ultimately) built up out of a number of combinators.

    I show a few here: here’s how I can wrap a value insode a program. Here’s how I can wrap a function which grabs something from my global config. Here’s a program which logs a message

    There can be more – combinators representing accessing a value which might throw an exception. Combinators representing side-effects like IO, or combinators involving the transitioning of state.

    30 minutes
  • Recently, more concerns over the financial state of Greece, among other things (troubles in Ukraine etc) meant that we had an extraordinary day of trading

    One of our PBs almost crashed their internal systems, such was the flow GSA were sending their way

    I had a morning to implement checks so that we were comfortable we understood our open positions before the non-farm payrolls, which ended up being our busiest day of trading up to that point – just shy of 2 million trades, in the immediate aftermath, we were doing ten thousand trades a minute.

    Normally I would have knocked something up quick – but I said to myself: “no – this is too important to make an error on”


    So – what goes wrong if we don’t do this?

    We get exception handling wrong
    We’re not forced to think about our failure modes
    We’re not forced to think about which bits of code might fail because they are accessing external resources

    33 minutes
    Doug asked me to demonstrate
  • Will be showing example in a minute
    Don’t want to suggest Monad transformer stacks are the solution to everything
    Plenty of boilerplate
    All I want you to take from this is the general shape of the program


    I don’t want to say that monad transformer stacks are the solution to everything, and there is much boilerplate in scala at least when we construct programs in this way. But there are significant advantages:

    One thing that I really enjoy about writing code like this is that it’s more readable than you might think it should be. On the next slide is some code from a real program which calculates the carry costs associated with a particular type of Brazilian bond future by accessing our positions system and the books the resultant charges into our transaction system. I hope you’d agree that it’s really rather followable

    34 minutes

  • So – here is a real program that exists within GSA. It represents the calculation of the carry-costs associated with holding overnight positions in a particular type of Brazilian bond future, and inserting those costs as cash transactions in our transaction system (called furnace). It looks to my eye (at least, it does if you squint) quite a bit like an imperative program. And yet the program that I’m building up does not actually do anything. It’s a referentially-transparent expression which only has an effect when I run it.

    I can combine it with other programs of the same type in predictable ways: ways that I can reason about sequentially. I don’t need to keep in my head a picture of what locks are being held, or of what mutation I’ve made which I will rely on later. Each piece of this program is constructed as a program which acts only on its input to produce an output. Types do the rest.

    36 minutes
  • Key points:

    Spat between 2 types of programmers
    Bit about CSS and pictures of dogs
    What is curry-howard?
    Programs can prove things
    Re-use existing proofs

    There seems to be a spat between two sets of programmers at the moment that I see a lot; the main thrust seems to be that “programming is not math” and that curry-howard, which essentially is a proof of the equivalence between a mathematical theorem and a type (that is, a program which exists as the implementation of a type is a proof of the theorem which is embedded in the type). Anyway, the idea is that this is totally irrelevant to the concerns of the everyday programmer.

    This is, to put it mildly, rubbish. Yes, I can see that if you are spending your mornings figuring out which pixel offsets in cascading stylesheets produce the most visually satisfying placement of text on a picture of a bemused-looking dog, it might not seem very mathematical. But this is absolutely the wrong way of looking at it. It’s maths in that you can prove things about your program, if you choose to do so!

    It’s maths in that you can re-use results that have been proven by others, in order to simplify your own proof. Have a Stream of values each provided by a side-effect? Simple: sequence them using this library and walk away with a single IO containing a stream of values. I could go on

    38 minutes
  • So – what have we seen in this talk?

    Well, I hope that I have persuaded you to use types more.

    I hope I have persuaded you to agitate for better programming languages.

    I hope I have made you think about what type parameters are

    I hope that I have persuaded you that there is another way of writing programs than a mutable class on which you make a confusing and brittle sequence of inter-dependent method calls.

    39 minutes
  • 40 minutes

×