Slide 1

Slide 1 text

Building better software through mathematics (And no, I don't mean formal verification) Greg Brockman Stripe CTO // @thegdb

Slide 2

Slide 2 text

Mathematical problem-solving techniques are dual to software engineering techniques. ! Proof by example to follow.

Slide 3

Slide 3 text

Mathematical low road Define “determinant” as a formula of various pieces of a matrix. ! Use symbolic manipulation to prove a bunch of interesting properties. ! It’s exhausting, but it works.

Slide 4

Slide 4 text

Translated to engineering… Just bang code into your editor. ! Easy to produce but hard to maintain or extend. ! This is what programming is for many people.

Slide 5

Slide 5 text

Translated to code… my_hand = ["2C", "2D", ...].shuffle your_hand = ... ! while true my_card = my_hand.shift your_card = your_hand.shift ! compare = compare_cards(my_card, your_card) if compare > 0 ...

Slide 6

Slide 6 text

Mathematical middle road Define “determinant” as a function with a few specific properties. ! Oh hey, it’s easy to show existence and uniqueness. Use these properties to easily derive a formula. ! It’s a clever way to solve the problem at hand.

Slide 7

Slide 7 text

Translated to engineering… Decompose your program into modules. ! The implementation of those modules should follow naturally from their interface. ! If it’s hard to implement any one piece, you haven’t decomposed enough.

Slide 8

Slide 8 text

Translated to code… class Card; ...; end class Hand; ...; end ! class War def initialize @my_hand = Hand.new @your_hand = Hand.new end ! def start my_card = @my_hand.draw your_card = @your_hand.draw if my_card.beats(your_card) ...

Slide 9

Slide 9 text

Mathematical high road Build the theory of exterior product space. Determinant is a special case of this general theory. ! All our desired properties are obvious. ! This is the “Ender’s Game” approach to problem solving.

Slide 10

Slide 10 text

Translated to engineering… Break a system into fundamental units, and design very general abstractions around them. ! This is really, really hard. ! When you get it right, everything else becomes easy. When you get it wrong, you never ship.

Slide 11

Slide 11 text

Translated to code… class War < AbstractCardGame players 2 loss_condition {my_hand.length == 0} victory_condition {your_hand.length == 0} on_win “add_card_to_deck” end

Slide 12

Slide 12 text

Mathematics is just software with a more expressive, more performant programming language.

Slide 13

Slide 13 text

Software does have its advantages though…

Slide 14

Slide 14 text

Mathematics: Software engineering:

Slide 15

Slide 15 text

Can we apply learnings from mathematics (which has had thousands of years to mature) to build better software?

Slide 16

Slide 16 text

Yes. (Ok, it’s not really fair to answer my own rhetorical questions.)

Slide 17

Slide 17 text

Elegance through least action Mathematical elegance comes from a stubborn unwillingness to do unnecessary work — refusing to accept anything but the simplest, most compact solution. ! In software, choose the design that requires to unnecessary work for your user. Example:

Slide 18

Slide 18 text

Understand how your abstractions are implemented To use a theorem, you need to understand its proof. ! In software, if you don’t understand how the abstractions you use are built, you won’t understand the resulting system.

Slide 19

Slide 19 text

Design software down but build software up The concept of “brute force” as a shortcut is well-understood in math. You’ll generally brute force by hand. ! In software, your CPU can instead do the brute force. Take advantage of this to get software built faster.

Slide 20

Slide 20 text

Greg Brockman Stripe CTO // @thegdb