text
stringlengths
0
2.46k
**Jerod Santo:** Can you give a for instance, like maybe in a basic case of a situation where maybe me as a programmer would approach something imperatively, or computationally, step by step, whatever it is, and you as a mathematician, maybe you would look at it differently? Because I can't look at it your way; I want ...
**Leslie Lamport:** \[11:59\] Yeah, it's funny, I don't have a ready example, except something that happened fairly recently with a colleague. He asked me how would I define something. And he said he found it really hard to write this definition. And it was defining some property of sequences; of actually infinite sequ...
**Jerod Santo:** Right. That's where I'm sitting right now.
**Leslie Lamport:** But he wasn't trying to compute it, he was trying to write a definition.
**Jerod Santo:** A definition of the problem, or of a solution?
**Leslie Lamport:** No, just the definition of some property of infinite sequences that he wanted to define.
**Jerod Santo:** I see.
**Leslie Lamport:** He was a theoretician. This is theoretical computer science, in some sense. It's talking about a few properties of programs, rather than how to write programs. So you represent the execution of a sequence as an infinite sequence of either states or steps, depending on how you want to do it... And th...
**Jerod Santo:** Gotcha. So this kind of is a pattern, or at least echoes what we talked about earlier with Knuth's Tex, and subsequently LaTeX was the separation of concerns. In that case, it's from the ideas, and then the display of the ideas, of the typesetting. You're talking about separation of concerns. You're ta...
**Leslie Lamport:** Well, yes, exactly. I mean, I wouldn't say it's separate --
**Jerod Santo:** Well, one informs the other.
**Leslie Lamport:** Well, the thing I like to say is coding is to programming what typing is to writing. I mean, obviously, it's somewhat hyperbolic, because there's a lot more intellectual effort goes into coding than typing... But I think, actually, maybe before the days of computers the analogy would be writing, and...
\[16:30\] Actually, there are two things that you should do before you start writing code. The first one is figure out, decide what the program is supposed to do. And again, you can think of that in terms of what you have to tell the user of the program, what the program is supposed to do. Now, that program very often ...
**Jerod Santo:** So you're referring to like a formal specification.
**Leslie Lamport:** It doesn't have to be formal.
**Jerod Santo:** Well, it has to be usable without the code. You can do that informally?
**Leslie Lamport:** Well, by formally I mean writing it down in mathematics, or in a language like TLA+.
**Jerod Santo:** That would be formal in my mind, yeah.
**Leslie Lamport:** I mean, I do this whenever I -- if I have a coding class, and some method in this class, I will write a description of what that method does. And in 95% of the cases, it's just English;, just pure prose.
**Jerod Santo:** Right. Right.
**Leslie Lamport:** Maybe a formula or two tossed in. Occasionally, pseudocode. Usually not, but sometimes perhaps pseudocode.
**Jerod Santo:** Sure.
**Leslie Lamport:** Whatever works. But it has to be precise enough that somebody can use the code without having to read it. And if what it does is simple enough, that you can explain it in English, that's great. Occasionally, there's a piece of code that -- but you have to start writing it. And when you write it, you...
There's this cartoonist \[unintelligible 00:19:14.18\] has this wonderful caption of a cartoon, which is "Writing is nature's way of showing you how fussy your thinking is."
**Jerod Santo:** I like that.
**Leslie Lamport:** I had this one example, this one certain aspect of actually writing a parser for TLA+ that somebody was doing, and he sort of asked "How you compute this little condition of some check of correctness of the specification?" And I thought, "Oh, well, this is quite simple. I would write down a piece of...
\[20:10\] And he coded it from the TLA+. And I actually sort of asked him about that... You know, TLA+ is a lot different from Java, what he was coding it in. How much effort was that? And he said, "Oh, no, it's really straightforward." And actually, at some point later I modified the parser, and looked at the code, ho...
Then the wonderful thing about that code is about once or twice a year for the next several years after he built that parser, I thought "Oh my God, here's a special case of this. Oh, I bet the parser doesn't get it right." And every time I checked it, the parser did the right thing. That stuff really works.
**Jerod Santo:** Okay. So this process that you're describing - I guess it kind of matters if we're talking about it in the small, like at a function level, or down in the details, versus like large systems thinking. And we can discuss that. But it's certainly countercultural to the way that software, generally speakin...
**Leslie Lamport:** Well, yeah. First of all, you're right, the world changes. If you build a program, and it's really used a lot, you're going to want to modify it at some point. And the real world is, you're not going to go back and start from scratch and redo everything. You're going to start patching it. And we've ...
So you start patching things, it gets sloppy. But if you don't do this design right from the beginning, then every piece of the code you write is a patch. And you start out from day one with a mess. I love this quote of Eisenhower, who said, "No battle was ever won according to plan, but no battle was ever won without ...
**Jerod Santo:** I like that. Okay, that's compelling. You start off with a mess; every line of code you write as a patch. I think there's wisdom in there.
**Leslie Lamport:** We might want to go back to what you said about you in the small versus in the large.
**Jerod Santo:** Yeah, let's do that.
**Leslie Lamport:** The only difference in the small versus the large is that in some sense the bigger something is, the more formal you have to be, because it's going to be more complicated. So a lot of the users today are -- you know, people in Azure, basically the web services of Microsoft, and Amazon Web Services, ...
\[24:23\] My colleague, Markus Kuppe, the one who is currently basically maintaining the TLA+ tools, he has this wonderful talk which is titled "How to save two hours of TLA with two weeks of debugging."
**Jerod Santo:** \[laughs\]
**Leslie Lamport:** People will just say, "Oh, using this formal stuff is just so hard. It's just so much work."
**Jerod Santo:** Right...
**Leslie Lamport:** "I don't need to do that." And it's not a good attitude, especially if you're dealing with concurrency. When there's concurrency involved, you just can't fly by the seat of your pants. You're not gonna get it right.
**Jerod Santo:** I guess one of the perhaps tragic, sad but true things is that oftentimes, based on this description, we don't know if we need these tools. We don't know if we need this upfront design, the formalized spec, the maths stuff, until we're already feeling the pain down the road. Like, maybe it's two weeks,...
**Leslie Lamport:** Well, there are two kinds of specifications you write. One is what the program is supposed to do. That's not telling you anything about coding it. Then the other spec is how the program does it, which is a high-level view of how the code works. Now, the way I like to think about it is a high-level s...
**Jerod Santo:** \[laughs\] It doesn't matter.
**Leslie Lamport:** ...the algorithm will be wrong. So it's eliminating one class of bugs. But it's a class of bugs, and especially with concurrency, that testing is very poor at finding, because the bug can occur just in terms of how really the speeds at which things are happening. And so you can have some system that...
**Jerod Santo:** Right. It kind of goes back to that quote about a battle - you have your plan, and then you have the execution of the plan. And so your plan is your algorithm; there's your thing that you're going to make sure you have right in the first place. And just because you've got the plan right doesn't mean yo...
**Leslie Lamport:** \[28:17\] Yeah. And when you do in testing find that it's wrong, it's a hell of a lot more work to fix it than it would have been had you found it when you were writing the algorithm.
**Jerod Santo:** Yeah. The sooner, the faster you can find those problems, the cheaper they are to route around. So this whole thinking in algorithms - this is something you say is very few programmers think in terms of algorithms. And I think you're right about that. But my question to you, for me, is how would one be...
**Leslie Lamport:** Well, what I do for engineers is I force them to think mathematically. I'm not the only person who talks about things, about the need for specifications. But just about everybody else wants to make writing the specifications easy for the programmers. So he writes their specifications in what looks l...
**Jerod Santo:** You don't wanna do that.
**Leslie Lamport:** I want to get people to think outside the box. People say that all the time, but they never say what the box is.