WEBVTT

0:00:00.000 --> 0:00:08.700
<v A>Hosting provided by Host Tornado. They offer website hosting packages, dedicated servers, and VPS solutions. HostT.net.

0:00:16.980 --> 0:00:21.500
<v A>Episode 33: Design Patterns. Take it away, Patrick.

0:00:21.500 --> 0:01:39.080
<v B>So I was watching the live launch of the newest SpaceX flight going to the Space Station. Oh, nice, with the Dragon capsule. And it was like at work; I felt like it was momentous. We were all standing around my monitor and like watching the rocket lift off and everything. And they had said it was not a main mission objective, but the first stage, the big rocket part, was supposed to come back and try to land. And they want to eventually reuse it. But they said it didn't have a large chance of success. So I was hoping to be able to watch this thing come back down. But they didn't have any video whatsoever of that part of it for unknown reasons. It took until like just recently that they—this is like, you know, it launched like last week. And then this week they just finally announced that it did successfully do that part of the mission where it deployed these like lander legs from the first stage and then hovered briefly above the ocean and then fell into the ocean. But because the seas were really bad, it got destroyed in the ocean. Oh, no. So you can launch something like the thing that launches something up to space, recover it with rocket engines to slow down. But then the ocean water can destroy it. It's like, oh.

0:01:39.980 --> 0:01:58.720
<v A>So a couple of things on this. One, I heard this crazy story that—I guess it's not that crazy—but the idea is like helium; I guess there's a finite amount of helium. You can correct me if I'm wrong here, on Earth at least. Yeah. And I guess helium, liquid helium is necessary for getting to orbit.

0:01:59.420 --> 0:02:00.640
<v B>I think liquid hydrogen.

0:02:00.640 --> 0:02:16.900
<v A>Oh, but helium has something to do with it. Anyways, the way this story went is that basically you need helium at some level. And if we used up all the helium on things like balloons or whatever, that basically we'd never be able to go into space.

0:02:18.160 --> 0:02:19.380
<v B>I've never heard that before.

0:02:19.400 --> 0:02:21.000
<v A>Oh, really? Yeah, I thought it was kind of ridiculous.

0:02:21.540 --> 0:02:35.400
<v B>So there is a problem with like, there is true of helium, and like they use it a lot because it's really cold and less dangerous than liquid hydrogen. So they use it for a lot of medical procedures and medical research. And so I know that like that is a problem.

0:02:35.739 --> 0:02:35.980
<v A>Oh, I see.

0:02:36.000 --> 0:02:39.540
<v B>I've never heard that we couldn't go to space anymore. That might be true. I don't know.

0:02:39.660 --> 0:02:40.940
<v A>Oh, I don't know. It's just kind of crazy.

0:02:41.040 --> 0:02:48.340
<v B>But of course, then there's always this caveat that if we ever start doing large-scale fusion, you'll most likely have an overabundance of helium.

0:02:48.940 --> 0:02:50.220
<v A>Oh, that's true. Yeah.

0:02:50.580 --> 0:02:51.430
<v B>So the other

0:02:51.430 --> 0:03:22.480
<v A>Thing I was going to say is that there was this article on SpaceX where I guess like Elon Musk is suing the government, which I, well, anyway, that's a side note, but I don't understand how you can do that. But basically, at any rate, he's suing the government because they had this like special, they had this contract with a joint venture of Lockheed and Boeing to do the, you know, the satellites. And they wouldn't let him bid. And so he's suing, you know, on the grounds that he should at least be able to compete and bid on this, on this project. Yeah.

0:03:24.579 --> 0:03:58.100
<v B>They're doing a lot of stuff. I don't—a lot of people have very strong feelings about it, especially being from Florida where a lot of people were employed by NASA and its subsidiaries, but people who worked for NASA and with NASA. Right? But yeah, the stuff they're doing is really kind of crazy. Like this rocket recovery where I was kind of going with it is like this fact that you could reuse the stage one part of a rocket. But that's like a giant way to drive down costs if you can do it reliably and with not it being a much more expensive thing in the first place.

0:03:58.799 --> 0:04:03.402
<v A>So is that really a big part of the cost, the destruction of the bottom part? It depends.

0:04:03.402 --> 0:04:22.099
<v B>Right? So it's like probably not. I don't know. But if you're trying to get costs down and down and down, I mean, just from the standpoint of it's a complicated, high-tolerance thing that you have to build, low tolerance. High tolerance. You have to have small tolerances. It has

0:04:22.099 --> 0:04:22.943
<v A>to be very precisely

0:04:22.943 --> 0:04:29.740
<v B>built. So no matter what, it's going to be expensive to build. And if you can spend just a little bit more and then reuse it several times, that's obviously better, right?

0:04:30.080 --> 0:04:30.908
<v A>Yeah. It's like the

0:04:30.908 --> 0:04:43.420
<v B>argument of like you can buy cheap shoes, but they'll fall apart. If you spend only a little bit more and get nice shoes, they'll last a lot longer. Yeah, right. But you don't necessarily spend 10 times as much because those shoes don't necessarily last even 10 times longer.

0:04:43.780 --> 0:04:45.020
<v A>Yeah, you get diminishing returns.

0:04:45.380 --> 0:04:54.740
<v B>Yeah. So I think that's the idea. But the fact that it's just kind of crazy, it has like these fold-down legs and, you know, does a deceleration burn, and like all of that is just crazy.

0:04:55.440 --> 0:05:01.640
<v A>Yeah, it's totally awesome. Yeah. Did you ever get into like building model rockets and shooting them in the sky or anything like that?

0:05:01.640 --> 0:05:10.400
<v B>I mean, we did it several times, and I wish I would have done more of it, but it's one of those things like where do you go to do it? And half the time we could never get back to rocket.

0:05:10.400 --> 0:05:15.099
<v A>I guess that is a problem, isn't it?

0:05:15.780 --> 0:05:32.520
<v B>Yeah. So like, you know, in Florida, we had some places, but, you know, I was thinking about stuff here and like Silicon Valley area. I'm sure if you went far enough away, but I don't have any idea if I wanted to take my kids out to do model rockets. Like you can't go to the park. Like, I don't think people would be happy with you.

0:05:33.080 --> 0:05:35.455
<v A>No, I'm pretty sure you can't shoot off model rockets. Not

0:05:35.522 --> 0:05:40.120
<v B>Everybody agrees. Yeah. So where would you go? Like I'd have to drive out of town to do it.

0:05:40.280 --> 0:05:46.879
<v A>Go wherever the MythBusters go. They're actually based in San Francisco, so they must go somewhere around here. But

0:05:46.879 --> 0:05:48.840
<v B>I think they get special permission, and I don't know.

0:05:50.000 --> 0:05:50.880
<v A>Yeah, that's true.

0:05:50.880 --> 0:06:04.880
<v B>So like I do know a couple of places that allow you to fly RC airplanes, which is nice. But even then, like, you know, in Florida, I had enough space. I could have flown it in my yard, like a very small one or whatever. But I don't have a yard here.

0:06:05.540 --> 0:06:10.659
<v A>Right, right. Can you fly RC airplanes at any kite flying zone or no?

0:06:13.080 --> 0:06:18.500
<v B>I mean, so it's a whole bunch of rules. And then there's like what's legal and what's nice.

0:06:18.940 --> 0:06:19.583
<v A>I see. So it's

0:06:19.583 --> 0:06:22.960
<v B>like if other people are flying kites, you probably don't want to.

0:06:25.159 --> 0:06:31.520
<v B>And then like when you get to a certain size and stuff, you're kind of supposed to get permissions and licenses and that kind of stuff.

0:06:31.599 --> 0:06:37.740
<v A>So you're saying I couldn't I shouldn't fly a drone with a Connect on it over my neighbor's backyard?

0:06:38.820 --> 0:06:41.700
<v B>I'm saying legally you probably could, but you might make them mad.

0:06:41.880 --> 0:06:43.719
<v A>Oh, I see. Unless I was Amazon.

0:06:43.720 --> 0:07:30.340
<v B>I think the FAA recently passed something like for non-commercial use below a certain level, like they said it was OK or whatever. Oh, really? You have to have—I think you have to have line of sight and below. I don't—I really can't remember now. But there's some ruling where, yeah, basically it's OK. But yeah, don't do it commercially. That's still not completely OK. And if it ever crashes in your neighbor's yard, they might not be very happy with you. Yeah, right. So the first news item I had was I came across this giant list. That's the only way I can describe it is a giant list of free programming books. So it's a GitHub site repository.

0:07:30.340 --> 0:07:36.760
<v A>I think it's a whole repository, but the repository is literally just a huge amount of links. Yeah.

0:07:37.020 --> 0:08:22.320
<v B>Yeah. I think it's just so people can like branch it and update it and make edits to it. I'm not sure why it's not a wiki. I'm not exactly sure anyways, other than like that. Other people could branch it and make their own alterations that they didn't want to necessarily share back. But it's got all the programming languages, different topics. And then under each heading, there's, you know, at least one or two books and some many more. And so some of the books are kind of like some guy wrote this. And then other ones are, you know, published books that just got permission to be released for free. But we'll post the link in the show notes, or you can search 'free programming books GitHub.' And it should come up. I would recommend you take a look if there's a topic you're interested in learning about.

0:08:23.060 --> 0:08:30.347
<v A>Yeah. If you search for 'GitHub books,' it's the fifth result, which is pretty remarkable. On

0:08:30.347 --> 0:08:31.800
<v B>your account.

0:08:31.800 --> 0:08:36.380
<v A>Oh, yeah. Well, let me try anonymously.

0:08:37.114 --> 0:08:41.400
<v B>OK, well, needless to say, you should be able to find it or you can just look in the show notes.

0:08:42.560 --> 0:08:47.610
<v A>You're right. It's actually the third result. If you search anonymous. Oh, that's like if

0:08:47.610 --> 0:08:55.840
<v B>you search Java, do you get coffee or the programming language? Well, it depends. If you're using Google, I guess it depends on what you also searched before.

0:08:56.340 --> 0:10:05.269
<v A>Yeah, that makes sense. Yeah. Cool. OK, so mine is pretty dorky, but I thought it was pretty cool. Basically, Russ Cox, who's one of the founding members of the Go, you know, Go language team. He decided to port the Go compiler to Go. So, originally they wrote the Go compiler in, I think, C or C++ or in C. And so he argues that the reason why we wrote it in C is because we didn't have Go. And so to back up that argument, he actually they wrote—I guess they wrote a program that transpiled C to Go. And that got them 90 percent of the way there. But then there were like Go-to's in the code and things like that, which didn't translate as well. You know, I just got to say, like if someone's inventing a language and they use Go-to's like that worries me. Like it makes me worried about using the language. But I do think Go is an amazing language, even though the person—wait, it's

0:10:05.269 --> 0:10:08.500
<v B>not. Wait, the Go had Go to's or the C had Go to's?

0:10:08.660 --> 0:10:12.220
<v A>Well, the C implementation of the Go compiler had Go-to's.

0:10:13.251 --> 0:10:18.940
<v B>Oh, was it auto-generated parts or did somebody actually write Go-to code?

0:10:19.140 --> 0:10:22.180
<v A>No, you said there are 1032 Go-to statements.

0:10:22.960 --> 0:10:28.380
<v B>I've never come across a Go-to statement in any C or C++ code I've ever looked at.

0:10:31.080 --> 0:10:39.060
<v B>No, I mean, like I see examples of it, like on the Internet. And I remember like in code that I've worked in and repositories I've worked in, I've never seen a Go-to statement. Not once.

0:10:39.199 --> 0:10:47.579
<v A>I have seen it very rarely, and it has always been terrible, terrible code. Like I've always looked at it and kind of just shook my head.

0:10:48.500 --> 0:11:11.079
<v B>Like I actually had a discussion with someone on my team about how we could avoid a lot of problems by using Go to. And they didn't even want to hear it. And I was, you know, it's generally, I guess, considered bad to use Go to. But like anything, it's just a tool and it got misused a bunch. And I think there are cases where it could be good if you use it right.

0:11:12.020 --> 0:11:21.420
<v A>I mean, I think that I used to agree with that. Unless you're using Java and you have finally. If you have finally, I don't think you need Go to.

0:11:23.900 --> 0:11:30.134
<v A>You know, like most of the time when I've seen Go to used, it's always been because—wait, does Java

0:11:30.134 --> 0:11:30.820
<v B>have Go to?

0:11:31.460 --> 0:11:46.420
<v A>No, they don't. Okay. But my argument is that if C++ had finally like a block of code that would execute, you know, no matter what happened, then that effectively is Go to in a sense.

0:11:48.180 --> 0:11:48.207
<v A>Like,

0:11:48.207 --> 0:11:48.460
<v B>Yeah.

0:11:48.620 --> 0:11:48.860
<v A>Yeah.

0:11:48.860 --> 0:11:59.980
<v B>So that's mainly the kind of thing I'm thinking of, like when I've come across it, mostly in C, not just C++. But in C, a lot of times you get this multi-path return, like you're try-catching without try-catch.

0:12:00.100 --> 0:12:00.360
<v A>Right.

0:12:00.520 --> 0:12:06.480
<v B>And it would be just more convenient instead of the convoluted copy and pasting they do to have a Go to.

0:12:07.240 --> 0:12:08.100
<v A>Yep. That makes sense.

0:12:08.880 --> 0:12:12.500
<v B>But what do I know? Nothing. That's the answer.

0:12:12.500 --> 0:12:42.920
<v A>I wrote a bunch of C++ and I'm kind of done with that language. I mean, unless I really have to. I just don't. I mean, unless we go back to doing, you know, like drivers for robots or something like that or, you know, image processing for robots. I mean, I don't really. I don't know. I just it just never seems to have the things that I want, you know. And then the build system, too, is kind of a nightmare unless someone's, you know, done a lot of infrastructure work for you and stuff like that.

0:12:43.120 --> 0:12:56.120
<v B>I used to only do C++ and I was happy and I thought Java was silly. Then I did only Java. And then I was like, OK, this isn't too bad. Now I'm doing C and I wish I could do C++ or Java. I don't really care.

0:12:57.920 --> 0:13:01.580
<v B>But I'm stuck with just C for now for what I'm currently working on.

0:13:01.782 --> 0:13:17.720
<v A>Oh, bummer. Wait, you can't even use C++? No. What? Wait, OK, so I got to know. So, I mean, without going into a lot of detail, like give me an example, like at a high level, like when I've never been in a situation where I couldn't use C++.

0:13:18.117 --> 0:13:20.513
<v B>It's just a severely resource-constrained

0:13:22.032 --> 0:13:22.605
<v B>situation, right?

0:13:22.720 --> 0:13:26.880
<v A>So, but I mean, even then, like they both compiled the machine language. What's the difference?

0:13:26.880 --> 0:13:57.940
<v B>So, part of it is I joined this team when they had already had a decent sized code base and they are resistant to switching to C++ or using any C++ because it is true. If you're not careful, you can have in our situation, the small amount of bloat that you would normally consider small would be very impactful. Okay. Okay. And I disagree. I think we have the space to spare. They disagree with me. So, we're stuck using C.

0:13:58.320 --> 0:14:46.760
<v A>Yeah. This is my argument against it, right? And I know I'm kind of preaching to the choir here, but it's, you know, when you use a language like C++, you can, because you're kind of working at a higher level, you can be more clever with the memory and not end up with a complete mess. You know, like basically like in C, you know, you can't, you know, like for example, with C++, you can do placement new and you can put objects in certain spots of memory, right? And so, I wouldn't feel comfortable doing like those kinds of hacks in regular C and trying to maintain it and keep it all in my head. But in C++, I could do it because there's, the language is rich enough that if I were to look at the code later, I would know what's going on, you know?

0:14:47.400 --> 0:14:52.560
<v B>Yeah. I feel like maybe my severely resource-constrained to severely wasn't emphasized enough, perhaps.

0:14:52.820 --> 0:14:57.730
<v A>Okay. Fair enough. Yeah. But yeah, check this article out. It's pretty cool. Oh, so

0:14:57.730 --> 0:15:00.840
<v B>Bootstrapping. Is that what that's called, right? Writing Go and Go?

0:15:01.500 --> 0:15:29.033
<v A>Bootstrapping? Yeah, I think that's what it's called. Yeah, yeah. So they actually, they were able to write Go and Go. And I always wondered about like how, you know, because GCC needs GCC to build. And I always wondered like if they go to a brand new machine, like someone invents a whole new architecture, I guess that person has to write a version of GCC and assembly. Yeah,

0:15:29.033 --> 0:15:38.060
<v B>That's cross-compiling, right? Yeah. You have to compile on one machine for another. You can compile for ARM on an x86 processor.

0:15:38.060 --> 0:15:46.532
<v A>Yeah, so if you go and invent the next one, like the leg processor to compete with ARM, then you have to write it. Oh, I get

0:15:46.532 --> 0:15:47.819
<v B>It. Ha ha ha. I see what you did there.

0:15:49.599 --> 0:15:58.380
<v A>Thanks. Thanks for that. Then you have to write the GCC in assembly or something. I don't know.

0:15:58.380 --> 0:16:01.140
<v B>No, I don't think so.

0:16:01.340 --> 0:16:01.620
<v A>Oh.

0:16:02.420 --> 0:16:26.620
<v B>You don't have to write all of it, right? Like a lot of it is common. You just the code generation part. And that's one of the LLVM, right? The other people is like one of the things they're working to make better is you have a bunch of front ends. And then you get into an intermediate language. And then you do a bunch of other stuff. And then at some, the very last step is you produce machine code. So only that part you would have to rewrite.

0:16:26.820 --> 0:16:30.300
<v A>Oh, I get it. And at that point, there's probably not that many instructions that you have to.

0:16:30.300 --> 0:16:33.239
<v B>Well, I'm not going to say it's not a hard job. It's just not as hard.

0:16:33.400 --> 0:16:37.880
<v A>Not as hard? No, right, right, right. All right. Cool. Learn something new.

0:16:39.239 --> 0:17:19.720
<v B>Our next article is about, I don't actually know how to say the name of this, the Litro camera. Litro? Litro. This is originally the one that looked like a large lipstick case camera. Okay. That was called a Lightfield camera. Anyways, the next version, version 2.0 or whatever, it's called something weird, is coming out. And it looks like a just kind of cool point-and-shoot camera instead of a very weird thing. And this is the one where you take one picture and it uses what they call Lightfield. But basically, it takes a whole bunch of different focused images all at once. And then later, it constructs where everything was in the scene. And so you can do refocusing.

0:17:20.740 --> 0:17:21.032
<v A>Okay.

0:17:21.360 --> 0:18:08.282
<v B>So this works kind of like, I think it's like the way like a fly's eye works, where it has many facets on it. And each one has a slightly different view of the scene. But then computationally, you can come up with, had you been at a given point and a given focus, what would the scene have looked like? Oh, nice. And so they take one picture, but the trade-off is you have less resolution. So because you're taking redundant pixels, pixels that have redundant information at some level, you lose megapixels. But you get this other information, this depth information. And so there's a whole bunch of neat effects you can do with it, like having a really shallow depth of field or having everything in focus or moving the focus around after the fact. And one of the, always the, I

0:18:09.835 --> 0:18:19.080
<v B>guess, two second explanation is you take an image and it's never blurry or it's never out of focus is what they say. It can be blurry because you can still have motion blur, but it's never out of focus.

0:18:20.600 --> 0:18:20.736
<v B>Which,

0:18:20.736 --> 0:18:32.660
<v A>Okay, yeah. But does it look weird? I mean, because it's sort of unnatural, right? Like if something was really close and in focus and then the whole background was also in focus, that might be jarring, right? Because your eye doesn't really work that way.

0:18:32.660 --> 0:19:38.780
<v B>So I did a little bit of looking at ways of doing strange pictures. So there's a lot of times when people actually do this. For instance, when you take product photography of like a watch, they'll do what's called image stacking. So they take a bunch of pictures at slightly different focus depths and then stack them all together to get a completely in everything sharp macro shot of a watch. You can see all the details. And it doesn't really look unnatural or when you have a scene of like a road stretching off into the distance, normally some parts of that would be out of focus because of the constraints of you would need an infinitely small aperture to have everything in focus, but infinitely small aperture means you have to have it open for a really long amount of time, infinite amount of time. So instead there's ways of shifting the plane of what records the image so that the part that's in focus is all the way along the thing that you're actually imaging. That was really bad in words. I don't know if anyone could follow that.

0:19:39.399 --> 0:19:40.639
<v A>I think I got it.

0:19:41.419 --> 0:19:55.680
<v B>So there are tricks and you can do them and they don't actually look that unnatural. Oh, okay. Because in your eye, you don't necessarily think of things being out of focus because whenever you look at is in focus typically.

0:19:55.920 --> 0:20:01.379
<v A>Oh, I see what you're saying. Yeah. Cause you're not really looking in your periphery like that clearly. It's not possible.

0:20:02.720 --> 0:20:18.720
<v B>So it's almost the reverse, right? The images that have the focus, like the depth blur, like things that are far away, the bokeh or whatever. It's an artistic effect to focus your attention on the thing that's sharp, but it doesn't necessarily look more natural.

0:20:20.200 --> 0:20:24.025
<v A>Gotcha. Cool. Cool. That makes sense. Anyway,

0:20:24.025 --> 0:20:34.860
<v B>So it's kind of cool. And it's interesting, like a long time people have known this light field thing and now they're actually making something that is a consumer device. So it's kind of cool to see.

0:20:35.139 --> 0:20:36.340
<v A>Yeah. Yeah. That's awesome.

0:20:36.700 --> 0:20:39.432
<v B>I'm really tongue-tied tonight. I apologize. Is it?

0:20:39.837 --> 0:20:44.309
<v A>Like when you say, is it like $4,000 or something ridiculous? I

0:20:44.309 --> 0:20:45.120
<v B>Think it's like 1,200.

0:20:45.860 --> 0:20:51.420
<v A>Okay. That's still pretty steep, but yeah. For camera enthusiasts, it's not too bad, I guess.

0:20:53.180 --> 0:21:23.159
<v B>I guess maybe it's the, it's oh, it's actually $1,600 and it's called the Elum. And they have some sample images. If you look online that you can actually move around in your browser. And it is kind of a bummer because you can't use your normal photography tools because it has a special format. But I, it's one of those things, I guess, like people call it the Tesla model, which is you sell the expensive niche thing to prove everything out. And then you bring the price down over time.

0:21:23.300 --> 0:21:30.060
<v A>Yeah. Right. I heard that the new Tesla, they're going to try to bring it down to like $3,500 instead of $90,000.

0:21:30.580 --> 0:21:32.120
<v B>Wait, $35,000?

0:21:32.220 --> 0:21:33.617
<v A>I mean, $35,000. Okay.

0:21:34.060 --> 0:21:34.400
<v B>Okay.

0:21:35.060 --> 0:21:40.300
<v A>Yeah. Yeah. So that'll be pretty cool. I think we'll see a lot more Teslas if that happens.

0:21:41.260 --> 0:21:49.640
<v B>Are you already starting that conversation with your wife? So I need to buy an electric car. It needs to be a Tesla.

0:21:50.500 --> 0:22:09.257
<v A>Yeah. I mean, our next car, because of the kids now have to be a minivan, the kid and the future kid have to be, has to be some kind of SUV minivan something. So they do have actually that, that Tesla Model X, which is supposed to be an SUV, but that's still

0:22:09.257 --> 0:22:10.100
<v B>Cheaper. Yeah.

0:22:10.240 --> 0:22:16.820
<v A>Yeah. That's still the $90,000 Tesla. So $35,000 Tesla is probably years and years in the future.

0:22:19.680 --> 0:22:29.102
<v A>Yeah. So yeah, mine, I have another news article. It's a hacks for everyday life. This is a pretty cool question on Quora. And wait, wait,

0:22:29.102 --> 0:22:32.540
<v B>You talked about this last episode, your core answering. Did you answer this one?

0:22:32.620 --> 0:22:37.439
<v A>That's right. I uploaded several answers on this question.

0:22:37.439 --> 0:22:38.580
<v B>But none of these are your answers.

0:22:38.580 --> 0:22:55.832
<v A>None of them are my answer. But I thought this was pretty cool. Actually the first one is like enhancing your Google Foo, which I thought was less cool. But some of them, like there's how to pack a suitcase and it's pretty amazing. I mean,

0:22:55.832 --> 0:23:17.239
<v B>Have you ever tried these? I've tried these, like how to pack a suitcase. Yeah. It never works like they show in the pictures. Like having these, having these little like rolling it up in a special way or putting it in special smaller bags. I've never, my stuff always ends up being wrinkled and I end up at the end of the trip, just everything's thrown in there. Cause it seems to work just as well.

0:23:17.240 --> 0:23:49.208
<v A>Oh, there's two answers, both on how to pick fruit, which is personally something I struggle with. I always seem to like, just re I randomly pick fruit. And sometimes like the mangoes I get from the store, sometimes they're great. Sometimes they're dry. Sometimes they're like, they're overly ripe or not ripe enough, whatever. And so it's just like a few very simple rules. Like for example, for strawberries, I guess how much, however much they smell tells you sort of how much taste they'll have. So if they don't have a lot

0:23:49.208 --> 0:23:53.439
<v B>of smell, like if you ever smell the smell of like a ripe strawberry, it makes you really want to eat one.

0:23:54.320 --> 0:23:59.029
<v A>Yeah. I mean, these are things I just, I guess I was always in a hurry and never like stopped to smell the roses. I

0:23:59.029 --> 0:24:07.159
<v B>Always smell stuff, and people always think I'm weird. Cause like I'll get food and then like I'll, you know, hold my face down to like smell it. Not like weirdly. I don't think.

0:24:07.500 --> 0:24:11.780
<v A>Not like, not like, uh, the guy from Lord of the Rings. You're like precious.

0:24:12.879 --> 0:24:14.540
<v B>Oh no. Wait, what?

0:24:14.760 --> 0:24:20.860
<v A>Who is that guy? What's his name? Totally drawing a blank. Gollum. Yeah. Yeah. Yeah. Not, not very Gollum-esque strawberry picking.

0:24:21.140 --> 0:24:26.000
<v B>No. Anyways. But yes, I do. I noticed that. So I, I really like smelling my food. I don't know.

0:24:26.700 --> 0:25:28.180
<v A>Yeah. I mean, and also for, um, citrus, they said to go by weight. Like if the grapefruit is heavy, that means there's a lot of juice in it. So, I mean, again, it's like, it makes sense, but it's one of these things that like, if you don't think about it, you're never going to do it. Right? So just someone needs to like educate you and all of a sudden you're like, Oh, all right. So I'll look for the heaviest grapefruit and be done. Um, also there's this, this cool answer. You know, those, um, you know, those, uh, boxed milks, like, uh, like not the ones like in the carton, but the ones in actual box, like the rice milk and stuff like that. So this guy has this post where basically if you pour it with the nozzle facing down, which is the most intuitive, then, you know, air can't get out and it makes it very hard to pour. But if you pour it with the nozzle, you know, on the top of the carton coming out, then the air always gets a chance to go in. I don't know. It's just kind of random things like that. I thought they were pretty cool. Yeah. Okay. I'm going to try that. It's literally just pages and pages of these random things. So, so

0:25:28.230 --> 0:25:31.000
<v B>Which one have you used the most since you read this?

0:25:31.825 --> 0:25:51.580
<v A>Well, uh, I read this yesterday, so, so none, um, yeah, none of them, but, uh, but we'll, we'll see. Hopefully I, I, uh, actually in May, you know, I'll be able to travel, you know, I'll maybe eat some citrus and, uh, and, uh, you know, pour some rice milk or something, get it all out in one, in one, in one day.

0:25:52.659 --> 0:25:55.480
<v B>So Jason hacks his life. Stay tuned.

0:25:55.820 --> 0:25:56.699
<v A>Yeah, that's right.

0:25:57.914 --> 0:25:59.219
<v B>Time for a book of the show.

0:25:59.659 --> 0:26:23.800
<v A>Book of the show. So this is a total shameless plug. I should feel terrible about this, but I co-wrote a book that is now hitting the shelves. It's called HTML5 Game Programming Insights. I wrote it with a Colt Mechanis and a bunch of other people. And I wrote the chapter on network programming. Hey, your name's

0:26:23.800 --> 0:26:24.820
<v B>on this page.

0:26:25.520 --> 0:26:28.060
<v A>What the front page? No, yes.

0:26:29.659 --> 0:26:48.600
<v A>So if you guys are interested in writing games for the web, definitely check it out. There's a lot of really sharp people who've contributed a lot of work into making this book awesome. I really, you know, it has a lot of authors, but I really like that because.

0:26:48.699 --> 0:26:55.400
<v B>Yeah. So I was going to say, how do you feel about being an author of a published book? And then how do you feel that you have to share the cover with like, it looks like a dozen other people.

0:26:55.620 --> 0:28:16.300
<v A>Yeah. So each person wrote a chapter and there is, I think 12 or 13 chapters. So there's a lot of authors, but the good thing is, you know, I feel like most of these books, you really can't write a whole book. You know, the reason is the person who's going to write an entire book on say, I don't know, Hadoop or something like that. It either is going to take them years and years, in which case the book is already kind of dated, or they don't really have like a job, or they're maybe they're on sabbatical or something, in which case, like they're just really crunching through the book and not really giving it the attention it deserves. Right? So by having each person write a chapter, I was able to focus on something I'm really passionate about, which is network game programming. And two to like, you know, I could spend a lot of time on it because it was one twelfth of a book and not, you know, 400, 500 pages. Congratulations. So, yeah. So I think it turned out really well. I've read a few of the other chapters. I'm a big fan. And, you know, in general, the cool thing about web games is that it's very easy to just give the link to your friends and family. And, you know, versus like if you were to make it on Windows or on the phone or something like that, then you have to go through a whole bunch of drama to deploy it and things like that.

0:28:16.580 --> 0:28:19.460
<v B>So will you be rich and famous by the next time we talk to you?

0:28:19.460 --> 0:28:35.982
<v A>Well, you know, considering I'm splitting a small percentage of the royalties with 12 other people on a niche book, I highly doubt it. But I think I am definitely more educated on HTML5 than I was before. We will be

0:28:35.982 --> 0:28:41.145
<v B>talking to you next episode of Lifestyles of the Rich and Full of Authors. Yeah.

0:28:42.140 --> 0:28:51.760
<v A>I'll be talking to you with HTML, in HTML. Hashtag. Or no, closing tag. Hashtag.

0:28:52.200 --> 0:28:54.860
<v B>Wait, you wrote a book on HTML?

0:28:55.220 --> 0:29:12.620
<v A>You know, I've heard the word hashtag so much more frequently than closing tag that it just took over. Okay. But yeah, so definitely give it a check. And, you know, let me know what you think. Give me some feedback. If you find bugs or typos, let me know. Okay. Yeah.

0:29:13.380 --> 0:29:15.975
<v B>Mine is a book that I wish I wrote. Does?

0:29:15.975 --> 0:29:19.520
<v A>That count? That counts. You get royalties for that.

0:29:19.980 --> 0:29:35.540
<v B>No, I do not. This is called The Martian by Andy Weir. Where? I don't know. Andy. And this is basically, I think, I won't try to, I'll try not to spoil anything. But I think the back cover says it's basically Robinson Caruso on Mars.

0:29:35.780 --> 0:29:36.560
<v A>Oh, nice.

0:29:38.480 --> 0:29:53.185
<v B>But that's only like a vague, like, don't think too much about that. Or you might have a missed expectation about what the book is about. So, you know, basically like a guy surviving where it's otherwise unexpected that he would survive. Isn't that similar?

0:29:53.185 --> 0:29:55.900
<v A>To The Abyss? The movie The Abyss?

0:29:57.480 --> 0:29:58.980
<v B>I've not watched that. I don't know what that is.

0:29:59.200 --> 0:30:02.179
<v A>Oh, basically in The Abyss, this guy. Don't spoil.

0:30:02.179 --> 0:30:04.380
<v B>It. Wait, I might should, I might should watch it, read it.

0:30:04.480 --> 0:30:16.560
<v A>No, no, I won't spoil it. But basically, you know, he goes into The Abyss, which is like a very deep trench. And he ends up there for a long time, which you just wouldn't expect. And so it sounds like it's kind of similar.

0:30:17.300 --> 0:31:07.100
<v B>Maybe. So the guy on Mars and what happens. Okay. And so it's really cool. It has a lot of science in it. But it's kind of one of those dangerous books where there's a lot of science that makes sense to my head. But I don't actually know if it's true because it's a fiction book. Oh, right. So like you ever do that? I don't know. I read a lot of science fiction. And then until like I have contradicting evidence, I kind of just like have this bit of information in my head that I learned from a fictional book. Yeah, oftentimes it turns out to be true, right? Like somebody will write about something about black holes. And it turns out that thing is actually true about black holes, except that there are no actual black holes anymore. But it'll turn out to be true. Like later on, I'll find out. But then other things, I have no idea if they're true or not, because I just read it in a fiction book. But it sounds good to me.

0:31:07.340 --> 0:31:29.980
<v A>Yeah, yeah. This happens when you read a fiction book and it starts off, you know, in the present or something. There's a bunch of, you know, common landmarks. Everything seems pretty legit. And then, you know, by the end of the book, there's like aliens and orcs and dwarves are fighting each other. And it's like, well, somewhere in between there, it became fiction. But you don't really know how where that gradient is.

0:31:30.840 --> 0:31:42.719
<v B>Yeah, that's true. Like stuff will take place in like a city. And it's like, I know it's a valid city, but I've never been there. Or and so I'll mention stuff that I know are like actual places there. And then I just assume everything they mention is actually there.

0:31:43.620 --> 0:31:44.020
<v A>Right.

0:31:44.864 --> 0:31:45.657
<v B>And so, anyways,

0:31:45.657 --> 0:31:46.820
<v A>It's kind of dangerous, including the Orc Capital.

0:31:47.500 --> 0:31:56.693
<v B>Yes. Including the giant castle with heads on pikes. Yes. Yeah. In Chicago. But anyways, I recommend this, The Martian. It's not that long of a

0:31:56.693 --> 0:32:01.820
<v A>book. That's in Detroit. So there is definitely a fiction book because what you described is in Detroit.

0:32:02.340 --> 0:32:16.200
<v B>Oh, okay. But The Martian by Andy Weir. I recommend it. It was a really fun read. And it was kind of nerdy, whether or not the nerdiness was true or made up. The guy either spent a lot of time doing research or he's just really creative.

0:32:17.060 --> 0:32:28.452
<v A>This is great. You know, when you recommended Ready Player One, I immediately read it because your description, I just knew I was going to love that book. And I did. It was great. And I definitely will read this book. You should definitely

0:32:28.452 --> 0:32:35.280
<v B>read this book. It's not that long. It's really good. And it has also cultural references to like '70s TV shows.

0:32:36.220 --> 0:32:39.032
<v A>I probably won't get any of those, but I'll read the book anyway. I didn't either,

0:32:39.032 --> 0:32:40.260
<v B>but I knew that they were there.

0:32:40.480 --> 0:32:46.080
<v A>Oh, okay. Fair enough. Unless the '70s TV show is like Price Is Right or something like that.

0:32:47.320 --> 0:32:53.260
<v B>Yeah. I don't remember what they were now, but yeah, something. Anyways, time for Tool of the Show.

0:32:53.320 --> 0:33:29.520
<v A>All right. Tool of the Show. My Tool of the Show. I can't believe that we haven't talked about this before. But it's VirtualBox. And VirtualBox is amazing. If you haven't used it, if you haven't downloaded it, just right now download it. We have this situation where I'm at work. We have this server. And we don't have a compiler on the server. So we figured out what OS it was running. And then using VirtualBox, we built... What was that?

0:33:31.100 --> 0:35:12.240
<v A>Oh. Using VirtualBox, we built some source code. Like we compiled some source code into binary on like in this virtual PC and then sent it over. So I'll explain VirtualBox briefly. It's kind of like an emulator, like those video game emulators for Nintendo and things like that. But it emulates your own computer. So in other words, like it emulates, you know, an AMD 64 or x86 or whatever architecture, which is what you're running right now on your desktop or laptop. And it even hooks in like if your BIOS is new enough, it'll, you know, do some cool stuff there where it makes it really fast. And it can even like use your graphics card and stuff like that. So, you know, you might be running, say, Windows. You might want to try out Linux, but not, you know, have to go and buy a computer. And then now you have two computers sitting around your house or whatever. So you install VirtualBox and then you create a brand new computer inside of your computer, the virtualized computer. So it has its own hard drive, which on your computer is really just one file, like on the what they call the host computer. But then this sort of parasite computer has its own hard drive, its own like sound card, all these things, but they're all fake. But they all work. You can even like access the Internet. You can do everything you can do on your main computer. So one thing that I use this for is when I'm building new versions of Mamehub, which is this emulator that I'm emulator open source project that I work on. When you

0:35:12.240 --> 0:35:13.380
<v B>build an emulator in an emulator?

0:35:13.680 --> 0:36:23.640
<v A>That's right. So I need to build it for Windows, Linux and Mac. And even like the one I build for Windows, I want to make sure it runs on just native Windows. And same for Mac. Like I don't want to just if it builds on my machine, I might have all sorts of crazy libraries and some ridiculous setup or whatever. You know, I copy it over to someone else's Mac. It doesn't work. So I have a VirtualBox guest machine for every OS. And then I launch all of those. I can actually launch all of them at the same time. And now I'm sitting and I have a window for every possible OS. And in each of those, I have, you know, the code, which I can update, build and then deploy. So it's pretty cool. I mean, also, you know, let's say you want to test things, you know, on just regular Windows or regular Mac or what have you. And you want to make sure that like this website or whatever you built still works on your friend's computer. But you could just have a virtual computer which doesn't have anything on it. It's just completely bare. And go to your website on that computer and see what happens.

0:36:26.400 --> 0:36:29.393
<v A>So it's pretty amazing. What is that called? That's

0:36:29.393 --> 0:36:37.840
<v B>called something. I have a specific name for when the instructions run on the CPU you're on, but everything else is virtualized. But I forgot what it's called.

0:36:38.820 --> 0:36:47.420
<v A>Yeah, it's like VTX or something like that. That's like the BIOS setting. I don't know. Yeah, but you're right. There is a term for it.

0:36:47.420 --> 0:37:01.260
<v B>Because there's like emulating a Super Nintendo, which has a different processor. And then there's like allowing the instructions to actually run, but having just enough hooks. So anytime it calls a system call, you trap it and you switch it out for something else.

0:37:01.840 --> 0:37:05.500
<v A>Yeah, right. Yeah. Crap, what is that called?

0:37:05.580 --> 0:37:09.809
<v B>It's okay. It's been bothering me the whole time you've been talking. Yeah, there's

0:37:09.809 --> 0:38:00.500
<v A>recompilation, which is that's the first case. So recompilation is where, you know, there's code that's been compiled for like the Super Nintendo. And you recompile it. You turn their machine code into your machine code. But then the other one where it's already your machine code, you just need to catch certain instructions. I forgot what that's called too. Anyways, VirtualBox does that. It's not like QEMC or one of these other ones, which run like painfully. So like if you use the Android emulator, actually, it's a lot faster now because they do what we're describing. But the original version of the Android emulator actually recompiled all of your instructions from ARM into x86. It's just brutally slow.

0:38:02.060 --> 0:38:05.520
<v A>But yeah, VirtualBox, it's fast. It does everything you want. It handles graphics.

0:38:05.520 --> 0:38:10.060
<v B>Does it work better than like, what is the other one, like VMware or Parallels or?

0:38:10.740 --> 0:38:39.420
<v A>So it's free and it does everything I want. So I've never tried any of the other ones. But yeah, I mean, it used to be that VMware could do some things that VirtualBox couldn't. I know now like they're pretty much even. Like VirtualBox, I think the direct 3D support is still experimental, which just comes down to you have to check a box saying that you want to do this experimental feature. But yeah, I've yet to find something I couldn't do in VirtualBox.

0:38:41.420 --> 0:38:43.860
<v A>Very good. Yeah. It's good times.

0:38:43.860 --> 0:39:27.640
<v B>My tool of the week is BitTorrent Sync. Okay. So people have issue with the BitTorrent, which is like a protocol, but also a company or whatever, right? I think. Anyway, so the company BitTorrent made this sync product. And it works on the same basic premise as regular BitTorrent. But instead of downloading from the cloud of BitTorrent users a file of the newest version of Linux only—that's the only thing you should use it for—you can basically do that with yourself. So it's Dropbox implemented with the BitTorrent technology, is an easy way to say it.

0:39:27.640 --> 0:39:36.960
<v A>Oh, I see. So if my mom has this running and I have it running, we can share our pictures. So if one of our houses burned down. That's right.

0:39:37.040 --> 0:40:57.120
<v B>And it doesn't rely on central servers. So it's just all distributed. And it's easy to set up. I can't vouch for the security of it. I don't use it for anything that's sensitive or secure or any of that. But I do have a computer. I have two stories in my house. I actually have three stories in my townhome. Before people get all excited. Anyways. And so like my garage, I actually have a computer in my garage because I use it when I'm working down there. And a computer in my top floor where my office is. And I want to synchronize between them without a USB drive. And so I use this because there's files I want to be shared back and forth between them. And so I can run it on both computers, and then the directories are kept in sync. And I don't have to worry about size limits. I can have multiple different ones running. And I don't have to worry about accounts. And the way you actually set it up is really easy. There's this thing they call a secret, which is a—I forget how long, like a 64-character string hash basically. And when you create a share folder, it gives you a hash. And then you can share that hash on other computers. I just email it to myself, and then you can share it to other computers. Put the hash in there, and then it'll start synchronizing to that. And anyone else who puts it in, even a stranger, would also start sharing to that folder.

0:40:57.680 --> 0:40:59.920
<v A>Oh, I see. But there's so many possible numbers.

0:41:00.160 --> 0:41:03.122
<v B>Yeah. So I think the chance of that happening is really low. Security by

0:41:03.122 --> 0:41:04.574
<v A>anonymity or something like that.

0:41:04.740 --> 0:41:33.240
<v B>Anonymity, yeah. But it also does show you like when someone's syncing and what other computers. So you would know if like, if you were watching, I guess, when it was happening or look in the logs, you'd be able to see like, oh, someone else accidentally collided with me. But I think it's probably long enough where statistically is very unlikely to happen unless someone was hunting and then using a lot of computers to hunt for active hashes or whatever.

0:41:34.358 --> 0:42:00.632
<v A>You know, this always fascinates me, like the idea that there's a one in a, you know, whatever, a billion or a trillion chance that I get like all of, you know, some like really important documents. I feel like this is a book waiting to happen, you know, like some kind of thriller where it's like you mistype your BitTorrent Sync secret and all of a sudden you get real NSA secrets or something. But this

0:42:00.632 --> 0:42:25.759
<v B>was like a King of Queens episode, I think, once. And it is intriguing where it's like they go to the—is it them? No. What? I'm trying to remember if it's that or another show. Some show, I forget. And they go to the—get film developed and they pick up their pictures and they accidentally pick up someone else's pictures. And then they start living vicariously through those people's lives, basically.

0:42:25.760 --> 0:42:26.519
<v A>Like they keep doing.

0:42:26.519 --> 0:42:33.820
<v B>it, and they want to keep finding out who these people are and why they're so much better or whatever. And more interesting and doing cool things.

0:42:34.920 --> 0:42:40.035
<v A>Oh, man. That's awesome. So. All right. Good times. Well,

0:42:40.035 --> 0:42:42.640
<v B>time for the topic of the show: Design Patterns.

0:42:43.040 --> 0:43:12.220
<v A>Design patterns. So, yeah, basically, at a high level, design patterns are sort of these like communal, agreed-upon, you know, good strategies when you're programming. And generally, although some of them are a little bit specific to certain types of languages or certain paradigms, but generally they apply to almost any language and almost any, you know, task that you're working on.

0:43:14.320 --> 0:44:10.220
<v B>Yeah. I think design patterns, when I first got introduced, people were always like, oh, they're so revolutionary. I don't know. It was such a big deal when they first learned about them. Yeah. And I didn't have that same experience. What it is to me is just kind of like things you, if you've been programming for any length of time or seen other people's code, you've probably seen at least most of the ideas. But it's just a way of making it concrete and like saying by understanding it and giving it a name—a pattern—you'll recognize it. And by recognizing it, you won't, you can reuse code because you already know how to do it or you can not fall into the traps that you know are likely to happen with that pattern versus just, you know, kind of the wild west of coding where you just code whatever you want and reinvent it every time you need to do something. Right? And so it's just a way of codifying, codifying these ideas and giving them names and a common language for people to talk about.

0:44:10.980 --> 0:45:15.259
<v A>Yeah. I mean, the common language is really important. I mean, there's, you know, it's sort of like this is true with programming contests. You know, so I did a lot of programming contests back in college, and the people who write the questions are usually ex-competitors, right? And so you end up with this, with this like gnosis, this common language that's built up through the years. And like the coaches are also problem writers or also former contestants, and it just kind of feeds on itself. And you have to sort of, if you're not sort of in the click, then, you know, you could be brilliant, but you won't be brilliant in the same direction. And there won't be enough overlap in what you know and what, you know, the judges or the problem writers know. And you just won't do well. And so this is one of these things with programming where, you know, by learning these ways of doing them and knowing where to, when to spot them, it will sort of like make it easier for you to integrate yourself in the ecosystem.

0:45:16.500 --> 0:45:36.700
<v B>Yep. They're not magic bullets. A lot of people think like, oh, I'll just use a design pattern and it'll fix my problem. Maybe. I don't know. Probably not. But we won't try to cover all of them because we would only be able to do a not enough good, helpful things about it. So we're going to try to cover only a few.

0:45:36.700 --> 0:45:37.307
<v A>and maybe we'll

0:45:37.307 --> 0:45:38.400
<v B>have a design patterns too later.

0:45:38.700 --> 0:45:50.500
<v A>Yeah. If you like this episode, then, you know, go and check out the Wikipedia page on Design Patterns because there's a ton of them. But we're mainly going to cover ones that we have practical experience and stories to share and things like that.

0:45:50.680 --> 0:46:19.840
<v B>Yeah. And, you know, some of them, especially we'll talk about the first one in a second. I've seen people overuse like it was like it caught on and it was fashionable. And then I saw people use it in, you know, a way to excuse bad behavior. Almost. They were doing something bad. They did this thing instead. And then because it's a design pattern, they're like, oh, but it's a design pattern. And it's like, yeah, but you're still doing the bad thing. You just labeled it. So with that transition, we'll talk about the Singleton.

0:46:21.900 --> 0:47:53.120
<v B>So the idea of a Singleton is, I guess, kind of what it sounds like. You want a single something, only one of a thing. So one instance of a class. And no matter if people try to create new instances, they should just get back the same instance. So people are just getting kind of the same reference to the same object. And so this has a lot of useful applications. And as I was alluding to, in recent years seems to have gotten a lot of bad uses as well. So one thing that it's really great at is if you have a class and you want to share data amongst all parts of your applications. So, for instance, if you had a file handler for a log and you wanted to be able to write to that log from your error handling system. But your error handling system gets errors from all over the place or whatever. And you may have different instances of error handling. But they all want to append to the same log for whatever reason. You could have a Singleton object that represented the log. And anybody who asked for a, hey, I want an instance of the log, would get the same shared instance, just one file. But everybody could pass information into it. That doesn't mean it's automatically multi-thread safe. So that's a separate topic. But everybody would at least know what file was going to be written to. And then could kind of handle separately how to write to it in a safe fashion. But that's something you might want to share throughout an application and pass around.

0:47:54.130 --> 0:48:46.820
<v A>And so, go ahead. Oh, yeah. The nice thing about a Singleton, too, is if you have just global variables sitting around somewhere, which would be sort of alternative to this, then you never really know when they're initialized or not. But the thing about a Singleton is that, you know, by design, when you say, you know, get instance or get Singleton or whatever function that you want to call to get your Singleton, it can check and see if the Singleton is initialized. And then depending on how your logic is set up, you can either error if you try to use it too early or you can initialize it on the fly. But, like, as opposed to just some variable, some number that's sitting out there, this will sort of let you know at what state the Singleton is in. Because often, like, one of the hardest things to do in writing an app is you get a very complicated app to start correctly and in the right order so that nothing blows up.

0:48:49.220 --> 0:50:11.220
<v B>Yeah. So, some people do use it. So, like you mentioned, kind of lazy initialization. So, it's not initialized until someone actually needs it. And that can be good that, like, avoiding code at, you know, when the initial app, different languages and models have different stages. So, speaking generically, it's not until someone actually goes to use the thing that's a Singleton that it actually runs the part of the code that does the initialization. So, before that, it just kind of sits there and doesn't initialize all its variables and its state. And so, that can be really helpful if it needs to do something expensive. But doing something expensive at an unknown time in the future can also be dangerous. Right. Exactly. So, that's not good. And then Jason mentioned global variables, which is one of the things I've seen people. So, a lot of people have begun to understand that global variables are dangerous because it's a way of, it's very difficult to keep track of who's changing what. And so, a lot of pieces of your code may change something that's a global variable. And then if it gets into a bad state, it's hard to tell who changed it amongst other problems. And so, I've seen people, one of the bad uses of the Singleton is to basically have these global variables that are modified from everywhere and just stick them in a Singleton instead of leaving them as global variables. And I don't think you've made the problem much better.

0:50:11.640 --> 0:50:12.120
<v A>Right.

0:50:12.120 --> 0:50:18.460
<v B>You've made it easier to share around the global variables, but you haven't made it less likely that you'll hurt yourself.

0:50:19.600 --> 0:50:20.859
<v A>Yeah, exactly. Exactly.

0:50:23.500 --> 0:50:56.620
<v A>Cool. Yeah. I mean, definitely, you'll see Singletons everywhere you go. You really can't avoid it because there's almost always, like, whether it's some kind of hardware component or, as Patrick said, some kind of logging, so it's tied to a file, to a single file on your computer. There's almost always some part of your code which is, you know, is tied to either, you know, database, what have you, which, you know, there has to be only one copy of that shared by many different clients. And so, the Singleton's an easy way to sort of get that to work right.

0:50:56.620 --> 0:51:02.859
<v B>And the Singleton does get used in a lot of the other design patterns as well because they want only one of something.

0:51:04.380 --> 0:51:09.480
<v B>Right. And that's how you kind of do it. So, design patterns can be used in other design patterns. Shocker.

0:51:10.500 --> 0:51:11.740
<v A>Recursive design patterns.

0:51:13.660 --> 0:53:04.320
<v A>Yeah, so, one that I really like is Facade. So, you know, imagine this, right? You're writing some app and you, you know, want to have some kind of database for your app. So, you could do some kind of, like, HBase or Cassandra or, and actually, we're going to have a show on databases later. But, but for now, just, just take this at face value. You could use one of these really, you know, distributed, you know, fault tolerant, one of these, like, very, like, robust databases. But it's a huge pain to set up and it's kind of a nightmare. You know, if you don't know what you're doing, especially if you do a lot of initialization and all this stuff. And, you know, the reality is you might not need that. Like, your, your, your website or your app or whatever. You know, it just, it might not need that kind of a sledgehammer. You might be fine with just storing everything on a file on your computer, right? So, whenever you have this kind of situation, like, you're stuck with, there's several options, right? You could either say, well, you know, to account for growth, I'm going to, you know, you know, use HBase or one of these things. And, you know, spend days setting it up and maintaining it and things like that. But you can go to the other end and say, I'm just going to put everything in a single just text file. All my data, all my user data, everything will be in a text file. And I'll load it all into memory when I start up the server. And then what will happen is that will get you by. But then all of a sudden, you know, your app makes it on SlashDot or, you know, in the front page of Hacker News or something like that. And all of a sudden, your website completely blows up and, you know, it's going to take you months to rewrite your whole website so that you can, you know, use HBase or one of these things. And now you're really in a struggle.

0:53:06.040 --> 0:55:03.240
<v A>So, another thing you can do, and you have to make these kind of decisions—there's many, many times you have to make decisions like this for various, you know, parts of your app, is to create a facade. So, create some library where, you know, in this case, thinking about in terms of a database, create some library where you can give it data in some format. And then it will have sort of several backends. So, you know, it might be that, you know, anytime you write anything, anytime your app has to write anything that needs to stick around, you know, that needs to go to disk or something like that, it writes, it goes through your library and then to this other, to the hard drive. So, there's something in between, you know, the thing that opens the file and reads it. There's something in between that and your code, which needs to get and store data. Then, if your app becomes really successful, you know, that middle layer can just call, you know, a different database. Instead of, like, reading from the file, it can read from MongoDB or Cassandra or something like that without having to change all of the stuff above it. So, this is an example of a facade. So, there's one open-source library I wrote a few years ago that I still use today called ZombieDB. And it's literally just a facade for a bunch of these databases. So, at the time, I didn't really know which database I wanted to use. And I didn't want to do a bunch of coding only to find out that I have to redo it all. So, I created this facade. And generally, when you have these kind of things, whether it's, like, databases or some kind of, like, networking or any kind of, like, library where you don't have the source code, you know, or anything kind of really complicated that, you know, you might have the source code, but you'd never want to look at it, you know, like Hadoop or something like that, where it's, like, you just, you know, cross your fingers and hope it works.

0:55:03.660 --> 0:55:12.180
<v A>Anything like that where you have options and you're not sure which option to choose? A facade will let you choose all of the options at once. And what could be better than that?

0:55:13.560 --> 0:55:16.879
<v B>Choosing all the options at once—yes. Always the right option. Yeah.

0:55:16.879 --> 0:55:43.660
<v A>That's right. When all else fails, choose everything. I mean, of course, on the downside, you know, the onus is still on you to connect your facade to each of those backends. And that could end up being pretty time-consuming. But, you know, and again, you can do that in a lazy fashion. Like, your facade could just connect to one backend. And then, you know, later on, if you need a second one or you want to explore a second one, you can do that.

0:55:44.660 --> 0:57:42.960
<v B>Nice. Nice. The third one to talk about this episode is the Observer or Publisher-Subscriber design pattern. And this one, it's kind of obvious, I guess, at some level. But, you know, I think a lot of people miss opportunities where you could use it because they feel like it's too expensive. Because it sounds a lot like message passing or queuing, things which can get expensive. But it doesn't have to be. All it says is, you know, you have something that wants to observe something happen in another class. And you need a way to register that and then for it to get notified when that thing has happened. So the actual keeping what things need to be notified can just be, you know, as simple as a linked list or an array. Or, you know, it doesn't have to be complicated. It's actually like a full-blown queue or message passing. And this is really useful for if you have different parts of your system that, you know, kind of create events and don't know who necessarily—you don't want to hard code that, like, hey, my—I'm trying to think of a good—so my device. So I have a device driver, right? And at some point I have—oh, here we go. I have a robot, and I have a laser scanner. So at some point, which can change over time, my scanning of the room is complete. And I have an image of the room, a bunch of distances that my laser rangefinder has found. And it gets—it's complete. But I don't—nobody may currently—the robot may be in, like, a not moving stage or not care stage or still processing the last one. So nobody may care at this time that, hey, I finished scanning the room. Here's my data. And as writing the device driver for that, I really shouldn't have to care if—wow, that's too many cares. I shouldn't have to worry about if anyone cares about my data or not. I simply just finish making the data. And then, you know, I kind of delegate to this piece of code that goes and says, 'Hey, who currently needs to be notified?'

0:57:43.220 --> 0:58:16.142
<v B>And anyone who needs to be notified, I notify them. And then they can take appropriate action. And so that's kind of the basis of that design pattern. And it is useful in a lot of places because that notion, like I said, I don't have to worry about when I'm writing my piece of the code. I don't necessarily worry about who else is listening or having to have a hard-coded list of here's to notify that needs to change and it needs to be maintained. And then when I add something new that needs to be notified, I get to go add it to 100 different places. Yeah, I mean, this saves

0:58:16.345 --> 1:00:05.799
<v A>—that turns into a mess. Yeah, exactly. This saves, like, a gigantic headache. I mean, I used to not know about this, like, when I started. And it ended up with a nightmare. It's like, for example—because there's all these cascading effects, right? It's like, you know, I was making this video game. And it was like, okay. So I pushed this person. It was like one of these, like, tactical games. Like, it was kind of like chess. But, you know, there's pieces I can move around. It's like, okay, I pushed this piece. And now the piece got pushed to a place where he's not on solid ground. Like, he's, like, floating. Got pushed off a mountain or something. So he has to fall. But then I need to, like, show an animation of the falling. And then every turn they need to fall a little further. There's just, like, all of these, you know, nested effects. And then eventually what would happen is invariably, you know, they would fall. And somehow that would cause the first player to get experience. So I tried to add to the experience. But I was already in the context of the first player. So it caused some kind of deadlock. And the whole game would crash. And I realized that, you know, trying to handle all of the side effects of your code just by calling the appropriate function just leads to a complete mess. It's just a complete nightmare. I mean, if you find yourself, you know, 15 levels deep in function calls, that's a bad sign. And so this Pub/Sub lets you say, look, you know, it doesn't have to happen right away. And most of the time that's true. You know, so just say, this guy got pushed off a mountain. So the next time I have a chance, he needs to get hurt and fall off the mountain or something like that. But it doesn't have to happen right now, you know. So the idea of sort of separating, you know, the time of that you're presenting to the user. And this is true whether you're doing a game or like an email system or what have you, right?

1:00:06.100 --> 1:00:24.620
<v A>Like separating, you know, the time that, you know, the ticks upon which you present things to the user from the actual flow of your code is really important. And just knowing that you can make several passes through your code before you show, you know, output to the user gives you a lot more freedom.

1:00:24.820 --> 1:01:16.420
<v B>And there are some dangers, right? So like I said, you know, if I'm going to notify a bunch of people that my laser scan of the room is complete, that probably requires a lot of processing to handle. And I might call several people who are several people—wow, several other classes that are interested in that that may want to do heavy processing, right? And without care, I could synchronously be doing that every five seconds when I finish, right? So it's relatively slow once every five seconds. And then it needs to do a lot of processing. And that could delay the system. But the things you notify don't have to process right away. It could simply be that they need to know that next time that they get their time slice to process, that they have something that they have to handle. Like, 'Oh, hey, this thing now has data and it lives at this address. So you should go read it.' Right? And that's something that you have to take into account as well.

1:01:17.300 --> 1:01:53.560
<v A>Yeah, I mean, the downside of Pub/Sub is exactly the same as the upside, which is, you know, things don't happen immediately. So, I mean, they happen whenever the subscriber, you know, reads the next message. And so if as a publisher, you know, you publish some data and then you immediately expect, you make assumptions about that. You make assumptions that the subscriber has read your data, you know, when that might not be true. That's a place where you can get burned, right? Yeah, if you're not careful.

1:01:53.560 --> 1:02:01.299
<v B>Yeah. So that's why I was saying, like, you might make it the responsibility of the callers. If they need this data, they have to copy it out when they get the notification.

1:02:02.560 --> 1:02:03.319
<v A>Right, right.

1:02:03.567 --> 1:02:11.532
<v B>Yeah. So you just got to be careful how to handle it. So we are not the first people to talk about design patterns, obviously. This is an established field at some

1:02:11.532 --> 1:02:12.342
<v A>level. So we

1:02:12.342 --> 1:03:03.379
<v B>have some resources for you if you're interested. People who cover this topic in far more depth, more eloquently and with more knowledge than me, at least. And so the first one is the kind of, I guess, most famous, at least it's the one I first heard about. And it's, I guess, maybe one of the older ones to first come up with this language and have a catalog of these design patterns. And it's known as the Gang of Four because it had four authors. And it's Design Patterns: Elements of Reusable Object-Oriented Software. It's not the most approachable book. It's not the least approachable, but it's not the most approachable coding book. I had it, and I won't lie, I couldn't make it all the way through it. But that was many years ago or several years ago. So if I read it again, maybe I'd get more out of it. But it's the one that, you know, was kind of the granddaddy of them all.

1:03:04.540 --> 1:03:44.243
<v A>Yeah, I had the same experience you did where I read the beginning of it, and it was just kind of, it was too much for me. Like at the time, I just didn't. It just is very dense. And it was kind of written for, like, true enthusiasts. And, yeah, I just couldn't digest it. I did read the second, like this other book, Head First Design Patterns. Yes. Which is, I did read that one, and I thought it was pretty awesome. You know, it talks about all the different design patterns and detail and things like that. But it has this, like, what would you describe, like kind of Americana theme? So it sort of has a lot of these, like, leave it to Beaver type, you know. Yeah, it doesn't take

1:03:44.243 --> 1:03:44.920
<v B>itself too seriously.

1:03:45.440 --> 1:04:01.340
<v A>Yeah, it's kind of goofy, and it's like, hey, make sure you have apple pie with your Singleton or whatever. It's kind of funny. It's got a lot of good content. It has examples, which is really useful. And, yeah, that was the one that I liked the most of all of them.

1:04:01.620 --> 1:04:28.700
<v B>Yeah. So this final one is actually a website that's a book called GameProgrammingPatterns.com. And I saw this one posted this week, actually. This guy finished writing this, and he did one of these interesting novel approaches where I think he was publishing drafts as he was going and getting feedback and bugs filed against him and all this. So he was sharing it as he was writing it, and he didn't publish it in a traditional sense. And he has a whole story about it you can read. I actually didn't read the whole thing.

1:04:30.380 --> 1:04:51.338
<v B>But I was going through this, and it's from the perspective of a game programmer, a guy who worked at EA for a number of years writing games, and saying how that in game programming there's still a lot of people who don't use design patterns, and they don't think it's for them because they're too manly to use design patterns or whatever. And so

1:04:51.338 --> 1:04:54.940
<v A>He has a pretty epic picture of him and his Chihuahua on the front page.

1:04:56.319 --> 1:05:29.840
<v B>Okay. You'll have to go see it for yourself. But he has kind of organized design patterns under the context of things that would be useful for a game and using games as examples. But I find that to be generally useful when I was skimming through that this week because everybody kind of understands games at some level because we've all played them, so we can imagine it versus we haven't all used enterprise software. So it doesn't make as good of an example per se. So I find that the examples here work well, and he does a really good job of explaining them, demonstrating their uses, and giving cautionary tales.

1:05:31.200 --> 1:05:32.940
<v A>Oh, nice. You'll have to check that out.

1:05:33.080 --> 1:05:33.640
<v B>And it's free!

1:05:34.520 --> 1:05:45.420
<v A>Yeah, it's pretty cool. It looks like he's working on an e-book, so you can sign up on his mailing list to get the e-book. But in the meantime, you can read it all online in an HTML format.

1:05:46.560 --> 1:05:49.620
<v B>Yep. Well, I think that's it for this episode.

1:05:50.280 --> 1:06:08.400
<v A>Yeah, definitely. Obviously, if you want to get involved in open source and other projects, it's really good to sort of wrap your head around some of these design patterns. You'll see them all over the place. So it won't be hard to find them, but it might be a little challenging to know that they're there at first.

1:06:10.364 --> 1:06:10.920
<v A>It's the way.

1:06:10.920 --> 1:06:12.680
<v B>to step up your programming to the next level.

1:06:13.140 --> 1:06:59.740
<v A>That's right. That's right. I mean, a lot of even languages, like JavaScript, is kind of, you know, a lot of, like, client server, like Socket.io, for example, in JavaScript, has, like, a... Socket.io has this concept of rooms, where a room has an ID and you can join a room. And anyone who's in a room receives all the messages that get posted to that room. But, you know, like, it's basically a publisher subscribe. I mean, what they're calling a room is really just a subscription that you can join and leave. And if you're joining, then the server publishes messages that you receive and vice versa. So, you know, you'll see the same patterns over and over again. They might have different names that might be called differently.

1:07:01.420 --> 1:07:08.500
<v A>But, you know, reading a book like Clean Code: Design Patterns, and following our podcast, you'll be able to sort of see them when they come up.

1:07:08.859 --> 1:07:12.879
<v B>We had some good emails. So thank you for your email and your continued support of this show.

1:07:13.620 --> 1:07:18.060
<v A>Yeah, somebody suggested design patterns, ironically. And I told that person...

1:07:18.060 --> 1:07:20.680
<v B>I think people have suggested almost all the topics we've ever covered.

1:07:21.100 --> 1:07:31.300
<v A>Yeah, that's true. But someone suggested design patterns. And I told them, 'Oh, no, Patrick has this show picked out. But we'll do Design Patterns next show.' I said that to somebody like two days ago.

1:07:32.880 --> 1:07:42.040
<v A>So it turns out that that's what you picked. So someone knows you too well. You and someone else, your hearts are beating to the same drum.

1:07:42.080 --> 1:07:43.080
<v B>That was actually just me.

1:07:43.780 --> 1:07:46.416
<v A>Oh, it was your alter ego on Google+. I'm just

1:07:47.260 --> 1:07:53.360
<v B>kidding. But thanks to you guys for your reviews and your posts on our community on Google+, and emails.

1:07:54.280 --> 1:07:59.292
<v A>Yeah, definitely. We have a Facebook page that I'll be keeping up to date along with the blog. I won't

1:07:59.292 --> 1:08:00.640
<v B>lie. I don't have a Facebook account.

1:08:01.480 --> 1:08:03.840
<v A>You still don't have a Facebook account?

1:08:04.040 --> 1:08:06.042
<v B>I may have one. I don't know. I've not

1:08:06.042 --> 1:08:10.180
<v A>logged on Facebook in three, four years. How do you log into anything?

1:08:10.180 --> 1:08:22.300
<v B>I make up fake emails and passwords. Oh, my gosh. Okay. I know. I know. It's just a thing. I don't. Well, yeah, you don't want your. I don't have time to keep up with the stuff I do have. So.

1:08:23.540 --> 1:08:27.300
<v A>Yeah. I mean, the bigger thing, too, is like everything becomes linked then, right?

1:08:29.920 --> 1:08:30.865
<v A>Like a

1:08:30.865 --> 1:08:32.599
<v B>separate discussion for another time.

1:08:33.400 --> 1:08:39.340
<v A>Yeah. If someone compromises my Facebook account, now they have everything. I'll get to work.

1:08:41.940 --> 1:09:35.319
<v A>Oh, man. It's a good time. Oh, man. Just a really quick thing. And maybe we'll talk about this on the next show. But we definitely need to cover the Heartbleed OpenSSL fiasco. All right. Maybe we'll save that as a thing for the next show. But, yeah, there are many soapboxes we can get on about that one. Sounds good. All right, guys. Well, keep coding. Keep using those design patterns. And we'll see you guys in a couple weeks. See ya. The intro music is Axo by Binar Pilot. Programming Throwdown is distributed under a Creative Commons Attribution Sharealike 2.0 license. You're free to share, copy, distribute, transmit the work, to remix, adapt the work. But you must provide attribution to Patrick and I, and share alike in kind. Mm. Mm. Mm. Mm.

