Return to Video

35C3 - A farewell to soul-crushing code

  • 0:05 - 0:17
    35c3 preroll music
  • 0:17 - 0:24
    Herald: So our first talk is going to be
    presented by two speakers: Michael Sperber
  • 0:24 - 0:30
    and Nicole Rauch. Michael is the CEO of
    Active Group. He has been developing
  • 0:30 - 0:35
    software and teaching programming for over
    30 years, and Nicole is an independent
  • 0:35 - 0:40
    software developer, focusing on domain
    driven design and event streaming and
  • 0:40 - 0:44
    she's been organizing Software
    Craftsmanship conferences. So please give
  • 0:44 - 0:50
    them a big round of applause for this
    talk.
  • 0:50 - 0:55
    Michael: Good morning everyone. Ah, this
    thing is on.
  • 0:55 - 1:02
    Nicole: Hey, it works. Excellent. Cool.
    So… soul-crushing code: I think before we
  • 1:02 - 1:06
    say farewell, we should think about what
    it actually is. And so I thought… *looks
  • 1:06 - 1:13
    at projection surface I'd maybe get a
    presentation first.
    projection of slides
  • 1:13 - 1:20
    starts* Excellent. So. OK. So first maybe
    we should talk a little bit about what's
  • 1:20 - 1:27
    soul-crushing code is and so I brought
    something for you for your entertainment.
  • 1:27 - 1:34
    And here we go. This is some code I found
    in an eclipse tutorial. If you know a
  • 1:34 - 1:40
    little bit about eclipse you can see this
    by looking at this "I…" thing here. Yeah.
  • 1:40 - 1:45
    And this actually… I mean I have no idea
    what that this does. You know, you have
  • 1:45 - 1:51
    this AdapterFactory which is really like…
    okay… and then we get an adapter and
  • 1:51 - 1:59
    there's lots of stuff going on. But what
    actually is this doing… so there is
  • 1:59 - 2:05
    "Todo". OK. This gives a hunch that this
    might be this famous Todo example, but
  • 2:05 - 2:10
    then I have no idea what's happening here
    M: but maybe that's just Eclipse, right,
  • 2:10 - 2:13
    and in Eclipse everything is an adapter
    for something else.
  • 2:13 - 2:19
    N: OK. Maybe. So, OK, I had expected you
    to say something like this so I thought
  • 2:19 - 2:26
    I'd bring another example. And this
    actually is from an open source project.
  • 2:26 - 2:31
    And this actually is a
    NativeQueryInterpreterInitiator. I also
  • 2:31 - 2:36
    want an interpreter initiator – who
    doesn't? And also it's a
  • 2:36 - 2:41
    SessionFactoryServiceInitiator. Wow, I'm
    getting impressed. So. And then it also
  • 2:41 - 2:46
    does lots of stuff and then. OK. We have
    initiateService() and then we have another
  • 2:46 - 2:54
    initiateService(). And then at the end…
    wow… we have this: getServiceInitiated.
  • 2:54 - 2:58
    Well OK so fine.
    M: But I mean that's just a bunch of kids
  • 2:58 - 3:01
    doing open source software.
    N: Right. Yeah, this is open source
  • 3:01 - 3:04
    software.
    M: So these are all hobbyists. So I mean
  • 3:04 - 3:05
    what would you expect from something like
    that, right?
  • 3:05 - 3:08
    N: OK fair enough.
    M: So, I brought a professional example.
  • 3:08 - 3:10
    N: Oh I see.
    laughter in the audience
  • 3:10 - 3:14
    N: Everybody stand back.
    M: So here's a professional example. So
  • 3:14 - 3:18
    this is from a system that does queries of
    some sort. I think there's a mishap in
  • 3:18 - 3:22
    translation from German or French to
    English in me or somewhere. So we can see
  • 3:22 - 3:25
    that it does either full text search or it
    does non full text search or something
  • 3:25 - 3:30
    like that. And so obviously in the
    initialization of some C++ class it checks
  • 3:30 - 3:36
    that flag and it instantiates some object
    either to the full text variant or the non
  • 3:36 - 3:40
    full text variant. Right. And you would
    think that this object oriented design,
  • 3:40 - 3:42
    you just go and call methods.
    N: Yeah…
  • 3:42 - 3:44
    M: You get one instance variable that you
    have there.
  • 3:44 - 3:48
    N: if and else is sooo object oriented.
    M: Yeah, well, that's just the
  • 3:48 - 3:52
    constructor. Right. This is not the bad
    part. The bad part is that every single
  • 3:52 - 3:55
    method that actually does something – like
    this one – looks like this, right, it
  • 3:55 - 3:57
    checks that flag again
  • 3:57 - 3:59
    laughter in the audience
  • 3:59 - 4:04
    M: and it either calls "VolltextRecherche"
    which is… I guess it also has something to
  • 4:04 - 4:10
    do with full text search… you can see that
    there's lines commented out and nobody
  • 4:10 - 4:16
    remembered to leave a comment as to why
    it's commented out. And you can see that
  • 4:16 - 4:20
    this code is really fragile, right. If you
    want to maintain that kind of code… every
  • 4:20 - 4:24
    method looks like this. You always need to
    remember to check that flag before you do
  • 4:24 - 4:27
    anything to be sure that… "Oh I'm here" or
    "I'm there".
  • 4:27 - 4:34
    N: OK yeah. So I mean… OK… So the fact
    that somebody uses an object-oriented
  • 4:34 - 4:39
    programming language does not necessarily
    imply they actually understand what object
  • 4:39 - 4:43
    orientation is all about. Right. So maybe
    they are just crappy programmers.
  • 4:43 - 4:47
    M: OK.
    N: So they happen to use this and then
  • 4:47 - 4:51
    they messed it up on the way you know…
    M: You mean non-crappy programmers can
  • 4:51 - 4:56
    produce crappy code
    N: And now you're getting me confused…
  • 4:56 - 4:59
    both laugh
    N: … probably.
  • 4:59 - 5:02
    M: I think I have… you have another
    example.
  • 5:02 - 5:08
    N: Yes I have a much better example here.
    A real object-oriented example. So this is
  • 5:08 - 5:18
    finance, right. So here we have options,
    in this case just call options, and so the
  • 5:18 - 5:22
    the financial guys want to talk about
    those options. But there are so many
  • 5:22 - 5:26
    different kinds of options so they cannot
    talk about each of them individually and
  • 5:26 - 5:32
    so they want to group them together in
    something they call a basket. So up here
  • 5:32 - 5:37
    you can see this basket, and it contains
    Google and Facebook, because they are sort
  • 5:37 - 5:41
    of like the same, you know.
    So they just group them together in this
  • 5:41 - 5:46
    basket and then they want to talk about
    properties of this basket of all those
  • 5:46 - 5:52
    options that are contained in it. And for
    example here they implement this market
  • 5:52 - 5:57
    data. And so this is standard object-
    oriented business like everything is a
  • 5:57 - 6:02
    class, right? And there we have two
    methods in there because that's also
  • 6:02 - 6:07
    standard object oriented business: We have
    a class and then we have methods in there.
  • 6:07 - 6:13
    And one of the first methods, GetSpot(),
    just gives us the spot price. So all of
  • 6:13 - 6:17
    these options have a number in the real
    world. And that's why they number this
  • 6:17 - 6:24
    here and now for fun they call this
    sicovam. I have no idea why, this seems to
  • 6:24 - 6:29
    be a French word for… I don't know what it
    means, but yeah, just go with us.
  • 6:29 - 6:33
    M: So. So this maturity thing that's the
    date at which point the option expires.
  • 6:33 - 6:41
    N: Yeah. So that's for the volatility. So
    you get the volatility for an option. An
  • 6:41 - 6:48
    option as defined by the underlying asset.
    And by the date it's due and also by the
  • 6:48 - 6:54
    price it's supposed to have then, and
    that's what is encoded here. So we have
  • 6:54 - 6:58
    the option with this long and then we have
    the maturity which is a point in time, so
  • 6:58 - 7:04
    we can properly use a double for this, I
    think. And then we have the strike which
  • 7:04 - 7:10
    is the price and probably some of you know
    that it's not a very good idea to deal
  • 7:10 - 7:15
    with money in terms of doubles. But on the
    other hand it's fairly common in banking.
  • 7:15 - 7:24
    So let's let's do this here as well. Okay
    fine. So yeah that's it. Yeah. And then
  • 7:24 - 7:28
    what they actually want to do so they
    don't only want to look at the world as it
  • 7:28 - 7:35
    is but you know those guys with the
    suspenders you know they want to analyze
  • 7:35 - 7:40
    and see what might happen if something
    would happen you know. So they want to
  • 7:40 - 7:45
    play what-if games and for this what-if
    game here they take the spot price and
  • 7:45 - 7:50
    they actually want to shift it. So they
    want to say what if the spot price were
  • 7:50 - 7:56
    different and what would happen then with
    my options. And here they are just… you
  • 7:56 - 8:03
    know, so if you want to modify something
    in object orientation you write a derived
  • 8:03 - 8:07
    class and this is the derived class
    SpotShiftedMarketData, and this derived
  • 8:07 - 8:17
    class overrides the GetSpot method and it
    takes the value of the parent class and
  • 8:17 - 8:24
    multiplies it with the factor. Okay.
    Sounds straightforward so far. And then of
  • 8:24 - 8:28
    course they don't only want to multiply
    this with a factor, but they also want to
  • 8:28 - 8:35
    do other modifications and they want to be
    able to do all these modifications without
  • 8:35 - 8:38
    re-compiling. So they want to play around
    with these and they don't want to
  • 8:38 - 8:44
    recompile their code every time they
    change something. So they want to have a
  • 8:44 - 8:49
    dynamically configurable code base so to
    speak, or dynamically configurable market
  • 8:49 - 8:55
    data. And if you look this up in the
    object-oriented literature you come up
  • 8:55 - 9:00
    with the decorator pattern. And so the
    Decorator pattern is something that allows
  • 9:00 - 9:06
    you to dynamically modify your code. So
    you have a component and then you derive a
  • 9:06 - 9:11
    decorator and the decorator is a delegate
    to something else. You want to plug-in
  • 9:11 - 9:18
    basically. And this is how they
    implemented the delegate so they wrote the
  • 9:18 - 9:24
    decorator as a derived class. And then
    they have there that they have the real
  • 9:24 - 9:32
    object in there and for the GetSpot method
    here they just ask the GetSpot method of
  • 9:32 - 9:39
    the underlying object. Fair enough. And
    now going back to the baskets, where I
  • 9:39 - 9:47
    started out initially. So what they did in
    this one derived modification here they
  • 9:47 - 9:55
    multiplied with a factor. And now in the
    basket they ... they get here. Here they
  • 9:55 - 10:01
    get a bunch of options, say, or a bunch of
    assets and now they want to calculate this
  • 10:01 - 10:07
    for all of them and they go into this
    recursively and – it's very hard to see
  • 10:07 - 10:13
    here – but what actually happens is they
    go into this recursively and do this
  • 10:13 - 10:18
    modified operation for all of them and
    because of late binding it happens that
  • 10:18 - 10:23
    they keep getting through this upper
    method again and again so adding the
  • 10:23 - 10:29
    factor again and again. And of course they
    did not figure this out by looking at the
  • 10:29 - 10:34
    code, because it's – like I said – really
    hard to understand. And of course this
  • 10:34 - 10:40
    is all just small snippets of the code but
    this is the essence. But they found this
  • 10:40 - 10:45
    because the values were incorrect, right,
    and so what they did is they compensated
  • 10:45 - 10:53
    for this. And for example here is the most
    interesting part I think: Does the first
  • 10:53 - 11:00
    market data derive from the second one? So
    they check whether they have this chain
  • 11:00 - 11:08
    going on and then they do something
    differently. Wow. I mean this is
  • 11:08 - 11:13
    production code, right. And this is still
    in operation and probably this method by
  • 11:13 - 11:18
    now is like hundreds of lines long because
    they have so many edge cases they need to
  • 11:18 - 11:26
    compensate for. Well.
    M: Yeah. So can imagine that. Yeah but I
  • 11:26 - 11:31
    mean it's obvious they just shouldn't have
    done this in C++ or using object-oriented
  • 11:31 - 11:35
    programming, right.
    N: Phew… so, do you have a better solution?
  • 11:35 - 11:38
    M: Oh, absolutely. Absolutely.
    We have slides on this.
  • 11:38 - 11:40
    N: You have slides!
    M: People should have used functional
  • 11:40 - 11:42
    programming, right. Which is great, because…
  • 11:42 - 11:44
    N: Oh, how could I forget this?
    M: Yeah.
  • 11:44 - 11:46
    N: Of course you would say that.
    M: Yeah. You know, I'm the functional
  • 11:46 - 11:48
    programming person here on stage.
  • 11:48 - 11:49
    N: chuckles
    M: So functional programming has all these
  • 11:49 - 11:54
    advantages, right. You can have immutable
    data. Immutable data means you have less
  • 11:54 - 11:57
    coupling. You don't have these complicated
    effects going on that you saw earlier
  • 11:57 - 12:01
    maybe. You can use… functional programming
    is very close to mathematics, so you can
  • 12:01 - 12:03
    apply formal verification…
    N: Isn't that scary?
  • 12:03 - 12:07
    M: Yeah. You can use all these great
    mathematical things in there. You can have
  • 12:07 - 12:13
    catamorphisms, you can have bifunctors.
    That's my new favorite thing. Monadic
  • 12:13 - 12:18
    profunctors is also something that we've
    been using lately. That's great. Kleisli
  • 12:18 - 12:20
    arrows. There's all these wonderful things
    in functional programming and they solve
  • 12:20 - 12:23
    all of these problems, right?
    N: Yes I could…
  • 12:23 - 12:25
    M: (towards the audience) Why are you
    laughing? Who's laughing?
  • 12:25 - 12:31
    N: I should have imagined you saying
    something like this. So… but… have you
  • 12:31 - 12:37
    ever considered that you're tackling the
    problem from the wrong angle. I mean you
  • 12:37 - 12:46
    and your horde of IT tech nerds, you're
    sitting in your cave, hacking away, having
  • 12:46 - 12:50
    your hoodie over your head and just
    sitting there and hacking and hacking.
  • 12:50 - 12:54
    M: (takes off his hoodie)
    N chuckles, audience laughs
  • 12:54 - 13:02
    M: So that problem solved. Okay anyway.
    N: Yeah. And I mean really just throwing
  • 13:02 - 13:06
    tech at the problem is not a solution,
    it's actually part of the problem…
  • 13:06 - 13:12
    M: But Nicole, we're producing software,
    we're producing tech, right? Have you gone
  • 13:12 - 13:14
    through this thing here points outside
    the hall
    ? There's tech outside everywhere
  • 13:14 - 13:18
    that… How do you make that?
    N: Probably not by sitting in the corner
  • 13:18 - 13:22
    and just writing… hacking away.
    M: OK.
  • 13:22 - 13:28
    N: So have you considered that there is
    more to it, that it's not only just tech,
  • 13:28 - 13:31
    that you need to talk to each other?
    M: Mm hmm…
  • 13:31 - 13:36
    N: Yesterday I saw this robot walking
    around in a circle and it said "I need new
  • 13:36 - 13:40
    code, please talk to me", right. This is
    something like this.
  • 13:40 - 13:44
    M: OK.
    N: So we need to talk to each other. It's
  • 13:44 - 13:47
    not only tech. Tech is nice and
    everything.
  • 13:47 - 13:50
    M: So where is… Do you have like a pattern
    manual for that?
  • 13:50 - 13:55
    N: A pattern manual? Yes, of course. There
    are talking patterns actually for people
  • 13:55 - 14:01
    like you. chuckles, audience laughs
    M: clears throat OK. So go. Go ahead.
  • 14:01 - 14:03
    N: So…
    M: Educate me.
  • 14:03 - 14:09
    N: OK. So I mean there were many
    approaches over the years, right. Some
  • 14:09 - 14:15
    approaches were for example… looking at
    agile software development you know and it
  • 14:15 - 14:21
    says "individuals and interactions over
    processes and tools". Tools… tech…
  • 14:21 - 14:25
    M: OK
    N: So let's talk together and let's figure
  • 14:25 - 14:28
    out things.
    M: OK well but it does say working
  • 14:28 - 14:34
    software also, right?
    N: One of four, you know, says "working
  • 14:34 - 14:37
    software" because of course we also want
    working software, right.
  • 14:37 - 14:40
    M: Yeah.
    N: I mean, just talking and no coding is
  • 14:40 - 14:43
    also not the answer. So…
    M: Yeah, anyway, so last year we were at
  • 14:43 - 14:46
    this conference, right, and you were
    probably talking to somebody but I
  • 14:46 - 14:52
    actually attended the keynote and it was
    by somebody who talked about what worked
  • 14:52 - 14:56
    and what were the ongoing problems in
    software engineering. And this was an
  • 14:56 - 15:01
    agile company, right? They do everything
    in an agile manner. So supposedly they
  • 15:01 - 15:05
    communicate all the time, but still when
    they look at where they spend all of their
  • 15:05 - 15:10
    time and all of their work and effort they
    say that they still spend 53 percent on
  • 15:10 - 15:14
    maintenance and complexity and not on new
    features or… I have no idea what that
  • 15:14 - 15:17
    professionalization thing is actually. But
    it takes up 18 percent…
  • 15:17 - 15:21
    N: nice
    M: So let's get back to the technical
  • 15:21 - 15:25
    problem, shall we. OK
    N: Yeah. So I mean we already saw this
  • 15:25 - 15:31
    right in the market data example. I think
    much of this maintenance and complexity
  • 15:31 - 15:40
    problems is caused that we're in a world
    consisting of objects and so everybody
  • 15:40 - 15:46
    jumps on this object-oriented bandwagon,
    right? So what they actually end up with
  • 15:46 - 15:49
    is something like this
    laughter in the audience
  • 15:49 - 15:56
    M: OK
    N: And this is sort of… yeah… not helpful.
  • 15:56 - 16:01
    M: So maybe but I would like to explain
    this maybe in a different way. So modern
  • 16:01 - 16:06
    object oriented programming – while you
    can all laugh at that slide before – but
  • 16:06 - 16:10
    we really need to understand the problem,
    right. The technical problem is this,
  • 16:10 - 16:15
    right? So at the at the heart of modern
    object-oriented programming something
  • 16:15 - 16:18
    called imperative programming where all
    these objects that you showed on the
  • 16:18 - 16:24
    previous slides they have what's called
    encapsulated state. Okay? There's some
  • 16:24 - 16:27
    state in there. And what happens is the
    world progresses by all these objects
  • 16:27 - 16:32
    sending messages to each other. And as a
    result of a message, some code gets
  • 16:32 - 16:38
    executed that modifies that encapsulated
    state. Now the thing was… I mean object-
  • 16:38 - 16:42
    oriented programming was originally
    developed to support simulations of the
  • 16:42 - 16:45
    real world. And the problem is that the
    real world just does not work like that.
  • 16:45 - 16:50
    The real world is not a bunch of objects
    sending messages to each other. So one
  • 16:50 - 16:54
    simple example that maybe can help explain
    that is there is an el… Speaking of
  • 16:54 - 16:56
    elephants, right?
    N: Yes
  • 16:56 - 16:59
    M: Great elephant slide. So. So there is
    an elephant and the elephant comes in from
  • 16:59 - 17:03
    the jungle and walks into some kind of
    room, right? And the object-oriented model
  • 17:03 - 17:08
    for this is… well… all the entities get
    models, get objects, so that the elephant
  • 17:08 - 17:12
    has an object, the jungle has an object,
    and the room that the elephant enters has
  • 17:12 - 17:18
    an object that represents them. And you
    have the sequence of method calls or
  • 17:18 - 17:24
    message sends that tries to reproduce that
    sequence as well that you know the jung…
  • 17:24 - 17:29
    that the elephant exits the jungle and the
    elephant enters the room, right? The
  • 17:29 - 17:32
    problem is that the exiting of the jungle
    and the entering of the room are one and
  • 17:32 - 17:36
    the same act. So the real world has
    dependencies, it is not just a bunch of
  • 17:36 - 17:42
    isolated entities that are sending
    messages to each other. Things hang
  • 17:42 - 17:47
    together in the real world. So if… so I
    think a more useful model for thinking
  • 17:47 - 17:53
    about programs and how programs should
    model the real world has to do with…
  • 17:53 - 17:57
    should really go through the way that we
    perceive things. So, if you watch a soccer
  • 17:57 - 18:03
    game these days there's lots of objects
    that you see, right. So you see 22
  • 18:03 - 18:06
    players, maybe you see a ball, you see the
    referees and you see lots of people in the
  • 18:06 - 18:13
    audience and they all move. Now. So, they
    all change their internal state if that's
  • 18:13 - 18:16
    the model that you use. Now, if you want
    to know what's going on in the football
  • 18:16 - 18:20
    field, you need to observe all of these
    changes. But, you know what the object
  • 18:20 - 18:25
    orient model is for observing changes?
    Something called the observer pattern,
  • 18:25 - 18:29
    which means that you register which each
    of these objects and tell them: Well, if
  • 18:29 - 18:33
    anything changes with you, send me a
    message. You want your ball, send me a
  • 18:33 - 18:35
    message if you move, you know, you do that
    with all the players, supposedly, you do
  • 18:35 - 18:42
    that with all the 20000 audience members.
    And of course, when you leave the stadium
  • 18:42 - 18:46
    you all send the messages: Oh no, I'm no
    longer interested in what you're doing,
  • 18:46 - 18:51
    right. The world doesn't work like that.
    It has another problem, that all these
  • 18:51 - 18:55
    messages will arrive in some sort of
    sequential order, and that also would mean
  • 18:55 - 19:01
    that with all of these objects moving
    around, we would observe inconsistencies
  • 19:01 - 19:05
    all the time, the same way that you
    observed it with the elephants going into
  • 19:05 - 19:10
    the room, right. If you remember, there
    was an inconsistent state in the middle
  • 19:10 - 19:17
    here. Which was that after the first step
    the elephant is, for a brief amount of
  • 19:17 - 19:22
    time, is nowhere. It has exited the
    jungle, but it has not entered the room
  • 19:22 - 19:26
    yet. And the same is true, of course, if
    we have many moving objects. But yet, we
  • 19:26 - 19:31
    never observe, like one person getting up
    and suddenly appearing in another place,
  • 19:31 - 19:36
    or two people appearing in the same place
    at the same time. And that's because our
  • 19:36 - 19:42
    perceptive apparatus creates consistent
    snapshots of what we observe, right? We
  • 19:42 - 19:45
    look at something, and it gets stored in
    memory and we can think about it for a
  • 19:45 - 19:51
    little amount of time and analyze what's
    going on. And so, of course, we remember
  • 19:51 - 19:53
    things that were in the past, which is
    also something that an object oriented
  • 19:53 - 19:58
    model cannot do. So, I think there's
    fundamental problems with this object
  • 19:58 - 20:02
    oriented model of programming, and that's
    one of the fundamental things that leads
  • 20:02 - 20:04
    to that soul crushing code that we've been
    talking about.
  • 20:04 - 20:11
    N: Now, that actually reminds me of a very
    interesting thing that lots of people are
  • 20:11 - 20:16
    using, and that's in the UI and it's
    called the MVC pattern, or Model View
  • 20:16 - 20:21
    Controller. And if you have ever worked
    with us, you can see here that this all
  • 20:21 - 20:26
    goes in circles and you can go in any
    direction and then you end up here again,
  • 20:26 - 20:31
    or you go this way around, or anything, or
    follow this dashed line. And so you can go
  • 20:31 - 20:38
    from anywhere to everywhere. And this
    leads to the obvious problem that, if you
  • 20:38 - 20:43
    have changes in the model, and changes in
    view, they need to, hopefully, be
  • 20:43 - 20:50
    corresponding. Or, maybe not. And what do
    you do about this? So, what you end up
  • 20:50 - 20:57
    with, if you do this enough, and if you
    aren't very, very careful, you end up with
  • 20:57 - 21:01
    this.
    M: Night MVC fraught programs have always
  • 21:01 - 21:06
    looked like that, right.
    N: Yes. Feels really familiar doesn't it.
  • 21:06 - 21:10
    M: Yeah. Yeah, it does.
    N: And I think that's also what Alan Kay
  • 21:10 - 21:17
    was talking about, back in the day. So,
    this is a quote from 1996. But I think the
  • 21:17 - 21:27
    paper just appeared then. But the original
    quote is much older. And so he said, okay,
  • 21:27 - 21:35
    OOP had those motivations that we
    described here. But eventually, we need to
  • 21:35 - 21:39
    overcome this model and we need to find
    something better, and eliminate it
  • 21:39 - 21:43
    altogether. That's what he says here.
    M: But that never happened, right?
  • 21:43 - 21:46
    N: No, I don't think so.
    M: Never happened. So if these days, if
  • 21:46 - 21:50
    you look for examples of how object
    oriented programming works, it always is
  • 21:50 - 21:56
    about encapsulated state that Alan Kay
    wanted to get rid of. So, I think that's
  • 21:56 - 21:59
    the first thing when I searched for Object
    Oriented examples, was something with
  • 21:59 - 22:06
    students, and you can immediately see that
    a lot of attributes that you have there go
  • 22:06 - 22:10
    through some kind of, some method that
    modifies them. My favorite one is that you
  • 22:10 - 22:14
    have the student and you can set the grade
    point average of the student. So you can
  • 22:14 - 22:17
    just,... yeah. So, if you're not happy
    with the grades that your kid is getting
  • 22:17 - 22:24
    you just sent the object a message. Get it
    get a perfect GPA there. So, and let me
  • 22:24 - 22:29
    reiterate, Nicole, of course people should
    have used functional programming. Which
  • 22:29 - 22:31
    has all these simple languages, less
    complexity, higher productivity, less
  • 22:31 - 22:35
    bugs. You know, we have all these powerful
    type systems, we can do property based
  • 22:35 - 22:39
    testing. We can do, oh it goes on and on,
    and we get more predictable behavior.
  • 22:39 - 22:43
    Generally testing is easier, because we
    don't need, you know, set up and tear down
  • 22:43 - 22:48
    methods. You get lower couplings, you have
    fewer dependency cycles. So, I didn't even
  • 22:48 - 22:51
    say monad, right, here in this list. So
    you get all these concrete...
  • 22:51 - 22:53
    N (at the same time): Lucky me.
    M: You get all these concrete advantages
  • 22:53 - 22:56
    from doing functional programming, right?
    And so that's what people should do to
  • 22:56 - 22:58
    solve those problems.
    N: So do you remember
  • 22:58 - 23:03
    M (at the same time): You, too.
    N: Fred Brooks, he said there is no silver
  • 23:03 - 23:06
    bullet.
    M: OK.
  • 23:06 - 23:10
    N: So, what do you say about that?
    M: Fred Brooks is an old guy, right?
  • 23:10 - 23:12
    N: Yes.
  • 23:12 - 23:13
    laughter
  • 23:13 - 23:18
    N: And what about you?
    M (laughing): Yeah, I guess I am, too.
  • 23:18 - 23:25
    M: I'm getting there. Yeah. Well, so Fred
    Brooks said that, but he's an old guy. So
  • 23:25 - 23:30
    let me get you one example of why that
    maybe is not true. So in the early 90s
  • 23:30 - 23:34
    actually, there was a big study conducted
    by the U.S. Navy, on the effectiveness of
  • 23:34 - 23:38
    different programming languages. And they
    had one set problem that was about
  • 23:38 - 23:42
    determining the regions of influence of
    warships and they had different teams
  • 23:42 - 23:48
    write solutions for their problem in
    different languages. And what they ended
  • 23:48 - 23:52
    up doing is also, they gave that also to
    people who were using functional
  • 23:52 - 23:56
    programming, specifically in the Haskell
    programming language, which was still
  • 23:56 - 24:01
    pretty young back then. And you can see,
    well, the solution in Haskell is much
  • 24:01 - 24:06
    shorter than the solution... you know C++,
    definitely. You know, less than 10 times
  • 24:06 - 24:12
    as short than the C++ solution. I think
    Java wasn't as big then. But I think the
  • 24:12 - 24:17
    factor would also be around between 3 and
    10 somewhere. Also, what's maybe
  • 24:17 - 24:21
    interesting, is that there are two Haskell
    solutions. One at the top and one of the
  • 24:21 - 24:24
    bottom, and...
    N: Probably they just split the code so
  • 24:24 - 24:26
    the numbers look nice.
  • 24:26 - 24:27
    laughter
  • 24:27 - 24:30
    M: Yeah, yeah. You would need to add them
    up, now that would be interesting. But
  • 24:30 - 24:33
    what they did is, they had a Haskell
    expert write a solution, and then they
  • 24:33 - 24:36
    also gave the solution to a student, I
    think, who learned Haskell for two or
  • 24:36 - 24:43
    three weeks and who also wrote a solution.
    And if you look at development time, so
  • 24:43 - 24:49
    somebody took 10, hours and somebody took
    8 hours, and the 8 hours as a student.
  • 24:49 - 24:53
    That's because the Haskell
    expert tried to put many interesting
  • 24:53 - 24:57
    flourishes and super cool programming
    techniques into the program but the
  • 24:57 - 25:01
    student was actually doing pretty well.
    So if that is not a silver if that's
  • 25:01 - 25:04
    not what a silver bullet looks like I
    don't know what would.
  • 25:04 - 25:11
    N: So the Yale study. They got a fixed set
    of instructions and they just had to code
  • 25:11 - 25:15
    those instructions. Do I remember that
    correctly?
  • 25:15 - 25:19
    M: Yeah. Yeah. Yeah.
    N: So do you ever experience that in the
  • 25:19 - 25:25
    real world? Getting a fixed set of
    instructions from your client and then
  • 25:25 - 25:31
    just implementing this and they never
    change their mind? They never come up with
  • 25:31 - 25:41
    new ideas? They never say "Oh I forgot
    something". I actually don't experience
  • 25:41 - 25:47
    this.
    M: Let me think about it.
  • 25:47 - 25:55
    N: That's what we need to consider as
    well. Coming back to the elephant. Talking
  • 25:55 - 25:57
    to each other. Everybody has different
    ideas ...
  • 25:57 - 26:01
    M: Are you gonna start with that agile
    stuff again?
  • 26:01 - 26:07
    N: Everybody has different ideas when they
    look at something and everybody describes
  • 26:07 - 26:13
    things differently and so what we need to
    do is to figure this out together. You
  • 26:13 - 26:17
    know coding a bit, talking a bit, talking
    a bit, coding a bit. And so this needs to
  • 26:17 - 26:23
    go hand-in-hand. And this is sort of
    agile, you know. So it doesn't mean Scrum
  • 26:23 - 26:28
    and you know standing in a circle every
    day or something. Relax, okay?
  • 26:28 - 26:31
    M: So I personally I like to communicate
    with code.
  • 26:31 - 26:35
    N: You can do that too, yes.
    M: That makes me think of an example. We
  • 26:35 - 26:38
    were working on a project. That was in a
    semiconductor factory.
  • 26:38 - 26:47
    N: Wow. So, real stuff!
    M: So when we started this I thought well
  • 26:47 - 26:51
    semiconductor the it way gets made: there
    is a big machine you put in a piece of
  • 26:51 - 26:58
    silicon and you go like this, and chunk,
    and outcomes of microprocessor. And it
  • 26:58 - 27:03
    doesn't doesn't really work that way. One
    of the reasons is just that the modern
  • 27:03 - 27:07
    chip consists of many layers. Another one
    is that there's just many different
  • 27:07 - 27:12
    production steps that are necessary for
    making even a single layer. And some of
  • 27:12 - 27:14
    the machines that make a layer are so
    expensive that you can't just make an
  • 27:14 - 27:20
    assembly line. And also a lot of things
    break all the time in a semiconductor
  • 27:20 - 27:24
    factory. So it makes no sense to just have
    an assembly line and push things through
  • 27:24 - 27:28
    that. But things just move around among
    the different machines in the
  • 27:28 - 27:32
    semiconductor factory. Right. And so
    what's important is that each chip undergoes
  • 27:32 - 27:37
    or each wafer undergoes a sequence of
    steps in the factory and that needs to be
  • 27:37 - 27:41
    managed. And those steps it's typically
    for big microprocessors that might be
  • 27:41 - 27:46
    like a thousand steps. So you need to
    manage something that's that's called a
  • 27:46 - 27:50
    route which is just a sequence of
    operations. And now here's a bunch of
  • 27:50 - 27:54
    Haskell code. Haskell is great because the
    programs are so short that they fit on
  • 27:54 - 27:59
    slides but if there's something unclear
    about that code then I invite you to
  • 27:59 - 28:04
    interrupt me and ask. So first of all you
    can read that declaration at the beginning
  • 28:04 - 28:11
    says "data Operation" and that's just a
    simplified data type that describes what
  • 28:11 - 28:16
    an operation would be. You can read that
    vertical bar as "OR". So it says an
  • 28:16 - 28:21
    operation is either TrackIn or Process or
    TrackOut. TrackIn it just means putting a
  • 28:21 - 28:27
    wafer into a machine and Process is you do
    something inside the machine and TrackOut
  • 28:27 - 28:32
    is you take it out of the machine. And
    then the next thing is that the route is
  • 28:32 - 28:37
    just a sequence of operations and these
    brackets that you see there they mean list
  • 28:37 - 28:43
    of. So what it says is a route is a list
    of operations. And down here you have an
  • 28:43 - 28:49
    example for a very simple route that says
    well route number one might be a list of
  • 28:49 - 28:53
    the following operations. You put a wafer
    into a machine, you process it, you
  • 28:53 - 29:00
    process it some more, and then you take it
    out again. Clear so far? Everybody nod!
  • 29:00 - 29:04
    Everybody who's still awake nod!
    N: laughter
  • 29:04 - 29:10
    M: Don't be afraid to ask. So one thing
    that you do is is when you have data
  • 29:10 - 29:15
    types, as you just saw, is you define
    functions on them that describe some
  • 29:15 - 29:20
    aspect of what happens in a fab, in a
    semiconductor factory. So in fact what
  • 29:20 - 29:25
    happens of course is you need to execute
    the next step, the next operation. That
  • 29:25 - 29:28
    happens as part of making a semiconductor
    and for that we're making a function
  • 29:28 - 29:33
    called routeHead - the head of the route.
    And what you do is you write a type
  • 29:33 - 29:38
    signatures and type signatures are very
    good for communication actually. So you
  • 29:38 - 29:43
    put in a route and you get out a single
    operation and then you write equations
  • 29:43 - 29:48
    that describe what that function would do
    on different aspects or different classes
  • 29:48 - 29:55
    of input. So in this case you remember a
    route was a list of operations. There are
  • 29:55 - 29:58
    two different kinds of lists. One type of
    list is the empty list and the other kind
  • 29:58 - 30:03
    of list is a list that has what's called a
    head or first element and a rest. And
  • 30:03 - 30:07
    because there's two kinds of lists you
    write two equations. And so that's why you
  • 30:07 - 30:14
    see two things where it says routeHead
    something equals to something else. The
  • 30:14 - 30:18
    first equation is for the empty list. This
    is why you have these two empty brackets.
  • 30:18 - 30:21
    And the second one that says well it's a
    non empty list and the first thing in that
  • 30:21 - 30:26
    list is some operation ops or there's
    something called pattern matching you
  • 30:26 - 30:31
    match this onto the actual list that you
    see and often gets bound to that first
  • 30:31 - 30:34
    operation. We're not we don't really care
    about what comes after that first
  • 30:34 - 30:38
    operation. And so the second equation is
    pretty clear if you want the head of a
  • 30:38 - 30:46
    route that is not empty you just take the
    first element of that list. OK so far? The
  • 30:46 - 30:50
    other equation says: what do we do with an
    empty list? An empty list does not have an
  • 30:50 - 30:53
    operation.
    N: So you're saying you're into the second
  • 30:53 - 30:58
    slide of your beautiful Haskell code and
    you already don't know what to write
  • 30:58 - 31:02
    there.
    M: So we're re communicating right.
  • 31:02 - 31:08
    N: OK. OK. So
    M: So you're talking to some expert and
  • 31:08 - 31:10
    you say: You have got an empty route.
    What's the first operation of an empty
  • 31:10 - 31:15
    route? And he says: Well, empty routes they
    don't really have a first operation. They
  • 31:15 - 31:19
    only maybe have an operation, and
    sometimes they don't. So for that we can
  • 31:19 - 31:23
    create a data type that says that
    something might be there and sometimes
  • 31:23 - 31:27
    it's not. And we'll just call it "Option".
    Are there any Haskell programmers in this
  • 31:27 - 31:33
    room? This is built in of course as the
    "maybe" type but I'm just making a
  • 31:33 - 31:37
    separate type called the "Option" type and
    that says: The a says this can be
  • 31:37 - 31:43
    anything. Anything in option a means it
    can either be there or not. And for that
  • 31:43 - 31:47
    it has two constructors or two different
    classes of Maybe objects and one are
  • 31:47 - 31:51
    called the Some objects and the other ones
    are called the None objects. Maybe we'll
  • 31:51 - 31:55
    start with None. So Anything can be a
    None. It just says that anything is not
  • 31:55 - 32:00
    there. So anything can be of type option
    of a. And it means that something is not
  • 32:00 - 32:04
    there and that is the type of that
    particular constructor. The other
  • 32:04 - 32:07
    constructor says while that thing actually
    is there and so the constructor has to
  • 32:07 - 32:12
    accept something of type A and then give
    us something of type Option of a.
  • 32:12 - 32:20
    N: So you're saying it wraps this object?
    M: Yes it wraps the object. Okay. And so
  • 32:20 - 32:25
    if you're not a Hasekell programmer but
    maybe maybe an F sharp programmer or an ML
  • 32:25 - 32:29
    programmer then that is what it looks like
    there. And I believe it's even built into
  • 32:29 - 32:36
    Java these days something called Optional.
    So now that means we can change our
  • 32:36 - 32:40
    routeHead functional a little bit because
    our first attempt didn't work out and
  • 32:40 - 32:46
    instead of saying Route --> Operation we
    write Route --> Option Operation. This may
  • 32:46 - 32:49
    seem trivial to you but it already
    communicates a tiny little bit of
  • 32:49 - 32:55
    something. Then we can write routeHead of
    the empty list is None. So there's no
  • 32:55 - 33:01
    routeHead of the empty route. or if we
    have an Operation coming out we just write
  • 33:01 - 33:05
    Some in front. And so if we use that
    example the route that you saw earlier
  • 33:05 - 33:11
    where our route was "TrackIn, Process,
    Process, TrackOut" what we get is "Some
  • 33:11 - 33:19
    TrackIn" so that type communicates a
    little bit of what we do. Because always
  • 33:19 - 33:22
    are you calling the shots. Very good. The
    next thing that we might want to do is we
  • 33:22 - 33:26
    don't want to always know only the first
    operation. We also want to know what
  • 33:26 - 33:31
    happens after that. So we can use that
    Option and we already know all that. Of
  • 33:31 - 33:33
    course. An empty route will not have
    something coming after that first
  • 33:33 - 33:37
    operation. So we could write another
    function called routeAdvance and it takes
  • 33:37 - 33:43
    a route as input. That's to the left of
    the arrow. It gives us both an operation
  • 33:43 - 33:47
    and a route. That's why there's these two
    things in parentheses with a comma in
  • 33:47 - 33:51
    between. So that's a tuple. So it gives us
    an operation and a route but only
  • 33:51 - 33:56
    sometimes when that actually exists which
    is why there's an option wrapped around
  • 33:56 - 34:00
    that. So what we want to do is if we take
    our Route Number one we want to split it
  • 34:00 - 34:03
    into that first operation and a list of
    the rest so it should split out the
  • 34:03 - 34:08
    TrackIn and then give us a list of the
    remaining or a route of the remaining
  • 34:08 - 34:14
    operations that are in there. OK so far?
    It gets technical. Does anybody have a
  • 34:14 - 34:23
    question? OK. Don't hesitate to ask. I'm
    looking at the clock. So then this is
  • 34:23 - 34:27
    actually pretty easy to write now. Again
    we need to make two equations because a
  • 34:27 - 34:32
    Route is a list and lists always need two
    equations. So we can say routeAdvance of
  • 34:32 - 34:37
    the empty list is None. And routeAdvance
    of op and the rest is we just return a Sum
  • 34:37 - 34:42
    of the rest because the list already
    splits exactly along the line that we
  • 34:42 - 34:47
    wanted to between the first and the
    remaining elements. Right. So this is just
  • 34:47 - 34:51
    very simple code or at least it's short
    code that communicates what routes are.
  • 34:51 - 34:58
    N: right, I see. If I remember correctly.
    I mean you said you put the wafer into the
  • 34:58 - 35:03
    machine and then it processes it. If I
    remember correctly some of these
  • 35:03 - 35:09
    processing steps can be chemical
    reactions. And so it might be the case
  • 35:09 - 35:14
    that they must happen in a certain amount
    of time or something?
  • 35:14 - 35:18
    M: Yeah.
    N: Okay. So what we could actually do is
  • 35:18 - 35:24
    we could model something like this. Yeah.
    I sneaked at your part of the slide so I
  • 35:24 - 35:29
    checked this in. Oh yeah. So what we
    actually could do is we could model
  • 35:29 - 35:36
    something like those three steps here need
    to happen together in a set period of
  • 35:36 - 35:40
    time.
    M: Yeah. So yeah. So the chemical
  • 35:40 - 35:43
    reactions mean that your wafer might go
    bad. If you start the sequence of steps
  • 35:43 - 35:45
    and you don't finish on time then your
    wafer goes bad.
  • 35:45 - 35:50
    N: like etching and washing, for example
    if you etch too much, then...
  • 35:50 - 35:54
    M: That's always a problem in existing
    systems, to model that.
  • 35:54 - 36:00
    N: Okay. Right. Oh so cool. So maybe I can
    try and see how I can model this into your
  • 36:00 - 36:02
    existing code.
    M: Okay
  • 36:02 - 36:08
    N: cool. So let's have a look. So what we
    first need as we we have this Route
  • 36:08 - 36:14
    element here with this Operation right.
    And now we need another representation for
  • 36:14 - 36:22
    a Route element and let's call this
    RouteQTZone for queue time zone. And there
  • 36:22 - 36:27
    of course we have the duration. That means
    the amount of time this step needs to be
  • 36:27 - 36:32
    finished in, or this sequence of steps
    needs to be finished in. And then we have
  • 36:32 - 36:38
    this list of Operations here. We saw this
    before. Right. The list of the Operations.
  • 36:38 - 36:43
    And then what this gives us is of course
    again a routeElement. So we can combine
  • 36:43 - 36:49
    like ordinary steps like putting the wafer
    into the machine, doesn't matter how long
  • 36:49 - 36:54
    it takes, maybe it blocks the machine but
    other than that no. No issues come from
  • 36:54 - 36:59
    that. But if we do with the etching and
    the washing for example we would need to
  • 36:59 - 37:05
    have a queue time zone because we need to
    restrict the time that this takes in
  • 37:05 - 37:08
    conjunction. Right. Is that correct so
    far?
  • 37:08 - 37:11
    M: Yeah.
    N: Good. And then if we look at our
  • 37:11 - 37:19
    example this is the previous example we
    had here. We could create another example
  • 37:19 - 37:28
    r2. Here we have a routeQTZone. Say it may
    only take five whatever seconds say and
  • 37:28 - 37:34
    then we have two processes here that need
    to be finished within five seconds and
  • 37:34 - 37:49
    then we do the TrackOut again. OK. So far
    so clear? Good. If we look at this and we
  • 37:49 - 37:53
    discover that here we have this
    routeElement list. And here we have this
  • 37:53 - 38:02
    Operation list. This is actually sort of
    similar isn't it. So maybe we can make
  • 38:02 - 38:07
    something out of this and maybe we can
    actually turn this down here into
  • 38:07 - 38:11
    routeElements as well.
    M: Oh so that's what you were doing
  • 38:11 - 38:14
    before, right. Before up there it also
    said list of Operation.
  • 38:14 - 38:21
    N: Up there?
    M: When you started.... My code had Route
  • 38:21 - 38:25
    = [Operation]. Right. And now you did the
    same thing.
  • 38:25 - 38:33
    N: Oh yes. Yeah. Right. So now it's now
    it's the same. Again. So it's both [RouteElements ].
  • 38:33 - 38:40
    Yeah. Good point. So now if we look at this again
    so maybe this actually means that this
  • 38:40 - 38:52
    here is not just a list of routeElements
    but maybe this is actually a route down
  • 38:52 - 39:00
    there. So I actually derive some
    information here from the code so we
  • 39:00 - 39:04
    discover that our routeQTZone actually
    contains a Route.
  • 39:04 - 39:13
    M: Oh all right.
    N: So if we look at this here. What we
  • 39:13 - 39:22
    then can do here with this RouteElement.
    So here we could plug in any RouteElement
  • 39:22 - 39:30
    right? For example we could plug in a
    RouteQTZone which is also a RouteElement.
  • 39:30 - 39:36
    So coming from this example here where we
    have just a flat list that does contain
  • 39:36 - 39:45
    some RouteOperations and a RouteQTZone and
    then a RouteOperation we could also stack
  • 39:45 - 39:52
    them into each other. So a RouteQTZone
    could again contain a route that contains
  • 39:52 - 39:55
    a RouteQTZone.
    M: That's pretty cool.
  • 39:55 - 39:58
    N: Do you think that would happen.
    M: Yeah. That's pretty cool because now we
  • 39:58 - 40:01
    can nest RouteQTZones and that's something
    that occurs in reality.
  • 40:01 - 40:04
    N: Oh really does it? Cool.
    M: And so your model has suggested that
  • 40:04 - 40:08
    but it is something that our old IT
    systems based on Object Oriented
  • 40:08 - 40:11
    Programming couldn't model. That's
    pretty neat.
  • 40:11 - 40:16
    N: So now I understand why you're aiming
    at functional programing and saying that
  • 40:16 - 40:19
    you can model things better with it.
    M: Exactly.
  • 40:19 - 40:23
    N: Yeah. This is pretty cool. So we
    discovered this in the code and then we
  • 40:23 - 40:30
    were able to get back to the business
    people and check back with them whether
  • 40:30 - 40:35
    they would actually see this in practice
    and whether it's a valuable addition here
  • 40:35 - 40:43
    and we discovered that just from looking
    at the type information we had. Yeah and
  • 40:43 - 40:48
    then we can continue this and because now
    we have this list of RouteElements down
  • 40:48 - 40:53
    there. We could actually say Oh yeah list
    of RouteElements, we know what that is:
  • 40:53 - 41:03
    This is actually a route. And now we go
    one level up. So whenever we learn more
  • 41:03 - 41:09
    about Routes or whenever we change this
    here this Route thing it will
  • 41:09 - 41:18
    automatically be reflected in here because
    we abstracted it. Right. And that's what
  • 41:18 - 41:22
    functional programming is all about
    abstracting things and figuring out what
  • 41:22 - 41:28
    the common parts are. Right?
    M: I notice you're agreeing with me. Very
  • 41:28 - 41:32
    good.
    N: Excellent. So and now we can also of
  • 41:32 - 41:40
    course check how our functions will be
    modified because now we need to go to
  • 41:40 - 41:48
    all of our functions and see whether they
    still work. And here we have this
  • 41:48 - 41:53
    routeHead and also routeElementHead. And
    now we need to extend this because the
  • 41:53 - 41:57
    routeElementHead works on the
    routeElement. And now we have a new
  • 41:57 - 42:02
    routeElement which is the RouteQTZone. And
    of course if we want the routeElementHead
  • 42:02 - 42:10
    of the RouteQTZone this is of course the
    head of the containing route. And we have
  • 42:10 - 42:14
    this neat function up here already,
    routeHead, which gives us the head of the
  • 42:14 - 42:21
    route. And so we can just reuse this here.
    So even this has become simpler for us to
  • 42:21 - 42:27
    implement, because we have discovered that
    there is a route in there instead of just
  • 42:27 - 42:33
    a list. So no special handling we can just
    revert to the standard function we already
  • 42:33 - 42:41
    have. And if we look at the routeAdvance
    so if we want to proceed our route to the
  • 42:41 - 42:49
    next operation and you know proceed to the
    next step then of course we also need to
  • 42:49 - 42:58
    add this here the RouteQTZone and now the
    question is what happens if we advance
  • 42:58 - 43:05
    into a RouteQTZone process because somehow
    we need to keep track of when does it need
  • 43:05 - 43:15
    to be finished. So we initially we said OK
    it may only take like x time or d time and
  • 43:15 - 43:22
    now we need to keep track of whether this
    time is already taken up or not. And so in
  • 43:22 - 43:33
    this case what we actually do is we need
    to add another RouteElement and that's the
  • 43:33 - 43:41
    RouteQTLimit which defines when a started
    operation needs to be finished. So it has
  • 43:41 - 43:47
    an actual time which is the point in time
    like no duration or something just the
  • 43:47 - 43:53
    finishing point in time and then it's just
    the same as the RouteQTZone. So this
  • 43:53 - 44:01
    limits our process up to this end point of
    time. And now we can implement our
  • 44:01 - 44:06
    routeAdvance because whenever we have a
    QTZone that's where we didn't know what to
  • 44:06 - 44:14
    write before. So whenever we advance this
    route then we know that we need to come up
  • 44:14 - 44:24
    with a RouteQTLimit here and whenever we
    have this RouteQTLimit and we advance over
  • 44:24 - 44:30
    that one then we know that we just need to
    basically behave like before, we need to
  • 44:30 - 44:38
    split this up and also keep our time limit
    of course. And then just proceed into this
  • 44:38 - 44:45
    limited while while keeping the time
    limit. And here if we start this out then
  • 44:45 - 44:51
    we need to to determine the end point, so
    we take the current time which we now need
  • 44:51 - 44:57
    to pass in here at the top. So we take the
    current time add the duration and then we
  • 44:57 - 45:04
    know when we need to be finished with this
    process. And then in here yeah we just we
  • 45:04 - 45:09
    just work on every step while keeping
    the time limit.
  • 45:09 - 45:13
    M: So your code suggested that there was a
    gap in your understanding of what needs to
  • 45:13 - 45:18
    be represented right. Yeah.
    N: So I didn't know what to put to the -
  • 45:18 - 45:24
    what to implement for the routeAdvance.
    Yeah. And now I know that. Yeah. I can
  • 45:24 - 45:26
    handle this.
    M: So watching this I'm thinking that
  • 45:26 - 45:31
    there's still a little, if I look at it
    with the eye of a domain person, I think
  • 45:31 - 45:34
    there's still a little problem in there.
    N: Oh. Is it?
  • 45:34 - 45:37
    M: Yeah. If you look at this right
    remember a RouteElement is something that
  • 45:37 - 45:42
    can occur anywhere in the middle beginning
    at the end of a route so it's these three
  • 45:42 - 45:45
    things. Obviously we can have RouteQTZones
    anywhere we can have operations anywhere
  • 45:45 - 45:49
    but the thing is we can only enter a
    RouteQTZone when it's at the beginning.
  • 45:49 - 45:51
    Right?
    N: Oh I see.
  • 45:51 - 45:54
    M: So now.
    N: You mean here we could have a random
  • 45:54 - 45:58
    list in a random order.
    M: Yeah. That's right.
  • 45:58 - 46:00
    N: That's a good point.
    M: So you can't... So this suggests that
  • 46:00 - 46:04
    the RouteQTZone has been entered because
    there is a RouteQTLimit. But there is even
  • 46:04 - 46:06
    - there there's still an operation there
    in front of it.
  • 46:06 - 46:12
    N: Okay. Yeah. That doesn't make sense.
    M: Yeah. That that makes no sense. So if
  • 46:12 - 46:15
    we could go back from the domain knowledge
    to the code now a little bit we could
  • 46:15 - 46:21
    refine that type further and we could pull
    out the RouteQTLimit from that type down
  • 46:21 - 46:25
    there, because these are all the things
    that occur in the middle of a route and
  • 46:25 - 46:28
    pull it up to a top level type and
    introduce an intermediate type
  • 46:28 - 46:32
    that distinguishes between what's in the
    middle and what's at the beginning.
  • 46:32 - 46:37
    N: Oh I see. That's neat.
    M: So what have as we have this back and
  • 46:37 - 46:42
    forth between the code which yields
    insights about the domain and the domain
  • 46:42 - 46:45
    from the domain back to the code and we
    can play that game we can use the code for
  • 46:45 - 46:50
    communication.
    N: Yeah. So that's what I intended. Did
  • 46:50 - 46:53
    you understand this?
    M: Yeah so that code no longer crushes my
  • 46:53 - 46:55
    soul.
    N: Excellent.
  • 46:55 - 46:57
    M: So I can say Yeah right.
    N: Same here.
  • 46:57 - 46:59
    M: So.
    N: Cool.
  • 46:59 - 47:02
    M: Okay.
    N: So that's what the point we wanted to
  • 47:02 - 47:08
    make. So if you take functional
    programming and if you add communication
  • 47:08 - 47:13
    and discussions and this going back and
    forth and learning from both sides and
  • 47:13 - 47:20
    enriching both sides with the information
    coming from the other part then you
  • 47:20 - 47:25
    actually end up at a silver bullet.
    M: Everybody's looking confused that's a
  • 47:25 - 47:32
    bullet train, a silver bullet train. OK
    we're done.
  • 47:32 - 47:37
    N: Yes thank you.
    Herald:
  • 47:37 - 47:45
    So thank you for a very entertaining talk
    we have some time for questions, Q&A, so if
  • 47:45 - 47:50
    you have any questions please line up next
    to the microphones. We have four
  • 47:50 - 47:52
    microphones spread across the room and
    we'll start from a question from the
  • 47:52 - 48:01
    Internet.
    Signal Angel: There is a question from the
  • 48:01 - 48:09
    internet: As an FP beginner with a weak
    background in math would it be preferable
  • 48:09 - 48:13
    to learn functional programming in a pure
    functional language or in languages that
  • 48:13 - 48:24
    are multi paradigm?
    M: I'll take that one? OK. So I think the
  • 48:24 - 48:27
    point is that there is many different
    functional programming languages and
  • 48:27 - 48:32
    Haskell happens to be what's called a pure
    one but there are also languages that are
  • 48:32 - 48:36
    hybrid between object oriented and
    functional programming. Scala I think is a
  • 48:36 - 48:42
    prime example right now. And I mean Scala
    is a fine language. The problem is if you
  • 48:42 - 48:45
    want to combine these two paradigms you
    typically get something that's pretty
  • 48:45 - 48:51
    complicated. So Scala is a complicated
    language that takes more time to master.
  • 48:51 - 48:59
    Also, because you have both paradigms
    available to you at all times. It is
  • 48:59 - 49:03
    sometimes... You often get confused about
    what paradigm you should use in a given
  • 49:03 - 49:08
    situation. So I think both of us we
    haven't really seen the great advantages
  • 49:08 - 49:12
    you get from that hybrid model. Right?
    N : Yes. Also the problem is if you're a
  • 49:12 - 49:17
    learner in FP and you try to tackle this
    with something like Scala you will
  • 49:17 - 49:23
    inevitably fall back to what you know if
    you run into problems. And so maybe just
  • 49:23 - 49:29
    jump into the deep end and try to swim and
    see where you get and get help on the
  • 49:29 - 49:33
    Internet.
    Herald: Number two.
  • 49:33 - 49:43
    Mic2: It was a good presentation. Thank
    you. Every time I see some functional
  • 49:43 - 49:49
    programming it's refreshing and it's
    interesting but the description of your
  • 49:49 - 49:55
    presentation was talking about using
    functional programming in IOT. So there
  • 49:55 - 50:00
    was nothing specific to IOT in this
    presentation. There was no interaction
  • 50:00 - 50:07
    with the hardware. No interrupt handling.
    No nothing. How would you handle that for
  • 50:07 - 50:10
    example.
    M : Yeah good point. I think we had a
  • 50:10 - 50:17
    bunch of slides on that that we ended up
    dropping because of time. So my argument
  • 50:17 - 50:24
    would be that IOT is the same software as
    any other software. What's special about
  • 50:24 - 50:33
    IOT is the risk that emanates from IOT
    obviously. So if you want to do things
  • 50:33 - 50:38
    like interrupt handling I think my
    response to that would be to convert it
  • 50:38 - 50:42
    into functional data structures and this
    gives you a deterministic model for
  • 50:42 - 50:47
    handling that kind of stuff. So we talked
    about that. I think we talked a little bit
  • 50:47 - 50:50
    about the observer pattern which is
    analogous to what usually happens with
  • 50:50 - 50:54
    interrupt handling which is what you were
    talking about. And the way to do that
  • 50:54 - 50:57
    really is to have... of course you have a
    tiny bit of imperative code that hooks
  • 50:57 - 51:02
    your functional code to the hardware or
    whatever it is. But to convert your
  • 51:02 - 51:06
    interrupts into a list and you can...
    Haskell actually is pretty good at that
  • 51:06 - 51:09
    and that then gives you all the advantages
    of functional programming: the testability,
  • 51:09 - 51:14
    the funky abstractions. And you
    can use that even on the interrupts and it
  • 51:14 - 51:18
    turns into software just like any other
    functional software.
  • 51:18 - 51:24
    Herald: Microphone number one.
    Mic1: Hi. Thank you for the talk. I have
  • 51:24 - 51:30
    to write code for microprocessors and most
    of the time I only have a C compiler and
  • 51:30 - 51:37
    if I'm lucky I get a C++ compiler. Where
    can I get a silver bullet?
  • 51:37 - 51:41
    laughter
    N: The old Haskell compiler used to
  • 51:41 - 51:48
    compile to C and nowadays it doesn't do
    that anymore by default but probably you
  • 51:48 - 51:53
    can make it do that still?
    M: But there's a number functional
  • 51:53 - 51:58
    languages that compile to C so it's kind
    of difficult to give a one shot answer.
  • 51:58 - 52:02
    We've also done a project for example
    where we got a lot of the advantages from
  • 52:02 - 52:09
    functional programming by writing code in
    Haskell that generates the C code, right.
  • 52:09 - 52:14
    And so it's difficult to give you like one
    answer without knowing more details about
  • 52:14 - 52:18
    what it is that you're doing but there's
    certainly a spectrum of options available
  • 52:18 - 52:25
    in that context.
    Q: So functional programming is pretty
  • 52:25 - 52:32
    concise and pretty compact so no one
    really wants to use large variable names
  • 52:32 - 52:39
    and I saw in your examples like a D and a
    TTL, RTs. And I don't think that there are
  • 52:39 - 52:44
    so much better than the long versions you
    showed earlier. Like what is yout take on
  • 52:44 - 52:49
    that?
    N: So the general - I'm also struggling a
  • 52:49 - 52:57
    little bit with this. One thing is that
    this was fairly concrete code, right? But
  • 52:57 - 53:05
    often you go into the abstractions and in
    the abstraction there it's arbitrary what
  • 53:05 - 53:11
    you have. So you can use short names
    because you're not talking about concrete
  • 53:11 - 53:18
    things anyway. So that's why it's easier
    to use - also more like abstract variable
  • 53:18 - 53:24
    names. But what I actually do is I also
    use longer names so I would not always use
  • 53:24 - 53:30
    D and RT and something like that to get a
    better grip on this. But one important
  • 53:30 - 53:35
    thing you must not forget is that this you
    have a function, right, and it's two
  • 53:35 - 53:41
    lines, three lines. And so if you start
    out and you understand D and RT, for
  • 53:41 - 53:47
    example, from the signature and reading
    three lines of code with a D and RT in it
  • 53:47 - 53:52
    it's not that bad right? And in object
    oriented or Java or whatever you sometimes
  • 53:52 - 53:56
    have hundreds of lines and then you have a
    D and RT and you read this for half an
  • 53:56 - 54:03
    hour and then of course you forget what it
    means. And so, you know, it's a bit of a
  • 54:03 - 54:08
    balance. So I would use longer names as
    well probably but sometimes also shorter
  • 54:08 - 54:14
    because, just the code is so short.
    M: Like if I can add one detail as I find
  • 54:14 - 54:18
    myself using longer names in dynamically
    typed languages right there dynamically
  • 54:18 - 54:22
    typed functional languages. There you don't have the
    type that spells out what that thing is.
  • 54:22 - 54:24
    N: Oh right.
    M: And then you need to put it in the
  • 54:24 - 54:26
    variable name.
    Herald: Microphone number 1.
  • 54:26 - 54:30
    M1: Yeah. In one of the slides you made
    the claim that a functional programming
  • 54:30 - 54:34
    lends itself to proving. How would you
    actually do this?
  • 54:34 - 54:38
    M: Good question. So
    N: That's another talk right?
  • 54:38 - 54:43
    M: I mean in practice, so there's various
    ways of doing that. So first of all as you
  • 54:43 - 54:48
    saw, right, a Haskell program is a bunch
    of equations so you can use algebra as a
  • 54:48 - 54:53
    mathematical technique to reason about
    functional programs. First of all, going
  • 54:53 - 54:58
    to the abstract aspect of that question
    which is something, well, you can sort of
  • 54:58 - 55:02
    do it with your Java program but it is
    much harder to establish an algebraic way
  • 55:02 - 55:08
    of talking about Java programs. There's
    also plenty of tooling available to write
  • 55:08 - 55:12
    to prove aspects of your programs in
    functional languages, starting with a
  • 55:12 - 55:17
    classic tool called ACL2. We can talk on
    something called Idris, so there is a
  • 55:17 - 55:21
    newer breed of functional languages where
    you can put more proofs into the types of
  • 55:21 - 55:27
    your languages. So it just turn, it turns
    out it tends to be just a magnitude of an
  • 55:27 - 55:31
    order of magnitude easier to prove
    properties of functional programming
  • 55:31 - 55:36
    because you can use algebra and equational
    reasoning as you would about Java
  • 55:36 - 55:38
    programs. Does that answer your question a
    little bit?
  • 55:38 - 55:45
    M1: A bit. But I think Idris uses like
    dependent types and doesn't - isn't it
  • 55:45 - 55:50
    possible to use it in imperative
    programming as well? Maybe? I don't know.
  • 55:50 - 55:56
    So is that specific to functional
    programming dependent types? Or could it
  • 55:56 - 55:59
    be used...
    M: It is even the way that it just talks
  • 55:59 - 56:04
    about imperative programming is
    functional. Right? Using monads, by the
  • 56:04 - 56:11
    way. So there is that and there's this
    whole spiel about reasoning about effects.
  • 56:11 - 56:14
    But the thing is effects side effects said
    you have an imperative programming right?
  • 56:14 - 56:17
    They don't make it impossible to reason
    about programs but they make it much much
  • 56:17 - 56:22
    harder. And so in a functional program you
    tend, in a proper functional program that
  • 56:22 - 56:26
    doesn't crush your soul, you tend to have
    large parts that are purely functional and
  • 56:26 - 56:30
    that allow functional that allow
    equational reasoning and you have smaller
  • 56:30 - 56:34
    parts that maybe make - that might be a
    little bit more difficult that are about
  • 56:34 - 56:37
    the interaction with the imperative
    environment.
  • 56:37 - 56:44
    N: Also the thing that we did with the
    type system you know you remember? First
  • 56:44 - 56:49
    we have the list and we have the the RT,
    the queue time limit, in the middle and
  • 56:49 - 56:55
    that was an illegal state. And so we
    changed the type system to disallow this.
  • 56:55 - 57:00
    And so actually already the compiler tells
    us: "Hey this is forbidden code." Right?
  • 57:00 - 57:06
    And it's not syntactically wrong but it's
    semantically wrong. And that's what is
  • 57:06 - 57:13
    also like a weak kind of validation or
    verification in my opinion.
  • 57:13 - 57:18
    M: So we could talk all about all this
    about this all day. Sorry.
  • 57:18 - 57:20
    Herald: Another question from Microphone
    number 2.
  • 57:20 - 57:27
    M2: I noticed that you didn't present any
    mechanism to hide your implementation or
  • 57:27 - 57:33
    to make things private - the things that
    you can do in C++. And I don't miss this
  • 57:33 - 57:39
    mechanism but I would like to know your
    take on why - I think you don't miss them.
  • 57:39 - 57:42
    So why you don't miss them either?
    M: No they exist in functional languages
  • 57:42 - 57:47
    as well. Right? And so the mechanisms that
    you're familiar with private things,
  • 57:47 - 57:51
    modules. Functional languages tend to not
    use objects and classes for
  • 57:51 - 57:55
    modularisation. I think that's the primary
    difference but functional languages tend
  • 57:55 - 57:59
    to always have mechanisms for doing that.
    They're just different between languages.
  • 57:59 - 58:02
    So it's difficult to talk about this in a
    talk. We could have told you how to do
  • 58:02 - 58:09
    this in Haskell and write a module on hide
    things. But would have put more code on
  • 58:09 - 58:12
    the slides.
    N: And the other aspect is that you don't
  • 58:12 - 58:16
    really have to hide things because
    everything is pure. So if you call this
  • 58:16 - 58:23
    function - I don't care, you know. You
    can't destroy anything. Whereas in an
  • 58:23 - 58:28
    object oriented programming you have this
    - change my object to really bad
  • 58:28 - 58:32
    something you know and you don't want
    anybody else to call this because it will
  • 58:32 - 58:36
    really break things and then functional
    programming - chucking some variables get
  • 58:36 - 58:42
    something out - do this as much as you
    want. I don't care. That last one is the
  • 58:42 - 58:48
    take I love. And I endorse fully.
    Herald: Mic for number 3.
  • 58:48 - 58:53
    M3: You had some slides on the importance
    of communication. I have a hard time to
  • 58:53 - 58:57
    see myself communicating with business
    people using Haskell code. How do you what
  • 58:57 - 59:03
    do you laughter do about that at this
    point? How would you do the communication
  • 59:03 - 59:10
    with like normal people?
    M: I mean we clean it up somewhat. But
  • 59:10 - 59:17
    this actually happened. So it's sometimes
    a little bit of a process to get there and
  • 59:17 - 59:21
    sometimes... but what you could, I mean,
    what you noticed maybe in the code with
  • 59:21 - 59:28
    the routes was that playing with a Haskell
    code yielded domain insights that you
  • 59:28 - 59:32
    could have also explained to somebody in a
    meeting, right?
  • 59:32 - 59:36
    N: Without showing the code.
    M: Yeah. And so that's - so the
  • 59:36 - 59:39
    communication goes through the Haskell
    code, maybe not. It doesn't happen, you
  • 59:39 - 59:46
    know, by the Haskell code. But all I can
    tell you is that that actually happens is
  • 59:46 - 59:51
    we sometimes communicate with clients
    showing them code and talking to them
  • 59:51 - 59:55
    about, is this really what you're doing is
    this what your domain is like. That
  • 59:55 - 59:58
    happens.
    N: Happened to me as well. So it depends
  • 59:58 - 60:02
    on your clients you know. They need to
    have a bit of resilience so they can, you
  • 60:02 - 60:09
    know, and they can accept that they
    wouldn't understand everything. But if
  • 60:09 - 60:12
    you, like, talk them through and say look
    here's this and this goes in and that
  • 60:12 - 60:17
    comes out and what do you think about
    this. And then say - so you just not throw
  • 60:17 - 60:22
    the code at them but you have a informed
    communication to say.
  • 60:22 - 60:25
    M: This can also be contractually
    enforced. And I remember one instance
  • 60:25 - 60:28
    where we did that.
    Herald: That actually finished the
  • 60:28 - 60:31
    questions. Again got a big round of
    applause for this.
  • 60:31 - 60:33
    M: Thank you.
  • 60:33 - 60:34
    applause
  • 60:34 - 60:39
    35c3 postroll music
  • 60:39 - 60:52
    Subtitles created by c3subtitles.de
    in the year 2020. Join, and help us!
Title:
35C3 - A farewell to soul-crushing code
Description:

more » « less
Video Language:
English
Duration:
01:00:57

English subtitles

Revisions