Age is not an int

Jan. 13, 2015
Age is not an int
Age is not an int
Age is not an int
Age is not an int
Age is not an int
Age is not an int
Age is not an int
Age is not an int
Age is not an int
Age is not an int
Age is not an int
Age is not an int
Age is not an int
Age is not an int
Age is not an int
Age is not an int
Age is not an int
Age is not an int
Age is not an int
Age is not an int
Age is not an int
Age is not an int
Age is not an int
Age is not an int
Age is not an int
Age is not an int
Age is not an int
Age is not an int
Age is not an int
Age is not an int
Age is not an int
Age is not an int
1 of 32

More Related Content

Similar to Age is not an int

Best defense of capital tax charity 15oct2013Best defense of capital tax charity 15oct2013
Best defense of capital tax charity 15oct2013Hans Goetze
CFD Guide - Accendo MarketsCFD Guide - Accendo Markets
CFD Guide - Accendo MarketsAccendo Markets
2014 results presentation_-_data_pack_-_12_february_20152014 results presentation_-_data_pack_-_12_february_2015
2014 results presentation_-_data_pack_-_12_february_2015Company Spotlight
Freetrade 2016 Crowdcube deckFreetrade 2016 Crowdcube deck
Freetrade 2016 Crowdcube deckIsabel Woodford
Smc previewSmc preview
Smc previewItumeleng S
STAR Conference, Londra - 9 ottobre 2017STAR Conference, Londra - 9 ottobre 2017
STAR Conference, Londra - 9 ottobre 2017Tamburi Investment Partners

Recently uploaded

Data-Driven (Reinforcement Learning-Based) ControlData-Driven (Reinforcement Learning-Based) Control
Data-Driven (Reinforcement Learning-Based) ControlDebmalya Biswas
AI Prompt EngineeringAI Prompt Engineering
AI Prompt EngineeringJason J Pulikkottil
alfred-product-research-proposal.pdfalfred-product-research-proposal.pdf
alfred-product-research-proposal.pdfAlfredSuratos
alfred-product-research-proposal.pdfalfred-product-research-proposal.pdf
alfred-product-research-proposal.pdfAlfredSuratos
Webinar : L&H Insurance in the 21st Century: Navigating Antimicrobial Resista...Webinar : L&H Insurance in the 21st Century: Navigating Antimicrobial Resista...
Webinar : L&H Insurance in the 21st Century: Navigating Antimicrobial Resista...The Digital Insurer
10 reasons to choose Galaxy Tab S9 for work on the go10 reasons to choose Galaxy Tab S9 for work on the go
10 reasons to choose Galaxy Tab S9 for work on the goSamsung Business USA

Age is not an int

Editor's Notes

  1. CLICK!
  2. 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!
  3. OK, so this is my background 1 minute CLICK!
  4. 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!
  5. 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
  6. 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
  7. 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
  8. 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
  9. 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
  10. 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. 11 minutes
  12. 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
  13. You might notice a few things about the previous slides. My type declarations were not in Java – they were in scala 13 minutes
  14. 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
  15. 17 minutes
  16. 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
  17. 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
  18. 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
  19. 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
  20. 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
  21. 28 minutes
  22. 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
  23. 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
  24. 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
  25. 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
  26. 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
  27. 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
  28. 40 minutes