< Return to Video

RailsConf 2014 - Keynote: Writing Software by David Heinemeier Hansson

  • 0:19 - 0:20
    DAVID HEINEMEIER HANSSON: That any better?
  • 0:20 - 0:22
    Oh, there we go. Woo.
  • 0:22 - 0:27
    Software's hard, as you can see. Hardware,
    too.
  • 0:27 - 0:33
    So last year I had the personal pleasure of
  • 0:33 - 0:37
    celebrating ten years of working with Ruby
    and ten
  • 0:37 - 0:40
    years of working with Rails. But this year,
    I
  • 0:40 - 0:44
    have a much more interesting anniversary,
    which is ten
  • 0:44 - 0:48
    years of sharing Ruby on Rails with all of
  • 0:48 - 0:51
    you and everyone who's been using it over
    the
  • 0:51 - 0:55
    past decade.
  • 0:55 - 0:57
    The picture in the background is actually
    from almost
  • 0:57 - 0:59
    exactly this time, where I gave the very first
  • 0:59 - 1:04
    presentation on Ruby on Rails at a Danish
    university
  • 1:04 - 1:06
    ten years ago.
  • 1:06 - 1:08
    Ten years ago, I had to talk a lot
  • 1:08 - 1:12
    about what is MVC, for example. Today, not
    so
  • 1:12 - 1:14
    much. There's a lot of things that over the
  • 1:14 - 1:18
    past ten years, things we were worried about
    in
  • 1:18 - 1:21
    the beginning, sort of leveling up as a community
  • 1:21 - 1:24
    and as, as programmers, that just aren't relevant
    anymore.
  • 1:24 - 1:25
    We're just taking all that stuff for granted.
  • 1:25 - 1:28
    Which is awesome. We get to care about a
  • 1:28 - 1:30
    lot of other stuff.
  • 1:30 - 1:32
    But as I look back over the past ten
  • 1:32 - 1:35
    years, which is pretty much the majority of
    my
  • 1:35 - 1:40
    adult life, I've been working on Ruby on Rails.
  • 1:40 - 1:43
    It's fun to look back even further. I think
  • 1:43 - 1:50
    there's a common misconception that anybody
    who ends up
  • 1:50 - 1:53
    creating something like Rails or
  • 1:53 - 1:55
    doing something else within
  • 1:55 - 1:57
    software development or computer science,
  • 1:57 - 1:57
    well, they must have
  • 1:57 - 2:01
    been programming since they were five years
    old, right.
  • 2:01 - 2:04
    The whole notion of a hacker is somebody who,
  • 2:04 - 2:08
    who sort of got their first computer twenty
    years
  • 2:08 - 2:12
    ago and was just programming the entire time.
    Well.
  • 2:12 - 2:13
    That wasn't me.
  • 2:13 - 2:16
    I did not learn to program when I was
  • 2:16 - 2:19
    five years old. I didn't learn to program
    until
  • 2:19 - 2:24
    I was closer to twenty. I'd been interested
    in
  • 2:24 - 2:26
    computers for a long time, but it wasn't really
  • 2:26 - 2:30
    until the late '90s, early 2000 that I dove
  • 2:30 - 2:33
    into computer programming as something that
    I was going
  • 2:33 - 2:33
    to do.
  • 2:33 - 2:34
    I had a lot of friends who were doing
  • 2:34 - 2:38
    it. I knew a lot of programmers. But somehow
  • 2:38 - 2:42
    it, it sort of never, never caught on. Before
  • 2:42 - 2:44
    I started writing software that I needed for
    myself,
  • 2:44 - 2:47
    and before I found sort of a place in
  • 2:47 - 2:50
    the software world for that to happen.
  • 2:50 - 2:53
    And the reason I, I say that is, is
  • 2:53 - 2:56
    I've seen a number of essays of like, what
  • 2:56 - 2:58
    is a true hacker, and, and as a true
  • 2:58 - 3:02
    hacker, one of the things that keeps being
    thrown
  • 3:02 - 3:04
    out is those ten years, right. You should
    have
  • 3:04 - 3:05
    been programming for ten years already,
  • 3:05 - 3:07
    otherwise you're way behind.
  • 3:07 - 3:12
    Well, I learned to program about three years
    before
  • 3:12 - 3:17
    I released Ruby on Rails. Turned out fine.
  • 3:17 - 3:23
    And I don't say that as, like, it was
  • 3:23 - 3:25
    because I grew up on a farm and didn't
  • 3:25 - 3:31
    know what a computer was. This is me in,
  • 3:31 - 3:34
    in the center there with the stick, and the
  • 3:34 - 3:39
    blue shirt in 1985. These are the kids that
  • 3:39 - 3:41
    were living in my neighborhood.
  • 3:41 - 3:44
    In 1985 I got introduced to my, my first
  • 3:44 - 3:50
    computer. And I was about five years old.
    And
  • 3:50 - 3:54
    I got introduced to computers through gaming.
    Sort of,
  • 3:54 - 3:57
    we were playing ninjas in the streets around
    our
  • 3:57 - 4:02
    houses, and then we'd play ninjas on the box.
  • 4:02 - 4:04
    And I found it fascinating right from the
    get
  • 4:04 - 4:06
    go, right. Computers were really
  • 4:06 - 4:08
    fascinating and games really
  • 4:08 - 4:12
    captured my imagination early on. I remember,
    at, at
  • 4:12 - 4:14
    that time, there were certain, lots of parents
    were
  • 4:14 - 4:16
    like, well make sure you get out and play
  • 4:16 - 4:18
    a lot. Because you don't want to spend your,
  • 4:18 - 4:19
    or wasting your time, that was the, that was
  • 4:19 - 4:22
    the word, wasting your time in front of computers
  • 4:22 - 4:23
    inside, right.
  • 4:23 - 4:26
    Well, I really did want to waste my time
  • 4:26 - 4:28
    in front of computers. And this was the computer
  • 4:28 - 4:34
    to have in 1985, in our neighborhood. But
    we
  • 4:34 - 4:36
    couldn't afford a computer like that. There
    was only
  • 4:36 - 4:38
    one guy in the whole neighborhood that had
    a
  • 4:38 - 4:39
    computer like that. So we all shared it and
  • 4:39 - 4:43
    we all played Yeah, Kung Fu, in turn.
  • 4:43 - 4:48
    But then the next year, so, I, I couldn't
  • 4:48 - 4:52
    afford this computer, but my dad somehow,
    he was
  • 4:52 - 4:57
    fixing TVs and stereos, he traded a stereo
    with
  • 4:57 - 5:00
    this guy for this other weird computer, which
    was
  • 5:00 - 5:04
    an Abstraught 646.
  • 5:04 - 5:06
    And I was really excited. It didn't actually
    play
  • 5:06 - 5:08
    Yeah, Kung Fu. I was a little disappointed
    by
  • 5:08 - 5:11
    that, but it had some other crappier games.
    Anyway,
  • 5:11 - 5:13
    it was a computer. And that was sort of
  • 5:13 - 5:15
    my first introduction to, to computers, six
    years old.
  • 5:15 - 5:18
    And, and I tried to learn programming.
  • 5:18 - 5:21
    I, I got a magazine and, at the back
  • 5:21 - 5:23
    of these magazines back then, there were programs
    you
  • 5:23 - 5:25
    could type in. And I was like, wow, this
  • 5:25 - 5:27
    is, this is amazing. I can control this computer.
  • 5:27 - 5:31
    So I built my first information technology
    system.
  • 5:31 - 5:37
    It was messages to my mom of where I
  • 5:37 - 5:38
    went, where, I had this clever system that
    would
  • 5:38 - 5:41
    really optimize the fact that writing a message
    of
  • 5:41 - 5:43
    where I went and, and when I was going
  • 5:43 - 5:45
    to be home, it was too complicated. It would
  • 5:45 - 5:47
    be much easier if I just wrote a little
  • 5:47 - 5:50
    note where I gave her the location on the
  • 5:50 - 5:52
    tape that she had to fast forward to, and
  • 5:52 - 5:54
    then she could read where I was.
  • 5:54 - 5:57
    I thought, man this is so clever. I just
  • 5:57 - 5:59
    have to write down two twenty-eight, and then
    I
  • 5:59 - 6:01
    could preprogram that note, and she'll never
    know I
  • 6:01 - 6:07
    was over at Peter's house playing Yeah, Kung
    Fu.
  • 6:07 - 6:10
    That really wasn't programming, right. I just
    typed some
  • 6:10 - 6:12
    stuff in. I didn't know what the hell I
  • 6:12 - 6:15
    was doing. I just somehow figured out print,
    OK,
  • 6:15 - 6:17
    that puts stuff up on the screen. That was,
  • 6:17 - 6:18
    that was the extent of it, right. But it
  • 6:18 - 6:21
    was my first stab at programming. And I, and
  • 6:21 - 6:23
    I, it kind of failed.
  • 6:23 - 6:25
    That was the extent of my programming, that
    I
  • 6:25 - 6:29
    knew how to fast-forward to a pre-recorded
    message.
  • 6:29 - 6:31
    Not that great.
  • 6:31 - 6:36
    So a couple years later, late 80s, I saw
  • 6:36 - 6:39
    this game for the first time. Battle Squadrant.
    And
  • 6:39 - 6:43
    I remember thinking, holy shit, these graphics
    are amazing.
  • 6:43 - 6:47
    How can they make this? This looks so good,
  • 6:47 - 6:51
    when you were used to a Commodore 64, the
  • 6:51 - 6:54
    graphics of the Amiga 500, which is mind blowing,
  • 6:54 - 6:57
    right. And once again, I felt this, like,
    wow,
  • 6:57 - 6:59
    wouldn't it be amazing to be part of that?
  • 6:59 - 7:01
    To be able to create something like that?
  • 7:01 - 7:03
    I'd love to make games.
  • 7:03 - 7:06
    So I sort of started looking around, and,
    and
  • 7:06 - 7:08
    I found this thing called Amus. I don't know,
  • 7:08 - 7:13
    has anybody here ever programmed in Amus?
    Not a
  • 7:13 - 7:16
    single hand. OK. Must have been a very European
  • 7:16 - 7:17
    thing.
  • 7:17 - 7:19
    But it was sort of a real programming environment,
  • 7:19 - 7:22
    and, and I got the box, and sort of
  • 7:22 - 7:24
    my English was a little, not that great, so
  • 7:24 - 7:26
    I was sort of just reading through it and
  • 7:26 - 7:27
    trying to find the code. And it was all
  • 7:27 - 7:31
    about sprites and vectors and ifs and variables,
    and
  • 7:31 - 7:33
    it, it didn't make any sense to me at
  • 7:33 - 7:33
    all.
  • 7:33 - 7:35
    So I thought, eh this is a little bit
  • 7:35 - 7:38
    too hard. Thankfully, there was something
    called Easy Amos,
  • 7:38 - 7:41
    right. Oh, wow, that's gonna be great. This
    other
  • 7:41 - 7:42
    one was too hard. Now I just have to
  • 7:42 - 7:43
    do the easy one.
  • 7:43 - 7:47
    Unfortunately, in Easy Amos, it was still
    programming, and
  • 7:47 - 7:49
    it still had conditionals and variables and
    all these
  • 7:49 - 7:52
    other things I just did not understand. I,
    it's
  • 7:52 - 7:55
    so funny, because, once you learn something,
    it can
  • 7:55 - 7:57
    sometimes be hard to go back and think, like,
  • 7:57 - 7:58
    how was it before I knew how to do
  • 7:58 - 8:02
    this? But I distinctly remember, why would
    you have
  • 8:02 - 8:03
    a variable?
  • 8:03 - 8:05
    Like, if you just assign something once, why
    would
  • 8:05 - 8:07
    you ever sort of want to change that? Why
  • 8:07 - 8:08
    does it have to be a space. Why can't
  • 8:08 - 8:10
    it just be the thing. Like, I did not
  • 8:10 - 8:12
    get the concept of variables.
  • 8:12 - 8:15
    And this is at, I don't know, age ten
  • 8:15 - 8:18
    or whatever. So, still not getting programming.
    It's still
  • 8:18 - 8:22
    not making any sense to me. So I gave
  • 8:22 - 8:25
    up on that, too.
  • 8:25 - 8:29
    Then, in 1993, I went to something called
    the
  • 8:29 - 8:33
    Gathering. The Gathering three, which was
    a big demo
  • 8:33 - 8:37
    party in Denmark, where people from all over
    Europe,
  • 8:37 - 8:39
    maybe some from the U.S. as well, would gather
  • 8:39 - 8:42
    to, to show off their skills of creating these
  • 8:42 - 8:43
    demos.
  • 8:43 - 8:47
    And demos were basically just, like, little
    music videos
  • 8:47 - 8:50
    with computer graphics. And I thought that
    was really
  • 8:50 - 8:53
    awesome. And, again, I got this sensation
    of, wow,
  • 8:53 - 8:56
    that's amazing. People are creating these
    sequences, they look
  • 8:56 - 8:58
    really good. This is, this is awesome. I'd
    love
  • 8:58 - 9:00
    to be a part of that.
  • 9:00 - 9:03
    This is '93, so I'm, I'm fourteen. And this
  • 9:03 - 9:06
    demo party, and then I met pretty much everybody
  • 9:06 - 9:09
    I knew for the next ten years in, in
  • 9:09 - 9:13
    computer software, including Allen of TextMate
    fame. I was
  • 9:13 - 9:14
    fourteen and he was part of one of these
  • 9:14 - 9:18
    demo groups, and we got talking, and then
    ten
  • 9:18 - 9:23
    years later, I'd help him release Textmate,
    and this
  • 9:23 - 9:25
    is now twenty years ago.
  • 9:25 - 9:26
    Anyway.
  • 9:26 - 9:28
    I still didn't get the concept, right. Like,
    it
  • 9:28 - 9:30
    was all, it was Assembler. So it was even
  • 9:30 - 9:35
    harder and weirder to figure out than Amos
    was.
  • 9:35 - 9:37
    It was vectors, it was math, it was, it
  • 9:37 - 9:41
    was just really hard. So once again, this
    is
  • 9:41 - 9:44
    the third time I tried to sort of figure
  • 9:44 - 9:46
    out programming, because I want to build stuff.
  • 9:46 - 9:50
    And the third time, it failed.
  • 9:50 - 9:52
    So I ended up building another information
    system. At
  • 9:52 - 9:57
    that time, there's something called BBS's.
    So pre-internet, you
  • 9:57 - 10:01
    dialed up to basically every web site individually
    through
  • 10:01 - 10:04
    a modem, and I ran one of those things.
  • 10:04 - 10:06
    At that time, it was, it was called a
  • 10:06 - 10:08
    Where's BBS, which is where we traded all
    the
  • 10:08 - 10:12
    illegal software that we couldn't afford,
    and games, and
  • 10:12 - 10:12
    demos.
  • 10:12 - 10:14
    And I had a lot of fun doing that.
  • 10:14 - 10:16
    I was fifteen and I was, I was working
  • 10:16 - 10:18
    at a grocery store, and I spent all my
  • 10:18 - 10:23
    money buying modems and phone lines.
  • 10:23 - 10:27
    But sort of the long and the short of
  • 10:27 - 10:31
    that is that I failed to identify with programming
  • 10:31 - 10:34
    under the computer-science paradigm.
  • 10:34 - 10:37
    Computer science, in itself, just didn't really
    appeal to
  • 10:37 - 10:40
    me. Like, it didn't make sense to me. Learning
  • 10:40 - 10:45
    programming through sort of the lens, the
    prism of,
  • 10:45 - 10:49
    of hard science just, it didn't really, it
    just
  • 10:49 - 10:53
    didn't click. And I was actually pretty disappointed
    for
  • 10:53 - 10:55
    awhile. I had tried to learn programming three
    or
  • 10:55 - 10:58
    four times over the past ten years of my,
  • 10:58 - 11:03
    my life, and it just, it wasn't clicking.
  • 11:03 - 11:08
    No surprise to sort of my teachers. This is
  • 11:08 - 11:11
    my high school diploma, part of it, and it
  • 11:11 - 11:16
    says math, final exam, F. And, and English,
    I
  • 11:16 - 11:20
    got an A. But math was just never my
  • 11:20 - 11:22
    thing. Physics never, was never my thing.
  • 11:22 - 11:25
    Any of the hard sciences were just never my
  • 11:25 - 11:27
    thing. And you say, oh, well that explains
    a
  • 11:27 - 11:30
    lot. That's why Rails is so fucking slow.
  • 11:30 - 11:35
    But it, it's true. It just never appealed
    to
  • 11:35 - 11:39
    me. But, I think it also inoculated me with
  • 11:39 - 11:42
    something really early on, which was, it disabused
    me
  • 11:42 - 11:45
    of the thinking that I was a computer scientist.
  • 11:45 - 11:47
    That I was ever going to come up with
  • 11:47 - 11:50
    an algorithm. That I was ever going to make
  • 11:50 - 11:55
    any ground-breaking discoveries at the low-level
    of, of computer
  • 11:55 - 11:57
    science.
  • 11:57 - 12:00
    And that was actually really a relief. Because
    when
  • 12:00 - 12:03
    I finally got into programming, I knew that
    was
  • 12:03 - 12:04
    just not what I was going to do with
  • 12:04 - 12:07
    it. That was never, it wasn't my idol, it
  • 12:07 - 12:10
    was not what I was chasing. I wanted to
  • 12:10 - 12:13
    build information systems. Like all these
    attempts I had
  • 12:13 - 12:15
    over the years, they were all about information
    systems.
  • 12:15 - 12:18
    They were about using the computer to build
    something
  • 12:18 - 12:20
    else that really didn't have much to do with
  • 12:20 - 12:25
    the underlying things. That there were people,
    smart people,
  • 12:25 - 12:27
    who had come up with algorithms underneath
    to, to
  • 12:27 - 12:31
    make it all work, wonderful. I'm not one of
  • 12:31 - 12:31
    them.
  • 12:31 - 12:33
    And that's fine.
  • 12:33 - 12:39
    I think as an industry, very few people have
  • 12:39 - 12:42
    gotten to that realization. Even if it is,
    that
  • 12:42 - 12:46
    they, on a daily basis, build information
    systems. Even
  • 12:46 - 12:48
    if it is that they're working on yet another
  • 12:48 - 12:52
    social network for sock puppets, or horror,
    in my
  • 12:52 - 12:57
    case, yet another fucking to-do list. The
    aspiration of
  • 12:57 - 13:00
    the whole industry, everyone in it, is that
    we're
  • 13:00 - 13:01
    all programmers.
  • 13:01 - 13:02
    Right?
  • 13:02 - 13:09
    No we're not. I am nothing like Linus, right.
  • 13:10 - 13:12
    He's actually a real computer scientist. To
    figure out
  • 13:12 - 13:15
    how to, I don't know, fucking improve the
    scheduler
  • 13:15 - 13:21
    in the kernel. Shew. No clue. No interest.
    All
  • 13:21 - 13:22
    good.
  • 13:22 - 13:25
    I am ever in debt that there are people
  • 13:25 - 13:29
    like that out there who can do this stuff.
  • 13:29 - 13:30
    So I don't have to do it. So I
  • 13:30 - 13:34
    can focus on something else. But I think most
  • 13:34 - 13:37
    programmers think that, oh yeah, that, that's
    what I
  • 13:37 - 13:40
    do. Yeah, I work information systems, but,
    we're kind
  • 13:40 - 13:42
    of colleagues, right? Me and Linus here.
  • 13:42 - 13:46
    I'm pretty sure that he would tell you, fuck
  • 13:46 - 13:49
    you. We're nothing alike. We are not colleagues.
    What
  • 13:49 - 13:53
    you do is making another fucking to do list.
  • 13:53 - 13:57
    I'm improving the fucking kernel of Linux.
    Far more
  • 13:57 - 14:01
    important work. He would disabuse you of your
    delusions
  • 14:01 - 14:07
    of grandeur real quick.
  • 14:07 - 14:08
    And I think that's a real shame. I think
  • 14:08 - 14:12
    it's a real shame that if you sort of
  • 14:12 - 14:16
    pick your heroes in such a impossible fashion,
    that
  • 14:16 - 14:18
    they're actually nothing like you and you
    will be
  • 14:18 - 14:20
    nothing like them, you're gonna set yourself
    up for
  • 14:20 - 14:22
    a bad time for the whole ride.
  • 14:22 - 14:27
    The truth of the matter is that most information
  • 14:27 - 14:32
    system development has very little to do with
    science.
  • 14:32 - 14:35
    Yes, it's all built on top of computer science.
  • 14:35 - 14:38
    Yes, computer science is what makes it possible
    for
  • 14:38 - 14:41
    us to do what it is that we do.
  • 14:41 - 14:45
    But it doesn't define what we do.
  • 14:45 - 14:47
    And I think in many ways that prism of
  • 14:47 - 14:51
    computer science is harmful to the development
    of information
  • 14:51 - 14:55
    systems. It's actually not a good view on
    the
  • 14:55 - 14:59
    world to have. Just because you can make,
    you're
  • 14:59 - 15:01
    Steingraeber and Sohne, and you can make the
    best
  • 15:01 - 15:03
    piano in the world, that doesn't make you
    a
  • 15:03 - 15:06
    great pianist. It doesn't mean you can play
    wonderful
  • 15:06 - 15:09
    tunes. Just because you can create the foundations
    of
  • 15:09 - 15:12
    which other people can build upon, just because
    you're
  • 15:12 - 15:16
    a great computer scientist, doesn't mean you're
    a great
  • 15:16 - 15:18
    software writer.
  • 15:18 - 15:22
    Doesn't mean you're a great programmer of
    information systems.
  • 15:22 - 15:26
    And most of all, if you are committed to
  • 15:26 - 15:28
    building information systems, and I am wholly
    committed to
  • 15:28 - 15:31
    building information systems, I've given up
    the notion, long
  • 15:31 - 15:33
    ago, that I was going to get into games
  • 15:33 - 15:37
    programming or vector programming or anything
    else that sounds
  • 15:37 - 15:41
    like hard science and is hard.
  • 15:41 - 15:43
    I think you're gonna be much better off. But
  • 15:43 - 15:45
    I think it's also really tough, because I
    think
  • 15:45 - 15:49
    most of the paths, the celebrated paths into
    programming
  • 15:49 - 15:53
    go through courses called computer science.
    So you're sort
  • 15:53 - 15:56
    of taught right from the get go that computer
  • 15:56 - 16:00
    science, like that is the ultimate ideal,
    and what
  • 16:00 - 16:02
    you're doing here is just sort of piddling
    along
  • 16:02 - 16:05
    until you can get to this top of the
  • 16:05 - 16:07
    mountain.
  • 16:07 - 16:08
    Even worse, if you actually have a degree
    in
  • 16:08 - 16:14
    computer science, right, and now you're slumming
    it, with
  • 16:14 - 16:16
    yet another social network, or, yet another
    fucking to-do
  • 16:16 - 16:20
    list. I mean, that's a recipe for self-loathing
    if
  • 16:20 - 16:22
    I ever knew one.
  • 16:22 - 16:25
    But, as I say, this is mostly about the
  • 16:25 - 16:27
    prism of how you're looking at programming,
    what is
  • 16:27 - 16:30
    programming, what is writing software. What
    is that we
  • 16:30 - 16:35
    do every day when we create information systems?
  • 16:35 - 16:37
    And if you look at it from this prism
  • 16:37 - 16:41
    of the hard sciences, you think, well, Law
    of
  • 16:41 - 16:45
    Thermodynamics. Physics. This is, this is
    the real serious
  • 16:45 - 16:49
    hard stuff, right. You will laugh at French
    poetry.
  • 16:49 - 16:52
    Ha, ha, ha, ha! They're all just, what, analyzing
  • 16:52 - 16:55
    what some schmuck in the 1700s did, and there's
  • 16:55 - 16:58
    a thousand different interpretations of, of
    what that person
  • 16:58 - 17:01
    actually wrote and what does that actually
    mean? Like,
  • 17:01 - 17:04
    that's pathetic, right. You can't arrive at
    any ultimate,
  • 17:04 - 17:06
    clear, universal truths.
  • 17:06 - 17:11
    Math! There's a truth. There's a final result.
    Physics.
  • 17:11 - 17:14
    There's a truth. We're knowing more about
    the natural
  • 17:14 - 17:18
    world in a way where we can be completely
  • 17:18 - 17:23
    confident. Mostly. In what we know. Certainly
    in math,
  • 17:23 - 17:23
    right.
  • 17:23 - 17:29
    If you carry that over into programming, you
    end
  • 17:29 - 17:35
    up with shit like this. Law of Demeter. Practices
  • 17:35 - 17:41
    and principles who sort of project that they're
    universal
  • 17:41 - 17:45
    truths about the natural world, that this
    is how
  • 17:45 - 17:47
    good programs are made, and this is not really
  • 17:47 - 17:50
    an argument. The only argument is whether
    you're professional
  • 17:50 - 17:53
    and following the laws, or you're an amateur
    and
  • 17:53 - 17:58
    you're breaking them.
  • 17:58 - 18:00
    When I look at computer programming, and when
    I
  • 18:00 - 18:04
    reach most, read most programs, I'm not reading
    hard
  • 18:04 - 18:07
    sciences. It is much more like studying 17th
    century
  • 18:07 - 18:10
    French poetry. What the fuck did this guy
    mean?
  • 18:10 - 18:13
    Like, I can't follow this at all. Like, is
  • 18:13 - 18:17
    this some weird reference to some play somewhere?
    What's
  • 18:17 - 18:18
    going on here?
  • 18:18 - 18:21
    It's actually more like forensics. It's more
    like analysis.
  • 18:21 - 18:24
    It's much more subjective. Like, what is actually
    going
  • 18:24 - 18:28
    on? What were they trying to communicate?
    What's just
  • 18:28 - 18:30
    going on here, right?
  • 18:30 - 18:33
    So, I find it so funny that, that programmers
  • 18:33 - 18:37
    who work in programming, and they laugh at
    all
  • 18:37 - 18:41
    these subjective fields of endeavor, when
    that is what
  • 18:41 - 18:45
    they do every day. They just, no, what I'm
  • 18:45 - 18:49
    doing is computer science. This is empirical
    truth, blah,
  • 18:49 - 18:52
    blah, blah, we have laws, blah, blah, blah.
  • 18:52 - 18:54
    I think the, the bottom line is that is
  • 18:54 - 18:56
    when you go in with that notion, when you
  • 18:56 - 18:58
    go in with the notion that we can actually
  • 18:58 - 19:02
    discover laws of programming, like, Law of
    Demeter, of
  • 19:02 - 19:05
    how we should be creating our programs, you
    lull
  • 19:05 - 19:10
    yourself into this belief that there are some
    practices
  • 19:10 - 19:13
    that are just true. They're not up for debate.
  • 19:13 - 19:15
    They're not up for discussion.
  • 19:15 - 19:20
    They're science. That what we do is science.
    Well,
  • 19:20 - 19:22
    I think there's another word for, sort of,
    those
  • 19:22 - 19:29
    delusions. Pseudoscience. When people think
    they're doing science and
  • 19:30 - 19:34
    they're not actually doing science. That's
    pseudoscience. I think
  • 19:34 - 19:38
    a lot of what's going on in software, methodology,
  • 19:38 - 19:42
    practices, is pseudoscience.
  • 19:42 - 19:44
    Which would be fine if people would accept
    that
  • 19:44 - 19:46
    and say, yes, what I'm doing is pseudo science.
  • 19:46 - 19:49
    Like, I'm not finding any grand truths here,
    but
  • 19:49 - 19:52
    they're not, right. They're ex-pouting that
    this is, this
  • 19:52 - 19:53
    is the truth.
  • 19:53 - 20:00
    Well, here's another pseudoscience. Diet schemes.
    I think diets
  • 20:00 - 20:06
    are actually incredibly similar to most software
    methodology approaches.
  • 20:06 - 20:11
    They all sort of espouse that I have the
  • 20:11 - 20:14
    truth, what you need to get slim and healthy
  • 20:14 - 20:17
    is the ten-day green smoothie cleanse.
  • 20:17 - 20:19
    That is the truth. That's how you get it,
  • 20:19 - 20:22
    right. And then you, shit, that, that's, OK,
    smoothies.
  • 20:22 - 20:25
    Sounds good. But what about this super shred
    diet?
  • 20:25 - 20:28
    Like, I lose twenty pounds in four weeks?
    That's
  • 20:28 - 20:31
    certainly better than ten pounds in, I don't
    know,
  • 20:31 - 20:33
    ten weeks, or whatever that hungry diet girl
    is
  • 20:33 - 20:36
    promising. I'll go with that super shred guy,
    like
  • 20:36 - 20:38
    he's got to have the truth, right.
  • 20:38 - 20:41
    And it's so funny, if you read any diet
  • 20:41 - 20:42
    books, and diet books are incredibly popular.
    If you
  • 20:42 - 20:44
    look at the most popular book on Amazon, the
  • 20:44 - 20:46
    top one hundred list, a lot of them are
  • 20:46 - 20:51
    diet books. People want to be told how they
  • 20:51 - 20:54
    can cheat the basics. I think software development
    is
  • 20:54 - 20:56
    exactly like that.
  • 20:56 - 20:59
    I think software developers are exactly like
    people trying
  • 20:59 - 21:04
    to lose ten pounds and thinking, you know
    what,
  • 21:04 - 21:07
    all this exercising, just eating healthier,
    that's a little
  • 21:07 - 21:09
    too hard. Let's, let's listen to this super
    shred
  • 21:09 - 21:10
    guy.
  • 21:10 - 21:12
    He's got to have the answer. An answer that's
  • 21:12 - 21:17
    less painful, less simple and basic. There's
    got to
  • 21:17 - 21:19
    be some grand secret I just don't know yet.
  • 21:19 - 21:22
    If I can just learn the secret then everything's
  • 21:22 - 21:25
    gonna be great, right. But it's pseudoscience.
    Those diets
  • 21:25 - 21:31
    are based on anecdotes. They're based on one
    guy
  • 21:31 - 21:33
    trying something, or, or looking at a few
    people,
  • 21:33 - 21:38
    a tiny sample size, it's just pure, poor,
    pure
  • 21:38 - 21:40
    poor science.
  • 21:40 - 21:44
    External variables, uncontrolled experiments
    that run for too long.
  • 21:44 - 21:46
    You can't derive any absolute truths from
    it. But
  • 21:46 - 21:52
    people keep arriving at absolute truths.
  • 21:52 - 21:56
    And just like feeling a little overweight,
    and most
  • 21:56 - 21:58
    people do at some point in their life. Everybody
  • 21:58 - 22:00
    wants to lose whatever it is. They want to
  • 22:00 - 22:02
    feel healthier even if they are at the correct
  • 22:02 - 22:05
    weight. They want to be in better shape. All
  • 22:05 - 22:07
    our code bases are exactly like that.
  • 22:07 - 22:09
    Everyone has like, oh I'd love that this part
  • 22:09 - 22:11
    of the code base, it's not that clean, right.
  • 22:11 - 22:14
    So we have that same feeling of being a
  • 22:14 - 22:19
    little insecure about our quote code quality,
    just like
  • 22:19 - 22:22
    most people are a little insecure, at least
    at
  • 22:22 - 22:25
    certain times in their life, about their body,
    right.
  • 22:25 - 22:28
    So we're ripe for somebody to come in and
  • 22:28 - 22:32
    tell us what's wrong. To fix it for us
  • 22:32 - 22:34
    by just saying, oh, no, no, no, you don't
  • 22:34 - 22:36
    have to do any of the hard stuff. Writing
  • 22:36 - 22:37
    good code, do you know what that's about?
    It's
  • 22:37 - 22:41
    about this one practice. This one secret that
    they
  • 22:41 - 22:43
    don't want you to know.
  • 22:43 - 22:46
    If I teach you that, then all your code
  • 22:46 - 22:49
    is going to be wonderful. But right now, you're
  • 22:49 - 22:52
    not a professional. You're an amateur. You're
    writing dirty
  • 22:52 - 22:56
    code. You should feel really bad about that.
    You
  • 22:56 - 22:58
    have sinned.
  • 22:58 - 23:02
    But, I will give you absolution. I have the
  • 23:02 - 23:06
    pathway to clean code.
  • 23:06 - 23:11
    And it hits a lot of people right in
  • 23:11 - 23:15
    the impostor plexus. Like, ugh, you're saying
    my code
  • 23:15 - 23:17
    is dirty? Yeah, I guess it is a little
  • 23:17 - 23:20
    dirty. There's this one part that's, like,
    shit, maybe
  • 23:20 - 23:23
    I'm not really a computer scientist. Maybe
    it doesn't
  • 23:23 - 23:27
    really, I don't really belong here amongst
    the programmers.
  • 23:27 - 23:29
    Can you please tell me, how do I get
  • 23:29 - 23:32
    to be a computer scientist?
  • 23:32 - 23:37
    How can I get to belong amongst the esteemed
  • 23:37 - 23:41
    professional programmers? Can you tell me
    how? And there
  • 23:41 - 23:44
    are lots of people willing to tell you how.
  • 23:44 - 23:47
    That the salvation will come through these
    patterns and
  • 23:47 - 23:49
    practices, and as long as you follow these
    ten
  • 23:49 - 23:55
    commandments of good code, all shall be well.
  • 23:55 - 23:57
    OK.
  • 23:57 - 24:00
    I think the most popular commandment, I'm
    gonna spend
  • 24:00 - 24:03
    some time on that, the most popular practice,
    the
  • 24:03 - 24:07
    most popular pattern for making people feel
    shitty about
  • 24:07 - 24:09
    their code and shitty about themselves and
    shitty about
  • 24:09 - 24:16
    their path through programming, is TDD.
  • 24:18 - 24:23
    TDD is the most successful software diet of
    all
  • 24:23 - 24:30
    times. It's so alluring, it has such an appeal
  • 24:31 - 24:35
    in its basic principles, that everyone gets
    wrapped up
  • 24:35 - 24:37
    in it. I got wrapped up in it for
  • 24:37 - 24:42
    quite awhile. I got wrapped up in the storytelling
  • 24:42 - 24:47
    that all software before TDD was shit and
    unprofessional.
  • 24:47 - 24:49
    And that the only way to arrive at clean
  • 24:49 - 24:54
    code was to follow the principles of TDD.
  • 24:54 - 24:57
    And the principles of TDD, mind you, are not
  • 24:57 - 25:02
    about the tests. It's about test first. It's
    about
  • 25:02 - 25:07
    test-driven design, right. That we have tests
    afterwards, that's
  • 25:07 - 25:13
    just an accidental side-effect. A benefit,
    if you will,
  • 25:13 - 25:15
    after the fact. And it's the perfect diet.
  • 25:15 - 25:20
    I tried multiple times, which is usually how
    it
  • 25:20 - 25:22
    goes with diets, we try one and it doesn't
  • 25:22 - 25:25
    really work and we fall off the wagon and
  • 25:25 - 25:27
    then a few months later you try again and
  • 25:27 - 25:28
    you feel bad about it the whole time and
  • 25:28 - 25:29
    that's how I felt about TDD for a long
  • 25:29 - 25:30
    time.
  • 25:30 - 25:32
    I felt like TDD was what I was supposed
  • 25:32 - 25:35
    to do. I was supposed to write all my
  • 25:35 - 25:38
    tests first, and then I would be allowed to
  • 25:38 - 25:42
    write my code. And it just didn't work. I
  • 25:42 - 25:45
    kept just feeling like, this is not, I'm not
  • 25:45 - 25:48
    arriving at something better here. When I'm
    driving my
  • 25:48 - 25:52
    design by writing my tests first, the code
    I
  • 25:52 - 25:56
    look at afterwards, it's not better. It's
    not cleaner.
  • 25:56 - 26:00
    The dirty code I wrote without being test-driven
    first,
  • 26:00 - 26:02
    it actually looks better.
  • 26:02 - 26:07
    But, so successful has TDD been, that for
    the
  • 26:07 - 26:10
    longest time, until actually fairly recently,
    I just thought,
  • 26:10 - 26:12
    well, I'm the wrong-doer. I'm the one doing
    it
  • 26:12 - 26:16
    wrong. TDD is not at fault, right. Just because
  • 26:16 - 26:19
    everybody's doing TDD wrong, doesn't mean
    that there's anything
  • 26:19 - 26:22
    wrong with TDD. There's just something wrong
    with all
  • 26:22 - 26:24
    of you. That's the problem.
  • 26:24 - 26:26
    If you would just be more faithful to the
  • 26:26 - 26:29
    practices, then everything would be great.
  • 26:29 - 26:31
    And that's what makes it such a great diet.
  • 26:31 - 26:34
    That it keeps people in the perpetual state
    of
  • 26:34 - 26:38
    feeling inadequate. So, you keep having to
    buy more
  • 26:38 - 26:43
    books, and attend more conference talks, and
    attend more
  • 26:43 - 26:45
    workshops, and hire more consultants, to teach
    you to
  • 26:45 - 26:51
    be truer to the religion of TDD. Hogwash.
  • 26:51 - 26:54
    Let's look at some code. So here's a very
  • 26:54 - 26:59
    simple piece of code. Person has an age method,
  • 26:59 - 27:02
    that calculates how old somebody is. And we
    have
  • 27:02 - 27:05
    a test for it. This piece of code depends
  • 27:05 - 27:06
    on the world.
  • 27:06 - 27:11
    It directly refers to date today. It's a explicit
  • 27:11 - 27:14
    dependency. You cannot change it in there.
    Well, in
  • 27:14 - 27:16
    a lot of languages, that's a problem. Like,
    how
  • 27:16 - 27:18
    are you actually going to test this if you
  • 27:18 - 27:19
    can't somehow figure out how to change the
    date
  • 27:19 - 27:21
    of today. Like, every time you run your test
  • 27:21 - 27:23
    it might be a different day and it might
  • 27:23 - 27:24
    be broken.
  • 27:24 - 27:27
    Well, in Ruby it's really easy. We just stop
  • 27:27 - 27:29
    that constant and make it work. That's what
    the
  • 27:29 - 27:32
    travel-to method is about, right.
  • 27:32 - 27:34
    Proponents of TDD will look at that code and
  • 27:34 - 27:41
    say, dirty, dirty code. Explicit dependencies
    hidden inside. You're
  • 27:41 - 27:45
    mocking a global object? What the fuck?
  • 27:45 - 27:48
    You need to shape up. Here's the shaped up
  • 27:48 - 27:52
    version. We inject our dependency, so we have
    a
  • 27:52 - 27:55
    default of date.today, but we can put in our
  • 27:55 - 27:58
    own, in the test, we can put in our
  • 27:58 - 28:01
    own date, right. This is much cleaner. Right.
    No.
  • 28:01 - 28:04
    Great. We improved our code base.
  • 28:04 - 28:08
    Did we? Is this a better code base? Is
  • 28:08 - 28:11
    this method better than what we just had there?
  • 28:11 - 28:14
    Is it simpler? Is it clearer? No. It's easier
  • 28:14 - 28:18
    to test. And that's the important point, right.
    That's
  • 28:18 - 28:20
    the important point in all of these debates,
    is
  • 28:20 - 28:22
    just, is it easier to test?
  • 28:22 - 28:24
    That's the measure of success. I think that's
    a
  • 28:24 - 28:26
    shitty measure of success. I think there are
    much
  • 28:26 - 28:30
    higher ideals than just whether something
    is easy to
  • 28:30 - 28:34
    test. But it gets worse.
  • 28:34 - 28:36
    Here's another example. If you actually have
    a method
  • 28:36 - 28:39
    that depends on another method, we have to
    inject
  • 28:39 - 28:42
    the dependency all the way down, now you're
    really
  • 28:42 - 28:44
    muddying things up and now the code is really
  • 28:44 - 28:46
    starting to get nasty. And this is such a
  • 28:46 - 28:49
    simple example. I've actually posted this
    example online before
  • 28:49 - 28:52
    and had arguments with TDD proponents about
    that.
  • 28:52 - 28:53
    And, yes, this is, I'm like, well, what does
  • 28:53 - 28:57
    it matter? You're just injecting one dependency,
    what does
  • 28:57 - 28:59
    it matter? It's not that big of a deal,
  • 28:59 - 29:00
    right? Yes it is.
  • 29:00 - 29:03
    Because this is exactly the type of thinking
    that
  • 29:03 - 29:06
    leads you down a really nasty path. Let's
    look
  • 29:06 - 29:07
    at another example.
  • 29:07 - 29:12
    Here's a standard Rails controller. It has
    reliance on
  • 29:12 - 29:14
    the world. It relies on a before action that
  • 29:14 - 29:19
    ensures permissions. It sets up a new object
    and
  • 29:19 - 29:22
    sends out an email and then it responds to
  • 29:22 - 29:24
    something, right. The whole purpose of the
    controller in
  • 29:24 - 29:27
    Rails is to sort of direct the world. It's
  • 29:27 - 29:29
    to interact with the world.
  • 29:29 - 29:32
    But how do you unit test that, right? That's
  • 29:32 - 29:34
    really hard. It's relying on the entire world.
    If
  • 29:34 - 29:38
    we're following this scientific approach of
    unit testing where
  • 29:38 - 29:40
    we're isolating all the variables, holding
    everything else constant
  • 29:40 - 29:43
    except for these two things, what goes in,
    what
  • 29:43 - 29:50
    goes out. This is bad, right.
  • 29:50 - 29:54
    If we instead put in something like a person
  • 29:54 - 29:56
    creation command and hide away all the actual
    doing
  • 29:56 - 29:58
    of the control and then we inject all the
  • 29:58 - 30:01
    stuff that it depends on we can test person
  • 30:01 - 30:04
    creation command really well.
  • 30:04 - 30:07
    Is that code better? Is that code simpler?
    Is
  • 30:07 - 30:10
    it clearer? Would you rather look at this
    and
  • 30:10 - 30:11
    then understand what the system does or would
    you
  • 30:11 - 30:13
    rather look at this and try to figure out
  • 30:13 - 30:16
    where does this thing go?
  • 30:16 - 30:22
    And that's the consequence of this chase of
    test-first.
  • 30:22 - 30:24
    It leads you down a path where the gospel
  • 30:24 - 30:28
    of test-driven design is that anything that's
    easier to
  • 30:28 - 30:33
    test is better. That's it. That's the measure
    of
  • 30:33 - 30:36
    quality. If you can test it easily it's better.
  • 30:36 - 30:39
    If you can't test it easily, it's worse.
  • 30:39 - 30:43
    Boo. Exactly right. Boo.
  • 30:43 - 30:46
    It's not better. We're losing sight of what
    we're
  • 30:46 - 30:49
    actually trying to do. Tests were supposed
    to support
  • 30:49 - 30:54
    us. They weren't supposed to be the main thing.
  • 30:54 - 30:55
    And I think this is leading to a lot
  • 30:55 - 31:01
    of Zombie astronautic architectures. Things
    that I thought we
  • 31:01 - 31:04
    moved past long ago. If you look at, at
  • 31:04 - 31:08
    this person create command, that reminds me
    very much
  • 31:08 - 31:11
    about Struts 1 point 2, and how they had
  • 31:11 - 31:13
    every action as their own object. And that
    it
  • 31:13 - 31:15
    was great because it was easy to test, and
  • 31:15 - 31:16
    it was shit when you were trying to put
  • 31:16 - 31:19
    a whole architecture together, because you
    had all these
  • 31:19 - 31:20
    create commands and all of the sudden you
    had
  • 31:20 - 31:22
    a million objects. Yes, they were easier to
    test,
  • 31:22 - 31:26
    but the system was much harder to reason about.
  • 31:26 - 31:29
    You see the same thing around ActiveRecord,
    for example.
  • 31:29 - 31:32
    You see, well ActiveRecord should just be
    data access
  • 31:32 - 31:34
    objects. They shouldn't actually have any
    logic. They should
  • 31:34 - 31:36
    just be about interfacing with the database,
    because then
  • 31:36 - 31:38
    we can split out everything else. Our domain
    logic,
  • 31:38 - 31:41
    it's just that it doesn't have to touch the
  • 31:41 - 31:43
    database, so that our tests can be simple,
    so
  • 31:43 - 31:46
    that our tests can be fast, right?
  • 31:46 - 31:53
    Again. Order of priority. Test, test fast,
    oh, your
  • 31:53 - 31:59
    architecture. That'll just fall from that,
    right?
  • 31:59 - 32:03
    I recently read James Coplien, has a great
    paper
  • 32:03 - 32:06
    out called "Why Most Unit Testing is Waste."
    And
  • 32:06 - 32:10
    for me, this is the money quote. Splitting
    up
  • 32:10 - 32:14
    functions to support the testing process,
    destroys your system
  • 32:14 - 32:18
    architecture and code comprehension along
    with it. Test at
  • 32:18 - 32:22
    a coarser level of granularity.
  • 32:22 - 32:29
    TDD is focused on the unit. The unit is
  • 32:29 - 32:31
    the sacred piece, because that's the science
    piece. That's
  • 32:31 - 32:33
    what we can control all of the variables.
    We're
  • 32:33 - 32:36
    just looking at these few pieces, right.
  • 32:36 - 32:39
    What James is saying, maybe that's not the
    right
  • 32:39 - 32:44
    level. Maybe testing, the role it should have,
    shouldn't
  • 32:44 - 32:48
    be about the unit most of the time. And,
  • 32:48 - 32:50
    I sort of alluded to this awhile back, I
  • 32:50 - 32:54
    wrote a post called Testing Like the TSA,
    and
  • 32:54 - 32:56
    the main thing about that was about over-testing
    and
  • 32:56 - 32:58
    sort of this testing theater that goes on.
    But
  • 32:58 - 33:02
    I hadn't really made the switch that it, the
  • 33:02 - 33:04
    problem is that we're trying to test at the
  • 33:04 - 33:05
    wrong level.
  • 33:05 - 33:07
    It's not testing itself. Testing is great.
    I'm not
  • 33:07 - 33:10
    advocating that we shouldn't have tests. I'm
    advocating that
  • 33:10 - 33:14
    driving your design from unit tests is actually
    not
  • 33:14 - 33:18
    a good idea. That you actually end up destroying
  • 33:18 - 33:20
    your system architecture and your code comprehension
    along with
  • 33:20 - 33:22
    it.
  • 33:22 - 33:26
    So if unit tests aren't the thing, what could
  • 33:26 - 33:27
    we do instead?
  • 33:27 - 33:30
    Well, I think there are higher levels of testing.
  • 33:30 - 33:31
    We've already sort of moved to that in Rails.
  • 33:31 - 33:34
    It's no longer called test unit, where you
    place
  • 33:34 - 33:37
    your tests, it's called test models. That's
    already one
  • 33:37 - 33:40
    step up. That sort of frees you from feeling
  • 33:40 - 33:43
    bad about the fact that your, your model tests
  • 33:43 - 33:45
    actually touch the database. That's not a
    bad thing.
  • 33:45 - 33:47
    Yes. They run slower. But they also test more
  • 33:47 - 33:48
    things.
  • 33:48 - 33:49
    You can make anything fast if it doesn't have
  • 33:49 - 33:52
    to work.
  • 33:52 - 33:54
    And I think that's the problem with testing
    in
  • 33:54 - 33:55
    a lot of cases. We recently had a really
  • 33:55 - 33:57
    bad bug on base kim where we actually lost
  • 33:57 - 34:01
    some data for real customers. And it was incredibly
  • 34:01 - 34:06
    well-tested at the unit level. And all the
    tests
  • 34:06 - 34:08
    passed. And still we lost data. How the fuck
  • 34:08 - 34:10
    did that happen?
  • 34:10 - 34:12
    It happened because we were so focused on
    driving
  • 34:12 - 34:14
    our design from the unit test level, we didn't
  • 34:14 - 34:17
    have any system tests for that particular
    thing. And
  • 34:17 - 34:19
    it was a really simple thing. It was like,
  • 34:19 - 34:21
    if you were editing an object and you were
  • 34:21 - 34:23
    editing the attachments, you could lose an
    attachment. And
  • 34:23 - 34:26
    we lost some attachments and it was a terrible
  • 34:26 - 34:27
    thing.
  • 34:27 - 34:30
    And after that, sort of thought, wait a minute.
  • 34:30 - 34:33
    All these unit tests are just focusing on
    these
  • 34:33 - 34:36
    core objects in the system. These individual
    unit pieces.
  • 34:36 - 34:38
    It doesn't say anything about whether the
    whole system
  • 34:38 - 34:39
    works.
  • 34:39 - 34:43
    Most TDD proponents, I find, are much more
    focused
  • 34:43 - 34:45
    on the unit level, because that's where they're
    driving
  • 34:45 - 34:47
    their design. And they're not very much focused
    on
  • 34:47 - 34:49
    the system level at all, which is what people
  • 34:49 - 34:50
    actually give a shit about.
  • 34:50 - 34:53
    Does the system work? I don't care about whether
  • 34:53 - 34:56
    your units work. Does the whole thing work?
    That's
  • 34:56 - 34:58
    what matters.
  • 34:58 - 35:00
    So that kind of freed my mind up a
  • 35:00 - 35:03
    little bit. That if we give up this need
  • 35:03 - 35:05
    for hard science experience, where we have
    to control
  • 35:05 - 35:07
    all the variables and boil everything down
    to a
  • 35:07 - 35:09
    single unit that can be tested, we can float
  • 35:09 - 35:12
    freely with the world.
  • 35:12 - 35:14
    Awesome.
  • 35:14 - 35:18
    This realization, I came to realize, was why
    people
  • 35:18 - 35:23
    hate fixtures. So fixtures in, in Rails is
    about
  • 35:23 - 35:27
    spinning up a world, it's about setting up,
    sort
  • 35:27 - 35:34
    of, small size version of the whole world.
    Where
  • 35:34 - 35:37
    most approaches, they focus on just one unit.
  • 35:37 - 35:39
    I don't want to have an account in here
  • 35:39 - 35:40
    and a project in here if I'm just testing
  • 35:40 - 35:43
    my message. I just want to test this one
  • 35:43 - 35:45
    single thing, right. And if you're doing that,
    yeah,
  • 35:45 - 35:47
    fixtures are probably not a good thing. It
    doesn't
  • 35:47 - 35:48
    really work for that.
  • 35:48 - 35:51
    It works really well when you're not concerned
    about
  • 35:51 - 35:54
    the hard science focus on unit tests. It works
  • 35:54 - 35:57
    really well when you're focused on a larger
    level.
  • 35:57 - 35:59
    When you're focused on models, when you're
    focused on
  • 35:59 - 36:03
    controllers, and most importantly when you're
    focused on systems.
  • 36:03 - 36:09
    But all that is sort of usually swept away
  • 36:09 - 36:15
    by the holy trinity of test metrics. Coverage,
    ratio,
  • 36:15 - 36:17
    and speed.
  • 36:17 - 36:24
    I've been in a lot of internet arguments lately.
  • 36:24 - 36:28
    In such esteemed establishments as Hacker
    News, and, and
  • 36:28 - 36:32
    elsewhere, and I find it really interesting,
    because each
  • 36:32 - 36:35
    individual argument will make me rage, but
    then the
  • 36:35 - 36:38
    larger set of all arguments, like a meta study,
  • 36:38 - 36:41
    actually reveals really interesting things
    about what people care
  • 36:41 - 36:42
    about. What they value.
  • 36:42 - 36:45
    And what I find is, in most discussions about
  • 36:45 - 36:48
    design, especially around Rails, what people
    care about these
  • 36:48 - 36:52
    things, and these things only. It's about
    the test
  • 36:52 - 36:54
    coverage. It's about the test ratio. And it's
    about
  • 36:54 - 36:56
    how fast your tests run.
  • 36:56 - 37:00
    Like, that's the pedestal. That's the holy
    grail. What
  • 37:00 - 37:04
    actually happens underneath, the design of
    the rest of
  • 37:04 - 37:07
    the application is, eh. Doesn't really matter.
  • 37:07 - 37:10
    And thus, a lot of people come to celebrate,
  • 37:10 - 37:13
    oh, I have a one to four test ratio.
  • 37:13 - 37:15
    For every line of production code, I have
    four
  • 37:15 - 37:19
    lines of test. Oh yeah.
  • 37:19 - 37:23
    And they say that with pride. And I'm like,
  • 37:23 - 37:25
    what? So you're saying for every line of production
  • 37:25 - 37:27
    code you write, you have to write four lines
  • 37:27 - 37:29
    of code? And that somehow makes you a hero?
  • 37:29 - 37:31
    How, how does that work?
  • 37:31 - 37:34
    So your system is now five times as large,
  • 37:34 - 37:36
    reasoning about the whole system is now five
    times
  • 37:36 - 37:39
    as complex, and you're proud of this, why?
    Well,
  • 37:39 - 37:42
    of course, because I have a hundred percent
    coverage.
  • 37:42 - 37:45
    My five thousand tests run incredibly fast
    because they
  • 37:45 - 37:47
    never actually test very much.
  • 37:47 - 37:49
    They certainly do not test the system. They
    test
  • 37:49 - 37:53
    all these little slices of unit. Wonderful.
  • 37:53 - 37:56
    It's not wonderful. You have anemic fucking
    tests. They
  • 37:56 - 37:58
    don't prove shit. You're gonna have the same
    bug
  • 37:58 - 38:00
    that we have on base camp, and the system
  • 38:00 - 38:02
    is not going to work even though you've proudly
  • 38:02 - 38:06
    proclaimed, oh, well, your units are working.
  • 38:06 - 38:10
    Well, whoopity-doo. This decoupling is now
    free. People think
  • 38:10 - 38:14
    that, oh, this is like that saying, like,
    quality's
  • 38:14 - 38:17
    free. Right. Testing is free. Not when you're
    doing
  • 38:17 - 38:21
    it like this. It's not free.
  • 38:21 - 38:23
    And most importantly, it's not free, not so
    much
  • 38:23 - 38:27
    in time, but in conceptual overhead. Understanding
    a system
  • 38:27 - 38:33
    that has been test-driven designed from the
    unit perspective
  • 38:33 - 38:36
    is really hard. Because you have all these
    levels
  • 38:36 - 38:40
    of indirection. You have all these levels
    of intermediation.
  • 38:40 - 38:45
    To separate the tests from slow things, like
    HTML
  • 38:45 - 38:48
    or the database or, any of the other parts
  • 38:48 - 38:50
    of the system that actually makes up your
    system.
  • 38:50 - 38:54
    And they focus just on that one thing. So
  • 38:54 - 38:56
    they can be very fast, if they don't have
  • 38:56 - 38:58
    to work. They don't actually have to test
    your
  • 38:58 - 38:59
    system.
  • 38:59 - 39:01
    So that's sort of two charges in one. It's
  • 39:01 - 39:04
    a charge first that your design is not going
  • 39:04 - 39:07
    to improve. Your design is going to deteriorate
    by
  • 39:07 - 39:11
    doing test first programming, because you're
    going to construct
  • 39:11 - 39:15
    your units of testing, your methods, in a
    different
  • 39:15 - 39:17
    way, like we say with the age example. You're
  • 39:17 - 39:20
    going to inject all your dependencies in a
    way
  • 39:20 - 39:22
    that does not prove things.
  • 39:22 - 39:24
    And second of all, you're not gonna get the
  • 39:24 - 39:27
    benefit of great coverage. You might have
    a lot
  • 39:27 - 39:28
    of tests, but they don't test your system.
    It
  • 39:28 - 39:33
    doesn't improve your confidence in actually
    the whole thing
  • 39:33 - 39:36
    working, and then what good is it?
  • 39:36 - 39:41
    Well, I thought about this for a long time
  • 39:41 - 39:45
    and thought, like, this is not really, it
    doesn't
  • 39:45 - 39:48
    seem like that great of a revelation. Why,
    why
  • 39:48 - 39:50
    do I keep having these arguments over and
    over
  • 39:50 - 39:53
    again? Why are people focused so hard and
    so
  • 39:53 - 39:58
    intensely on this trinity of test metrics?
    How did
  • 39:58 - 40:01
    that come to be the main thing that people
  • 40:01 - 40:02
    are arguing about?
  • 40:02 - 40:03
    How did that come to be the main decider
  • 40:03 - 40:06
    of what's good design and what's bad design?
    Really,
  • 40:06 - 40:10
    couldn't really figure it out. Until I started
    thinking
  • 40:10 - 40:12
    back of like, what is this prism we're looking
  • 40:12 - 40:18
    through? We're looking through computer science.
    Engineering. Professionalism.
  • 40:18 - 40:22
    James Harrington wrote a bunch of books on
    quality
  • 40:22 - 40:24
    of engineering, and he has a great quote here.
  • 40:24 - 40:27
    If you can't measure something, you can't
    understand it.
  • 40:27 - 40:29
    If you can't understand it, you can't control
    it.
  • 40:29 - 40:31
    If you can't control it, you can't improve
    it.
  • 40:31 - 40:36
    That makes a lot of sense. Cause like, yeah,
  • 40:36 - 40:38
    yeah, that makes sense. That's gotta be why.
    And
  • 40:38 - 40:41
    then I got another great quote. Just because
    you
  • 40:41 - 40:43
    can, just because something is easy to measure
    doesn't
  • 40:43 - 40:44
    mean it's important.
  • 40:44 - 40:49
    This, I think, is exactly what's going on
    here.
  • 40:49 - 40:53
    Programming of information systems is a lot
    more like
  • 40:53 - 40:58
    French poetry than it is like physics. But
    programmers
  • 40:58 - 41:00
    grow up thinking that they're computer scientists,
    so they
  • 41:00 - 41:03
    want it really badly to be like physics. They
  • 41:03 - 41:07
    want it really badly to be a hard, professional
  • 41:07 - 41:08
    science.
  • 41:08 - 41:14
    And coverage, ratio, and speed. You can get
    that
  • 41:14 - 41:18
    fucking thing down to six decimals. Like,
    that, I
  • 41:18 - 41:20
    can be so precise about how fast my test
  • 41:20 - 41:26
    runs, eighty-four point seven percent coverage,
    boom. Got it.
  • 41:26 - 41:28
    Doesn't say anything about whether or not
    that's actually
  • 41:28 - 41:32
    important. Doesn't say anything about whether
    that's actually producing
  • 41:32 - 41:34
    a good system. Doesn't say anything about
    whether the
  • 41:34 - 41:36
    person after you, or you yourself, three months
    from
  • 41:36 - 41:38
    now, can understand what the hell is going
    on
  • 41:38 - 41:41
    in this code base.
  • 41:41 - 41:43
    You haven't necessarily made anything any
    clearer. You've made
  • 41:43 - 41:48
    it very easy to produce metrics. And if there's
  • 41:48 - 41:51
    one thing we love with, with science, it's
    clear
  • 41:51 - 41:58
    concise objective truths and coverage and
    ratio and speed
  • 41:58 - 42:01
    fit that bill. So we adopted them with open
  • 42:01 - 42:04
    arms, even though they were not that important.
  • 42:04 - 42:08
    Second part of it. Cost is not value. A
  • 42:08 - 42:12
    lot of people have invested so much in building
  • 42:12 - 42:18
    up their expertise, their time, their four-to-one
    ratio in
  • 42:18 - 42:22
    tests. The investment is massive. Well, of
    course they're
  • 42:22 - 42:25
    gonna be defensive about it. Like, you've
    invested so
  • 42:25 - 42:28
    much of your ego and your time and your
  • 42:28 - 42:31
    resources on this project, into testing. So
    of course
  • 42:31 - 42:33
    it must be valuable. Of course it must be
  • 42:33 - 42:34
    important.
  • 42:34 - 42:37
    That's not how it works. Just because something
    is
  • 42:37 - 42:39
    really expensive, just because something takes
    a lot of
  • 42:39 - 42:43
    your time doesn't mean it's valuable. Doesn't
    mean it's
  • 42:43 - 42:48
    important.
  • 42:48 - 42:52
    So I was sort of giving a brief description
  • 42:52 - 42:57
    of this talk yesterday at dinner with Aaron
    Patterson,
  • 42:57 - 43:01
    and he trolled me right back and said, TL;DR,
  • 43:01 - 43:04
    just don't test, right. Like, that's what
    I'm supposed
  • 43:04 - 43:07
    to get out of this.
  • 43:07 - 43:12
    No. No. Testing absolutely has value. Regression
    testing absolutely
  • 43:12 - 43:18
    has value. Driving your design through test
    first? In
  • 43:18 - 43:23
    my mind, rarely has value. Not never. There
    are
  • 43:23 - 43:25
    times where I'll write my tests first, usually
    when
  • 43:25 - 43:29
    it's something like a translator of some kind,
    where
  • 43:29 - 43:31
    I know exactly what's going in and I know
  • 43:31 - 43:32
    exactly what I want out.
  • 43:32 - 43:34
    That could be a good case to start with
  • 43:34 - 43:37
    test first. Most information system design
    is not like
  • 43:37 - 43:39
    that. I'm trying to figure out and sell what
  • 43:39 - 43:42
    the system is supposed to do. What I'm going
  • 43:42 - 43:44
    to arrive at is the test, is this set
  • 43:44 - 43:47
    of tests, it's a set of regression tests,
    that
  • 43:47 - 43:48
    make me feel good about that after the fact,
  • 43:48 - 43:50
    that I can still change my system and not
  • 43:50 - 43:56
    break it, right.
  • 43:56 - 44:03
    So TDD. Kent Beck. Main proponent behind TDD
    has
  • 44:06 - 44:09
    a very sensible quote that goes exactly along
    these
  • 44:09 - 44:12
    lines. I get paid for code that works, not
  • 44:12 - 44:15
    for tests, so my philosophy is to test as
  • 44:15 - 44:19
    little as possible to reach a given level
    of
  • 44:19 - 44:20
    confidence.
  • 44:20 - 44:24
    Immensely sensible. I find that that's actually
    often the
  • 44:24 - 44:28
    case with these things that get taken too
    far.
  • 44:28 - 44:33
    TDD started out as a pretty sensible thing.
    Kent
  • 44:33 - 44:35
    has an even more sensible perception of it
    now,
  • 44:35 - 44:39
    I think, than when he wrote the test-driven
    book
  • 44:39 - 44:43
    originally. But that's not what most people
    take away.
  • 44:43 - 44:45
    That's not what most people run with if they
  • 44:45 - 44:47
    want to build a career on making people feel
  • 44:47 - 44:50
    shitty about their code bases and their dirty,
    dirty
  • 44:50 - 44:51
    code.
  • 44:51 - 44:54
    They take a much more extremist approach,
    that unless
  • 44:54 - 44:59
    you're doing test-first, you're not a professional.
    Certainly not
  • 44:59 - 45:02
    what Kent's saying.
  • 45:02 - 45:07
    OK. So for me, this really boils down to,
  • 45:07 - 45:10
    we're, we're trying to wear the wrong hat
    the
  • 45:10 - 45:13
    majority of the time. Thinking of yourself
    as a
  • 45:13 - 45:18
    software engineer will lead you down the path
    of
  • 45:18 - 45:24
    coverage, speed, metrics, hard sciences - all
    these things
  • 45:24 - 45:29
    we can measure and it leave you laughing at
  • 45:29 - 45:35
    shit like interpretation of French poetry.
    Of subjective evaluations
  • 45:35 - 45:37
    of a design in the system, even though these
  • 45:37 - 45:40
    are the only tools that we have.
  • 45:40 - 45:43
    So this has taken me awhile to arrive at
  • 45:43 - 45:46
    this conclusion. I've hated the word software
    engineer for
  • 45:46 - 45:49
    quite awhile. Cause I never felt it fit me.
  • 45:49 - 45:52
    I never thought of myself as a software engineer.
  • 45:52 - 45:54
    I kind of tried to be one, a few
  • 45:54 - 45:56
    times, and I failed all the time. And by
  • 45:56 - 45:58
    the time I finally arrived at programming
    as something
  • 45:58 - 46:00
    that I wanted to do, it sure as shit
  • 46:00 - 46:03
    wasn't software engineering.
  • 46:03 - 46:06
    Yes. It's a hard hat that I wear occasionally,
  • 46:06 - 46:11
    when I do performance optimization. That's
    hard science. You
  • 46:11 - 46:13
    make a change. You measure it. Was it an
  • 46:13 - 46:19
    improvement? If not, revert. If yes, deploy.
    Very scientific.
  • 46:19 - 46:21
    Very good.
  • 46:21 - 46:24
    Great to wear the hard hat when that fits.
  • 46:24 - 46:26
    Is what, that what I do the majority of
  • 46:26 - 46:27
    the time? Is that how I think of myself
  • 46:27 - 46:29
    when I write most of the things that I
  • 46:29 - 46:31
    write? When I add a new feature to base
  • 46:31 - 46:34
    camp or do forensics to figure out how a
  • 46:34 - 46:37
    bug came about, or what somebody meant when
    they
  • 46:37 - 46:39
    wrote a bug in or something? No. That's not
  • 46:39 - 46:41
    what I do.
  • 46:41 - 46:42
    So I don't try to think of myself as
  • 46:42 - 46:44
    a software engineer.
  • 46:44 - 46:48
    OK. If we're not software engineers, most
    of the
  • 46:48 - 46:52
    time when we make information systems, what
    are we
  • 46:52 - 46:55
    then? What other hat should we try to wear?
  • 46:55 - 46:59
    What other identity should we try to aspire
    to?
  • 46:59 - 47:01
    I think we had it all along. I think
  • 47:01 - 47:04
    we had it in the language all along. We're
  • 47:04 - 47:10
    software writers. Writing is a much more apt
    metaphor
  • 47:10 - 47:13
    for what we do most of the time, than
  • 47:13 - 47:20
    engineering is. Writing is about clarity.
    It's about presenting
  • 47:22 - 47:28
    information and motivations in a clear-to-follow
    manner so that
  • 47:28 - 47:30
    anybody can understand it.
  • 47:30 - 47:34
    There are not bonus points for making something
    convoluted,
  • 47:34 - 47:37
    as there often is with engineering and with
    test-first
  • 47:37 - 47:40
    design. Making things more convoluted gives
    you the benefits
  • 47:40 - 47:44
    of, perhaps, easier to test. They don't give
    you
  • 47:44 - 47:49
    clarity. So those things are often in opposition.
  • 47:49 - 47:53
    Clarity is all about being succinct without
    being terse.
  • 47:53 - 47:56
    WE can write things using as small words as
  • 47:56 - 48:00
    we know how, using as little complication
    as we
  • 48:00 - 48:03
    know how, using as little conceptual overhead
    as we
  • 48:03 - 48:07
    know how to get the job done.
  • 48:07 - 48:10
    That's a much better approach. And I think
    it
  • 48:10 - 48:14
    comes very easy if you think of software development
  • 48:14 - 48:17
    as writing. If you look at a piece of
  • 48:17 - 48:19
    writing that somebody has written and it's
    kind of
  • 48:19 - 48:22
    convoluted, can't really follow the argument,
    and paragraphs are
  • 48:22 - 48:24
    not broken up neatly, is the first thing you're
  • 48:24 - 48:26
    gonna say, you know what the problem with
    this
  • 48:26 - 48:29
    is? You're not using big enough words.
  • 48:29 - 48:31
    If we just shoved some bigger words into this
  • 48:31 - 48:35
    text, it's gonna be there. That's good. Oh.
    The
  • 48:35 - 48:38
    problem here is like, like your sentences
    are too
  • 48:38 - 48:42
    clear. If you just insert a sentence in the
  • 48:42 - 48:44
    middle, that'd be great. Oh, do you know what?
  • 48:44 - 48:47
    This needs more semicolons. That's what this
    needs. If
  • 48:47 - 48:51
    this has more semicolons, boom. You got clarity.
  • 48:51 - 48:54
    No. More indirection. More third-person. These
    are not the
  • 48:54 - 48:57
    things that make for great, clear writing.
    And that's
  • 48:57 - 49:00
    obvious when we talk about things like writing.
    SO
  • 49:00 - 49:03
    if we talk about software development as writing,
    I
  • 49:03 - 49:06
    think it'll be obvious too. I think if we
  • 49:06 - 49:11
    supplant the high ideal of what matters for
    design
  • 49:11 - 49:12
    is how easy it is to test, how easy
  • 49:12 - 49:16
    it is to make engineering driven, and put
    clarity
  • 49:16 - 49:20
    of the code base above all else, we're gonna
  • 49:20 - 49:23
    be much better off. And arguments are gonna
    be
  • 49:23 - 49:26
    settled much easier. And it's gonna be much
    easier
  • 49:26 - 49:28
    to read the fucking code you wrote three months
  • 49:28 - 49:30
    ago, because you had that in mind.
  • 49:30 - 49:32
    That was your motivation. That was what you
    were
  • 49:32 - 49:34
    going for.
  • 49:34 - 49:38
    So what is clarity? How do you figure that
  • 49:38 - 49:41
    out, right? That's real easy to say, oh it's
  • 49:41 - 49:46
    just clarity. Boom. It's open to interpretation,
    right. It's
  • 49:46 - 49:48
    not as clear as just saying, oh if you
  • 49:48 - 49:50
    can just get your code coverage above 85%
    then
  • 49:50 - 49:52
    you're gold, right.
  • 49:52 - 49:54
    Clarity doesn't work like that. There's not
    a metric
  • 49:54 - 49:56
    we can just apply, because, again, it's not
    hard
  • 49:56 - 50:01
    science. Clarity of writing is not hard science.
  • 50:01 - 50:05
    So the easy answer is, I know when I
  • 50:05 - 50:09
    see it. Right? There's not just gonna be a
  • 50:09 - 50:12
    list of principles and practices that somebody
    can be
  • 50:12 - 50:15
    taught and then they will automatically produce
    clear writing
  • 50:15 - 50:20
    every time. Right? If you want to be a
  • 50:20 - 50:22
    good writer, is it enough just to sit and
  • 50:22 - 50:28
    memorize the dictionary? No. Just knowing
    the words available
  • 50:28 - 50:30
    to you, knowing the patterns of development
    is not
  • 50:30 - 50:33
    gonna make you a good developer.
  • 50:33 - 50:37
    You have to develop an eye. You have to
  • 50:37 - 50:40
    develop an eye for clarity, which means first
    of
  • 50:40 - 50:41
    all, you have to decide that that's important
    to
  • 50:41 - 50:44
    you. So that's the first step. If you're still
  • 50:44 - 50:46
    stuck in, the most important thing about my
    system
  • 50:46 - 50:49
    is how fast my tests run, and how many
  • 50:49 - 50:52
    of them I have, well. Forget about it. You're
  • 50:52 - 50:53
    not gonna get to this point.
  • 50:53 - 50:54
    You have to decide that the most important
    thing
  • 50:54 - 50:59
    for your system is clarity. When you do decide
  • 50:59 - 51:02
    that, you can start developing an eye. I started
  • 51:02 - 51:08
    getting into photography maybe six years ago.
    When I
  • 51:08 - 51:10
    first got into photography, like, I would
    look at
  • 51:10 - 51:13
    a picture and it was like, well, looks like
  • 51:13 - 51:13
    a good picture.
  • 51:13 - 51:15
    Now, I've been looking at thousands of pictures.
    I've
  • 51:15 - 51:18
    been taking thousands of pictures. And I've
    developed an
  • 51:18 - 51:20
    eye. I can see when the white balance is
  • 51:20 - 51:23
    off. I can see, oh, this has a blue
  • 51:23 - 51:25
    tint. Oh, this actually, if we crop it just
  • 51:25 - 51:28
    a little bit more, only the subjects we want
  • 51:28 - 51:29
    to have in focus are in focus. Oh, this
  • 51:29 - 51:32
    would actually be better in black and white.
  • 51:32 - 51:36
    That eye just came from doing it. A lot.
  • 51:36 - 51:38
    It didn't come from just sitting down and
    reading
  • 51:38 - 51:42
    a lot of photography books. And I think it's
  • 51:42 - 51:44
    the same thing with code. I think a lot
  • 51:44 - 51:48
    of programmers, coming at it from a software
    engineering
  • 51:48 - 51:50
    angle, thing that just all they have to do
  • 51:50 - 51:55
    is learn the practices, learn the patterns,
    memorize them
  • 51:55 - 51:58
    all, and then they will be good programmers.
  • 51:58 - 52:01
    No, they won't. The only way to become a
  • 52:01 - 52:04
    good programmer, where, by definition, I define
    good programmers
  • 52:04 - 52:07
    as somebody who programs, who writes software
    with clarity,
  • 52:07 - 52:10
    is to read a lot of software, write a
  • 52:10 - 52:13
    lot of software.
  • 52:13 - 52:14
    Just like how do you become a good photographer?
  • 52:14 - 52:16
    You take a lot of pictures. And you look
  • 52:16 - 52:18
    at them. And you practice. And you practice.
    And
  • 52:18 - 52:20
    you practice.
  • 52:20 - 52:22
    I think it's quite similar to the problem
    with
  • 52:22 - 52:26
    diets, right. The fundamental truth with diets
    is to
  • 52:26 - 52:29
    be healthy you should probably exercise regularly,
    you should
  • 52:29 - 52:33
    probably eat a reasonable amount and it should
    be
  • 52:33 - 52:37
    good stuff. Like, that's three things. Incredibly
    hard to
  • 52:37 - 52:41
    do. Most people do not do that, right. Figuring
  • 52:41 - 52:44
    out how to write good software: read a lot
  • 52:44 - 52:48
    of software, write a lot of software, aim
    for
  • 52:48 - 52:49
    clarity. It sounds too simple.
  • 52:49 - 52:51
    Why is it simple? Because there's not just
    a
  • 52:51 - 52:54
    secret. There's not just one answer somebody
    can give
  • 52:54 - 52:57
    you. The only way you can get there is
  • 52:57 - 53:02
    by doing it. So when I first started developing
  • 53:02 - 53:06
    Rails, I read a ton of software. I read
  • 53:06 - 53:11
    the entire Ruby standard library. Partly because
    documentation of
  • 53:11 - 53:13
    Ruby at that time was pretty poor, and the
  • 53:13 - 53:14
    only way to figure out how it worked was
  • 53:14 - 53:16
    to actually look at the code. But that was
  • 53:16 - 53:18
    also where I learned so much.
  • 53:18 - 53:22
    Today, we have it so much easier. Bundle open
  • 53:22 - 53:25
    name of any gem, and it'll open, boom, right
  • 53:25 - 53:26
    up in your text editor. You can look at
  • 53:26 - 53:29
    any code.
  • 53:29 - 53:32
    How many of you have read through a complete
  • 53:32 - 53:37
    gem recently. Something you did not write.
    Awesome. That's
  • 53:37 - 53:39
    actually really encouraging. I thought it
    would be much
  • 53:39 - 53:40
    less.
  • 53:40 - 53:42
    I think that is exactly the path you need
  • 53:42 - 53:44
    to take. You need to read a shit ton
  • 53:44 - 53:46
    of code. And it's not so much just because
  • 53:46 - 53:47
    you read this code and then, oh that's all
  • 53:47 - 53:51
    great stuff. Just as important as it is to,
  • 53:51 - 53:53
    to develop your sense of writing by reading
    a
  • 53:53 - 53:58
    lot of shit writing, so is it with code.
  • 53:58 - 53:59
    And I think you will find that that is
  • 53:59 - 54:02
    actually very easy. Because a lot of things
    you'll
  • 54:02 - 54:07
    do bundle open on will follow Sturgeon's Revelation.
    90%
  • 54:07 - 54:09
    of everything is crap.
  • 54:09 - 54:13
    Well, at least you know you have company if
  • 54:13 - 54:15
    you write crap software and I certainly do
    from
  • 54:15 - 54:18
    time to time. And that's a great way to
  • 54:18 - 54:21
    learn. I actually find that I learn the most
  • 54:21 - 54:23
    about software and learn the most about what
    matters
  • 54:23 - 54:26
    to me, I learn the most about what clarity
  • 54:26 - 54:28
    is when I read poor software.
  • 54:28 - 54:30
    Because what I do is, I take a piece
  • 54:30 - 54:34
    of software, I take a class or method, and
  • 54:34 - 54:36
    then I look at it, how could this be
  • 54:36 - 54:37
    clearer? Like this is, I think this is poorly
  • 54:37 - 54:41
    written. I think this smells. How can I rewrite
  • 54:41 - 54:42
    it?
  • 54:42 - 54:44
    So by just sitting down and going through
    that
  • 54:44 - 54:46
    exercise and rewriting it, I find I learn
    a
  • 54:46 - 54:49
    whole lot about what I care about. So that's
  • 54:49 - 54:52
    what I've been doing lately. Engaging in a
    lot
  • 54:52 - 54:54
    of these internet arguments. Somebody will
    submit a piece
  • 54:54 - 54:59
    of code, and usually the submission will come
    along
  • 54:59 - 55:00
    with the proposed solution, too, right.
  • 55:00 - 55:03
    I have this shitty piece of code. Then I
  • 55:03 - 55:07
    learned about these three patterns. And now
    it's wonderful.
  • 55:07 - 55:09
    And what I have found every single time, and
  • 55:09 - 55:11
    I've only done this maybe a handful of times,
  • 55:11 - 55:14
    maybe a little more, is that every single
    time,
  • 55:14 - 55:15
    you just took the shitty code and you stuck
  • 55:15 - 55:17
    it into some different boxes.
  • 55:17 - 55:19
    Like, it didn't actually improve. Applying
    the pattern to
  • 55:19 - 55:22
    it did not improve the underlying clarity
    of the
  • 55:22 - 55:25
    code, because you just wrote it poorly. Like,
    the
  • 55:25 - 55:27
    problem with the code was not that it was
  • 55:27 - 55:30
    missing patterns. The problem with the code
    was that
  • 55:30 - 55:33
    it was crap. That it just had to be
  • 55:33 - 55:35
    rewritten.
  • 55:35 - 55:42
    Now, that leads us to sort of a mission,
  • 55:42 - 55:45
    in some ways, from Rails is and what Ruby
  • 55:45 - 55:49
    is, and it leads also to clarify some of
  • 55:49 - 55:50
    the arguments we've had in the Rails community
    for
  • 55:50 - 55:54
    awhile. Readability is incredibly important
    to Ruby. We have
  • 55:54 - 55:57
    a lot of duplicated methods that do exactly
    the
  • 55:57 - 56:01
    same thing, just so we can improve readability.
  • 56:01 - 56:05
    I remember the first time I saw unless, when
  • 56:05 - 56:07
    I was learning about Ruby. That was one of
  • 56:07 - 56:10
    those light bulb moments. It's like, wait
    a minute.
  • 56:10 - 56:14
    Unless is exactly the same as if not, but
  • 56:14 - 56:19
    it's a different keyword. Huh.
  • 56:19 - 56:22
    Right? It was not just about making the most
  • 56:22 - 56:28
    efficient, compact language. It was about
    readability. Poof!
  • 56:30 - 56:33
    Mind blown.
  • 56:33 - 56:37
    And decade-long love-affair with Ruby established.
    And I think
  • 56:37 - 56:41
    that this is what we're trying to achieve
    constantly
  • 56:41 - 56:43
    in Rails as well. A lot of people will
  • 56:43 - 56:46
    gripe about, oh, ActiveRecord is too big or
    something
  • 56:46 - 56:49
    is too big, or have too many methods. The
  • 56:49 - 56:52
    surface area is too big or there's, whatever
    it
  • 56:52 - 56:52
    is, right.
  • 56:52 - 56:55
    Like, who gives a shit? Is it more readable?
  • 56:55 - 56:57
    Is it more clear? That's the only thing that
  • 56:57 - 57:00
    matters. What do I care whether the surface
    area
  • 57:00 - 57:02
    of a method is a hundred methods or it's
  • 57:02 - 57:05
    two hundred methods? I don't give a shit about
  • 57:05 - 57:06
    that. The only thing I give a shit about
  • 57:06 - 57:08
    is whether, is the code I'm actually reading,
    is
  • 57:08 - 57:10
    the system I'm trying to understand, is that
    more
  • 57:10 - 57:13
    clear. When you put clarity as your number
    one
  • 57:13 - 57:15
    mission, a lot of concerns just fall by the
  • 57:15 - 57:16
    wayside.
  • 57:16 - 57:22
    It just doesn't matter anymore. And it's liberating.
  • 57:22 - 57:24
    So, I think this actually comes from sort
    of
  • 57:24 - 57:26
    the same rope. I didn't have time to write
  • 57:26 - 57:28
    a short letter, so I wrote a long one
  • 57:28 - 57:32
    instead. I think that describes about eighty
    percent of
  • 57:32 - 57:35
    all that ninety percent of shitty code.
  • 57:35 - 57:39
    Most people did not take the time to write
  • 57:39 - 57:41
    a short piece of code, so they wrote a
  • 57:41 - 57:43
    long one instead. And then they wrote that
    long
  • 57:43 - 57:45
    one, piece of code, and they like, pulled
    out
  • 57:45 - 57:48
    their suspenders and like, oh yeah, I'm done.
    My
  • 57:48 - 57:49
    tests pass.
  • 57:49 - 57:52
    Boom. Right? Or they look at it and decide,
  • 57:52 - 57:54
    oh shit, this is too long. I must be
  • 57:54 - 57:58
    missing some patterns. I just sprinkle some
    patterns over
  • 57:58 - 58:03
    this. Wonders, right? No. What you wrote was
    a
  • 58:03 - 58:06
    draft.
  • 58:06 - 58:09
    This was just a first draft, right. Any piece
  • 58:09 - 58:12
    of code you write down is just a draft.
  • 58:12 - 58:16
    Mark Twain actually had the hard job, right.
    He
  • 58:16 - 58:18
    wrote in ink. If you actually had to change
  • 58:18 - 58:21
    that, well that was kind of hard, right. So
  • 58:21 - 58:23
    his drafts were a lot more complicated. Ours?
    We
  • 58:23 - 58:26
    have it so easy. A text editor? You just
  • 58:26 - 58:28
    delete stuff. And you don't need any of the
  • 58:28 - 58:30
    little stuff that you, you fill over the page
  • 58:30 - 58:33
    and you spill it everywhere and so forth.
    An
  • 58:33 - 58:34
    eraser.
  • 58:34 - 58:36
    You can just delete stuff. Like that's my
    favorite
  • 58:36 - 58:41
    key. The delete key. It's the number one tool
  • 58:41 - 58:48
    for improving code. Delete key.
  • 58:48 - 58:53
    So when I was in high school, I submitted
  • 58:53 - 58:57
    a bunch of first drafts as essays, and they
  • 58:57 - 58:59
    were really shitty. And of course they were.
    They
  • 58:59 - 59:01
    were the first draft. And my teacher at the
  • 59:01 - 59:03
    time said, oh, all right, all right, this
    is
  • 59:03 - 59:06
    actually not bad. You just told me the step
  • 59:06 - 59:07
    one. If you have something on your mind, you
  • 59:07 - 59:09
    should write it down.
  • 59:09 - 59:10
    That's what I did. I, I wrote it down.
  • 59:10 - 59:13
    And then I handed it in. Oh, if you've
  • 59:13 - 59:15
    written something down, you should rewrite
    it.
  • 59:15 - 59:18
    Oh. That was the step I missed. And I
  • 59:18 - 59:21
    think that's the step most people miss when
    they
  • 59:21 - 59:23
    write down code. Cause they're focused on
    all these
  • 59:23 - 59:25
    other things. They're not focused on the clarity,
    because
  • 59:25 - 59:26
    when you are focused on the clarity, you will
  • 59:26 - 59:31
    realize that all your first drafts are terrible.
  • 59:31 - 59:33
    All my first drafts are terrible. All my first
  • 59:33 - 59:36
    attempts at writing a good class are poor.
    They're
  • 59:36 - 59:40
    too long. They're not at the same level of
  • 59:40 - 59:43
    abstraction. They're not clear. And that's
    OK. I wrote
  • 59:43 - 59:44
    something down. I was trying to figure out
    what
  • 59:44 - 59:47
    the system was supposed to do.
  • 59:47 - 59:49
    That's hard work. And often times you don't
    get
  • 59:49 - 59:51
    perfect code out of that when you're still
    trying
  • 59:51 - 59:53
    to figure out what it is that you're writing.
  • 59:53 - 59:56
    But once you've written it down, you should
    rewrite
  • 59:56 - 59:58
    it.
  • 59:58 - 60:03
    And I think the key part of rewriting is
  • 60:03 - 60:07
    omitting needless words when it comes to regular
    writing.
  • 60:07 - 60:11
    When it comes to programming, it's omitting
    needless concepts.
  • 60:11 - 60:15
    It's omitting needless patterns. It's omitting
    needless practices. It's
  • 60:15 - 60:21
    omitting needless classes. It's omitting all
    these extra things
  • 60:21 - 60:25
    that aren't getting you closer to clarity,
    right.
  • 60:25 - 60:27
    How do you know? You develop an eye for
  • 60:27 - 60:29
    it. How do you develop an eye? You read
  • 60:29 - 60:30
    a lot of code. You write a lot of
  • 60:30 - 60:33
    code. You rewrite a lot of code. And you
  • 60:33 - 60:37
    forget about fucking patterns for awhile.
    You forget about
  • 60:37 - 60:40
    fucking TDD for awhile. And you focus on just
  • 60:40 - 60:42
    what's in front of you. The piece of code.
  • 60:42 - 60:45
    How can I write it simpler?
  • 60:45 - 60:48
    Write software well. Thank you very much.
Title:
RailsConf 2014 - Keynote: Writing Software by David Heinemeier Hansson
Description:

more » « less
Video Language:
English
Duration:
01:01:17

English subtitles

Revisions