0:00:04.001,0:00:07.507 Ready? Is Sound On? 0:00:08.922,0:00:10.753 Cool. Alright. So. 0:00:22.778,0:00:25.208 Do you see that red dot? 0:00:30.020,0:00:31.743 Why is it red? 0:00:35.418,0:00:36.934 It's dangerous. 0:00:37.798,0:00:41.339 I like that answer. Watch out! Take me to the Cuba. 0:00:43.073,0:00:51.915 Yeah, I've had the security people restricted me from going in the airports, because I'm carrying lasers with me. 0:00:51.988,0:00:55.109 They have, you know, sign on and it says dangerous. 0:00:56.990,0:00:59.148 But, why is that red? 0:01:01.035,0:01:02.399 I have a green laser. 0:01:02.469,0:01:05.432 Hey, you know, you gotta have lasers. 0:01:06.280,0:01:09.323 Alright? I carry three of them with me. 0:01:11.184,0:01:15.861 One of them is red. I always keep them in my back pack with the batteries (??). 0:01:15.901,0:01:17.887 Or turned around actually. 0:01:18.277,0:01:22.806 So this is my red laser. You can get a red laser for twelve dollars. 0:01:24.341,0:01:25.436 There it is. Red laser. 0:01:25.460,0:01:28.763 Nice. And I got a green laser. 0:01:30.029,0:01:31.272 This one is nice one. 0:01:33.062,0:01:34.684 A pretty bright one too. 0:01:34.752,0:01:39.001 Not bright enough to do anything interesting, but bright. 0:01:39.075,0:01:41.025 There is little adjustment in here. 0:01:41.025,0:01:44.585 You can cut a component out and put a different register in here. 0:01:44.595,0:01:47.797 Then you can get almost of quarter of Watt out of it. 0:01:47.847,0:01:50.857 The battery drains pretty fast. You can pop a balloon with it. 0:01:51.668,0:01:54.919 I mean that's cool. Boom. 0:01:57.124,0:02:00.599 But this is my favorite laser. 0:02:02.496,0:02:05.139 And I like this one because 0:02:06.698,0:02:12.734 Well, can you see that? 0:02:14.716,0:02:19.295 Little tiny violet dot. Do you see that up there? 0:02:20.906,0:02:24.869 See if I can show it to you here. Oh! That’s nice and bright. 0:02:25.269,0:02:27.833 On my thing here. That's nice and bright. 0:02:28.344,0:02:31.192 But over there, you can hardly see it. 0:02:31.445,0:02:33.524 Can you see this thing? No. 0:02:33.559,0:02:35.886 Can you see it here? No, not too much. 0:02:36.492,0:02:39.445 No, can't see it there much. 0:02:39.477,0:02:48.820 But, I found this once. 0:02:51.325,0:02:57.433 Just a marker. Litter laser doesn't do too much to the marker. 0:02:57.465,0:02:59.458 But the lid! 0:03:02.153,0:03:05.457 And look! It's yellow! 0:03:05.529,0:03:07.331 It's not blue! 0:03:08.210,0:03:11.093 And then see that little orange thing there? 0:03:11.093,0:03:13.747 Watch this! I gotta aim it carefully. 0:03:14.353,0:03:17.780 Wow! It's orange. 0:03:17.838,0:03:19.988 What kind of laser is this? 0:03:22.060,0:03:26.491 This is a laser of some other color. 0:03:33.884,0:03:41.141 My glasses are the kind that turn dark in the sun light. 0:03:44.719,0:03:47.650 I don't know if you can tell. But now there are all dark. 0:03:47.688,0:03:50.853 Alright? And I can't see any of you. 0:03:50.917,0:03:53.470 This is an ultra violet laser. 0:03:53.560,0:03:57.504 They don't bill it as such. You can buy them on amazon. 17$. 0:03:57.504,0:04:01.100 They say it's a violet laser. They lie. 0:04:01.368,0:04:06.948 It's much cooler than violet laser. It's an ultra violet laser. 0:04:06.948,0:04:09.637 Everybody has to have an ultraviolet laser. 0:04:09.703,0:04:12.649 It's completely useless as a laser pointer. 0:04:12.701,0:04:16.997 But you can draw nice little pictures on you glasses with it. 0:04:18.598,0:04:21.843 Oh~ I got my name. 0:04:24.672,0:04:26.507 Alright. Whatever. 0:04:29.240,0:04:31.126 Look at the code on the screen. 0:04:32.639,0:04:34.428 Anybody recognize that code? 0:04:35.765,0:04:38.325 I can't see it because my glasses are all dark. 0:04:38.771,0:04:40.798 Anybody recognize that code? 0:04:42.267,0:04:44.242 That's PDP-8 code. 0:04:44.945,0:04:48.863 That what code looked like in 1970s. 0:04:48.928,0:04:54.753 That's kind of code I was writing when I was slightly older teenager. 0:04:55.825,0:04:58.618 And then on into my twenties as well. 0:05:00.074,0:05:03.543 This statement right there. 0:05:03.979,0:05:06.305 Anybody know what that means? 0:05:07.940,0:05:13.611 That's the memory address which this program would be loaded. 0:05:15.334,0:05:20.159 We used to write the address our program into our program. 0:05:21.160,0:05:23.551 This program would be loaded at address 200. 0:05:24.245,0:05:26.996 And we put the data at address 300. 0:05:27.042,0:05:28.052 How about that? 0:05:28.669,0:05:32.636 And it makes perfect sense. Of course you would know where programs getting get loaded. 0:05:32.668,0:05:34.836 I mean who else is gonna decide that for you? 0:05:34.905,0:05:37.708 You are the programmer. You have control over memory. 0:05:39.471,0:05:41.323 Now, this works fine. 0:05:43.026,0:05:45.572 I'll show you a sequence of pictures here. 0:05:46.268,0:05:50.080 Let's see. Yeah, that's a nice one. 0:05:50.151,0:05:55.087 Hello. No, that's not the one what I wanted. 0:05:56.140,0:06:01.655 That's because nowadays when you open up documents 0:06:02.386,0:06:09.623 It opens up every document that's been opened by that application. 0:06:10.509,0:06:12.138 Don't save that. 0:06:12.177,0:06:14.630 That's the one I wanted, right there. 0:06:17.049,0:06:20.356 Imagine you are programmer who's writing this kind of code. 0:06:20.899,0:06:23.826 And you've got a program like this one. 0:06:24.626,0:06:28.010 My program lives here. It starts at address 200. 0:06:28.900,0:06:32.107 And there's a subroutine library that somebody else has written. 0:06:32.524,0:06:35.145 By the way subroutine libraries were not real common. 0:06:35.229,0:06:37.768 You usually wrote your own subroutine back in those days. 0:06:37.818,0:06:45.607 But after a while a few guys write some useful subroutines. You think "You know, I should have those in my program too." 0:06:45.637,0:06:50.378 And you think, "Well, just compile them in with my code" 0:06:50.411,0:06:51.663 That's what we used to do. 0:06:51.695,0:06:53.496 You just take the source code and jam it together. 0:06:53.531,0:06:55.465 What was the problem with that? 0:06:58.735,0:07:02.218 We were talking about the 1970s here. Right? 0:07:02.314,0:07:05.566 Those programs were contained on paper tape. 0:07:06.124,0:07:10.498 Paper tapes is being 50 characters per second, if you were lucky. 0:07:10.534,0:07:19.939 And so increasing the size of your source code lengthened the size of your compile by minutes. 0:07:20.346,0:07:26.642 So after a while these subroutine libraries got too long to continue to add your source code. 0:07:26.642,0:07:35.124 So what we did is we would compiled the subroutine library and we would loaded at location 1200. 0:07:35.847,0:07:42.367 Then what we could do is we could have a binary file which got loaded at 1200. 0:07:42.417,0:07:45.363 And we could have our program at 200. 0:07:45.396,0:07:49.044 And we did have a little file that all the symbols in it. 0:07:49.122,0:07:55.016 So the symbols would tell us which subroutine was loaded where. 0:07:55.016,0:08:03.131 So we knew the Get subroutine was at 205 and the Put subroutine was at 210 and so on. 0:08:03.518,0:08:06.998 And our symbols would get compiled in with the program 0:08:07.032,0:08:09.907 The subroutine would be loaded separately. And everything worked fine. 0:08:12.236,0:08:14.215 What's the problem with this? 0:08:15.705,0:08:19.428 When is the last time you saw a program that stayed small? 0:08:20.839,0:08:22.122 They grow! 0:08:22.634,0:08:26.489 And after a while, well let's see. 0:08:28.017,0:08:29.632 I got another picture here. 0:08:34.783,0:08:36.475 Yeah, that's that one. 0:08:40.664,0:08:43.767 Oh yeah, a program that got too big. 0:08:43.767,0:08:47.278 It overwrites the subroutines. This doesn't work. 0:08:49.171,0:08:56.041 When your program overwrites the subroutines, your program still thinks that the subroutines are there. 0:08:56.073,0:09:02.337 So when it calls the location 1205 it actually jumps into some arbitrary part of you code. 0:09:02.577,0:09:04.491 You didn't know this happened of course. 0:09:04.510,0:09:08.095 Until finally you debugged it and realized. "Oh, my programs got too big!" 0:09:08.914,0:09:11.360 What's the solution to this? 0:09:13.744,0:09:17.567 You are programmers, you can come up with the solution to this. 0:09:20.598,0:09:23.282 Jump around the subroutine library. 0:09:23.954,0:09:27.486 Right? You put it Jump right there to jump over here. 0:09:28.322,0:09:31.370 Of course the subroutine library gets bigger too. 0:09:32.140,0:09:39.809 And so after a while. Let's see if I've got that picture right. 0:09:39.842,0:09:42.093 How about that one? Yeah, that's the one. 0:09:42.505,0:09:45.243 After a while you get that problem. 0:09:48.209,0:09:50.504 We actually faced to this problems. 0:09:51.014,0:09:53.910 We actually had to deal with this stuff. 0:09:53.946,0:09:55.702 And you know how we solved it? 0:09:59.595,0:10:04.698 We came up with relocatable code. 0:10:04.730,0:10:10.495 We said "You know what? This idea of putting absolute address in the program is killing us." 0:10:10.528,0:10:17.440 "What we really like to do is compile our programs without telling them where they're going to be loaded." 0:10:17.813,0:10:20.630 "And then we'll tell the loader where to load them" 0:10:21.435,0:10:23.141 Now there's problem with that. 0:10:23.632,0:10:29.658 Because that means that your binary files cannot really be binary. 0:10:29.705,0:10:38.706 They have to have codes in them to tell you that certain address are not actually addresses. They are offsets. 0:10:39.030,0:10:47.994 And the loader has to find every address that's marked as an offset and add the start address to it. 0:10:49.321,0:10:51.940 But that works. We had relocatable loaders. 0:10:51.988,0:10:54.619 We made this relocatable binaries and loaders. 0:10:54.619,0:10:57.034 But now you've got another problem. 0:10:57.234,0:11:00.415 Because how do you know where the subroutines are. 0:11:00.447,0:11:05.737 If the subroutines are moving all over the place, how do you know where the subroutines are? 0:11:06.007,0:11:11.043 So now you have to add more information to the binary file. 0:11:11.264,0:11:19.687 This binary file you thought just binary of your program is now becoming very bizarre files. 0:11:19.726,0:11:21.301 It's got all kinds of gunky in it. 0:11:21.372,0:11:28.293 Now you have to put the names of the subroutine library into the binary file of the subroutines. 0:11:28.357,0:11:32.468 And you have to show what address they will get loaded at 0:11:32.523,0:11:37.614 And relocatable loader has to remember where it put those addresses 0:11:37.682,0:11:42.622 And then in the program you have to have another thing in there. 0:11:42.694,0:11:47.250 That says "Hey, I need to know where this programs gonna be loaded" 0:11:47.250,0:11:53.432 "And the loader has to link the subroutine library of the program." 0:11:57.322,0:12:00.831 Computers were slow in those days. 0:12:00.899,0:12:02.548 Disk drivers were very slow. 0:12:02.626,0:12:04.539 And there wasn't a lot of disk memory. 0:12:04.621,0:12:08.102 You were lucky if you had megabytes of disk. 0:12:08.173,0:12:14.636 And the seek arm took a long time and the rotational latency was high. 0:12:14.673,0:12:18.136 So link times took a long time. 0:12:18.201,0:12:22.206 Especially as we got more and more libraries. 0:12:22.257,0:12:23.743 More and bigger program. 0:12:23.784,0:12:26.032 Link time could take an hour. 0:12:26.082,0:12:28.448 Anybody have a link that took an hour? 0:12:28.480,0:12:30.845 Anybody here working in the 80s? 0:12:30.880,0:12:32.694 Oh no! You got one now! 0:12:32.776,0:12:35.263 You must be C++ programmer. 0:12:36.524,0:12:38.661 That says so, right on your shirt. 0:12:38.701,0:12:40.747 OSLO C++ Users Group. 0:12:41.137,0:12:42.647 Long link times. 0:12:45.358,0:12:50.458 Even in the 70s we had that problem. Although it was much smaller programs. 0:12:50.500,0:12:57.964 So the solution to that was to separate the link pace from the load pace. 0:12:57.964,0:13:02.302 We would link as a second compile step. 0:13:02.302,0:13:07.435 And that would produce a final relocatable file that had all the linkage were resolved. 0:13:07.468,0:13:10.141 And then we could load it at run time. 0:13:10.141,0:13:12.488 Ant that was relatively fast enough. 0:13:13.287,0:13:17.964 And for years and years and years. We lived with this 2 step process. 0:13:18.015,0:13:24.358 Compile down to binary files then link all the binary files into an executable. 0:13:24.401,0:13:26.497 And then you can load the executable. 0:13:26.531,0:13:29.877 And that solved problem until the 90s. 0:13:29.942,0:13:33.540 In the 90s something happened. 0:13:33.588,0:13:36.238 It was called Moore's Law. 0:13:36.772,0:13:38.009 What's Moore's law? 0:13:39.302,0:13:43.558 The speed of processors will double every 18 month. 0:13:43.671,0:13:52.960 Now apply that from about 1970 when the speed of our processors were half a million instructions per second. 0:13:53.640,0:13:56.959 And keep that going forward until the 1990s. 0:13:57.025,0:13:59.999 Well that's 20 years, how many 18 cycles is that? 0:14:00.048,0:14:02.176 Well, 18 month cycle is that? 0:14:02.176,0:14:03.981 That's about 15 cycles. 0:14:03.981,0:14:07.257 So we have 2^15 increase in speed. 0:14:08.369,0:14:09.286 Think about that. 0:14:09.338,0:14:11.523 2^15 increase in speed. What is that? 0:14:11.602,0:14:13.700 That's increase about 32000! 0:14:13.700,0:14:15.171 That's about right too. 0:14:15.223,0:14:18.751 Cause we went from about a half MHz to 2.8 GHz. 0:14:18.786,0:14:21.746 Well, maybe 1 GHz by the late 90s. 0:14:21.787,0:14:24.907 By that time disks were going faster too. 0:14:24.941,0:14:27.232 We spun up a lot faster in the road. 0:14:27.300,0:14:31.782 The heads weren't moving as far, we were getting a lot more bits around rim too. 0:14:31.830,0:14:38.692 We could get hundreds of MBs on a disk. Oh! 0:14:40.512,0:14:44.219 And somebody made a bright thought. 0:14:44.270,0:14:46.157 Somebody had a bright thought that 0:14:47.454,0:14:50.440 "We don't have to do the link separately anymore." 0:14:51.042,0:14:54.378 "We can do the link at the same time we load." 0:14:54.424,0:14:56.582 Anybody remember the ActiveX? 0:14:56.621,0:14:58.946 Anybody remember OLE? 0:14:59.546,0:15:01.917 What does DLL stands for? 0:15:04.119,0:15:08.215 Dynamically linked library. 0:15:08.258,0:15:11.120 Which means it's linked at load time. 0:15:11.153,0:15:14.817 The link step got moved back into the loader. 0:15:15.699,0:15:19.203 And we have the situation we have today. 0:15:20.762,0:15:22.616 Who's .NET programmer, here? 0:15:23.668,0:15:25.037 Look at that. A lot of people. 0:15:25.070,0:15:28.122 Java programmer! Raise your hands. 0:15:28.189,0:15:29.952 Not so many. How come? 0:15:31.001,0:15:35.314 How come it's all .NET? Oh maybe because it's a .NET kind of conference? Huh? 0:15:36.034,0:15:41.840 So, in .NET you got DLLs. 0:15:41.872,0:15:43.732 Dynamically Linked Libraries. 0:15:43.765,0:15:45.922 In Java, you got Jar files. 0:15:45.969,0:15:50.940 But they are still dynamically linked libraries. Same idea. Same purpose. 0:15:51.780,0:15:56.055 In C++, if you do in the Microsoft thing you still got DLLs. 0:15:56.088,0:15:58.850 If you don in UNIX thing you've got shared libraries. 0:15:58.850,0:16:01.031 They are still dynamically linked libraries. 0:16:01.080,0:16:05.131 Our mode of operation now a days is too dynamic linked libraries. 0:16:05.165,0:16:07.867 That's how we got here. 0:16:11.980,0:16:13.626 How many DLLs do you have? 0:16:15.342,0:16:18.575 Guys with the solutions, Visual Studio solutions. 0:16:18.608,0:16:20.415 How many projects? 0:16:21.315,0:16:23.550 60? That's not bad. 0:16:23.550,0:16:25.017 Who's got more than 60? 0:16:25.060,0:16:26.597 Oh, look at that. 0:16:26.635,0:16:28.094 Who's got more than 200? 0:16:30.942,0:16:33.132 And do you know why? 0:16:33.215,0:16:38.055 You separate your code into different DLLs? 0:16:38.886,0:16:40.692 Let me ask that question differently. 0:16:41.272,0:16:43.624 When you deploy your application, 0:16:44.590,0:16:50.366 Do you gather up all the DLLs and just ship the wad? 0:16:52.521,0:16:57.677 If you do then why are you dynamically linking them? 0:16:57.728,0:16:59.395 Statically link them. 0:17:00.269,0:17:04.820 Why would you bother with dynamic linking? If you just gonna take all those DLLs. 0:17:04.887,0:17:07.260 Gather them up into one gigantic wad. 0:17:07.313,0:17:10.359 Throw the big wad into directory. And says, "It's my system." 0:17:11.996,0:17:16.857 Why dynamically link if you not going to dynamically deploy? 0:17:17.540,0:17:21.675 Why did we come up with dynamically linked library? 0:17:21.743,0:17:28.603 We came up with dynamically linked library so that we could dynamically deploy our applications. 0:17:29.093,0:17:30.155 Why? 0:17:32.571,0:17:35.630 Well, we gonna get to network speed. Hang on in a minute. 0:17:35.676,0:17:38.946 Cause network speed has huge impact on this all thing. 0:17:38.996,0:17:43.985 Mid 90s I've got a client. He's got a 250MB executable. 0:17:43.985,0:17:46.594 In the mid-90s that was big program. Now it' not. 0:17:47.267,0:17:51.733 But then 250MB was big deal, you could not fit it on a CD. 0:17:52.250,0:17:57.127 This was CAD system. He shipped it to the company like Ford. 0:17:57.127,0:18:01.548 Ford would use it to design gears and levers. Stuff like that. 0:18:02.876,0:18:04.331 He statically linked it. 0:18:05.035,0:18:11.207 He would deploy the executable to his clients by burning it on several CDs. 0:18:11.844,0:18:15.109 If he changed one line of code, 0:18:16.782,0:18:26.422 He had to recompile, re-link, re-burn all the CDs and deploy all the CDs to all his clients. 0:18:27.237,0:18:29.756 And you can imagine how it cost him a fair bit of money. 0:18:31.981,0:18:34.189 I went there in the mid-90s. 0:18:34.246,0:18:36.615 And encountered them at a time 0:18:36.665,0:18:44.005 when they were trying to chop up their executable into this new Idea, DLLs. 0:18:44.262,0:18:48.902 Because they realized that if they had dynamically linked libraries 0:18:48.902,0:18:52.166 Then they could change a line of code 0:18:52.205,0:18:56.740 And ideally you would only have to ship that DLL. 0:18:57.545,0:19:01.125 You could e-mail it!. Back in those days that was a big deal. 0:19:01.168,0:19:03.370 You couldn't e-mail 250MB in those days. 0:19:03.439,0:19:07.631 Now a days you can as long as the guy you're talking to got a reasonable e-mail server. 0:19:07.703,0:19:17.166 But back in those days e-mailing 250MB was impossible, so they could e-mail the 100KB of DLL. 0:19:17.219,0:19:20.060 And so that was very very desirable for them. 0:19:20.060,0:19:22.163 They worked for month and month and month. 0:19:22.188,0:19:24.972 Chopping their application up in the little tiny bits, 0:19:25.010,0:19:26.933 turning them all into bunch of DLLs 0:19:27.021,0:19:29.465 And that when they realized their critical mistake. 0:19:30.557,0:19:35.474 The critical mistake was that chopping your system up into bunch of arbitrary DLLs 0:19:35.474,0:19:39.293 doesn’t do you a damn bit of good if they all depend on each other. 0:19:40.189,0:19:42.742 If they are all depend on each other then you can... 0:19:51.828,0:19:56.005 Was anybody just in Scott Meyer's talk here? 0:19:56.091,0:19:58.434 The last talk he just gave an hour ago? 0:19:58.466,0:20:01.075 He was talking about the problem of keyholes. 0:20:01.126,0:20:07.846 Problem of keyholes is that we arbitrarily constrain someone for no good reason. 0:20:07.894,0:20:09.813 Just arbitrary constrain them. 0:20:09.849,0:20:14.522 So for example, have you ever seen a text box on a GUI? 0:20:14.572,0:20:16.453 That was just too short? 0:20:16.521,0:20:21.868 And you had typed bunch of stuffs in it and it wouldn't let you resize the window? 0:20:21.868,0:20:25.885 It wouldn't let you scroll and you just had to type blind? 0:20:25.930,0:20:29.602 Or maybe the text with scroll but you wouldn't be able to see the beginning of it? 0:20:29.656,0:20:34.728 He was mentioning the keyhole problem. 0:20:34.795,0:20:38.273 And I know that something just happened here. 0:20:39.093,0:20:43.362 Apparently I'm not allowed not touch my computer for more than 5 minutes. 0:20:43.412,0:20:48.041 I must apparently touch my computer otherwise I'll be punished. 0:20:52.043,0:20:54.513 What was I talking about? Oh yeah, DLLs. 0:20:54.513,0:20:58.225 So this guy, he put all his DLLs together. 0:20:58.276,0:21:00.500 He forgot that DLLs depend upon each other. 0:21:00.534,0:21:04.391 His goal was to be able to touch a line of code 0:21:04.423,0:21:07.752 And just ship that DLL that was affected. 0:21:07.821,0:21:12.386 But he found that all the '#includes', C++ guys know what I'm talking about 0:21:12.450,0:21:15.307 All the '#includes' form the horrible network. 0:21:15.358,0:21:18.146 And he had to recompile and redeploy everything anyway. 0:21:18.218,0:21:19.680 They went out of business. 0:21:22.666,0:21:27.814 The purpose of my talk today, now that I'm getting around to it 0:21:29.349,0:21:31.336 is to talk about components. 0:21:31.381,0:21:33.408 The problem of component design. 0:21:33.480,0:21:36.167 And the first thing we gonna do is to define a component. 0:21:36.213,0:21:38.665 What's a component? Component is DLL. 0:21:39.475,0:21:42.531 When I talk about the word component what I mean is DLL. 0:21:42.565,0:21:47.002 Very particular kind of DLL. A dynamically deployable DLL. 0:21:49.185,0:21:52.573 A dynamically deployable DLL. 0:21:53.473,0:21:55.929 Why would we want dynamically deploy? 0:21:56.816,0:21:59.877 Well, because we would like to be able to change one line of code 0:21:59.926,0:22:03.113 Just ship the one DLL that changed and ignore all the others. 0:22:03.163,0:22:05.399 What's DLL hell? 0:22:05.448,0:22:09.273 A term invented, I believe, by Microsoft 0:22:10.135,0:22:12.442 to describe their own situation. 0:22:12.509,0:22:17.506 And was to be completely cured by .NET. 0:22:17.540,0:22:22.185 Anybody remember that line? "Dear .NET cures DLL hell." 0:22:22.185,0:22:27.531 Hu Hu Hu. No, it doesn’t cure DLL hell. 0:22:27.541,0:22:32.285 DLL hell is the problem that we've got all these little components with different version numbers 0:22:32.285,0:22:35.084 And nobody hell knows which one go should together 0:22:35.150,0:22:38.669 So we invented this module maintenance tools like Maven. 0:22:38.742,0:22:40.642 What are you guys using in .NET? 0:22:41.176,0:22:45.925 What's the tool that lets you keep all of your DLLs are in line. 0:22:45.974,0:22:50.143 So you know that download version 1 of that one and version 3 of that one. 0:22:50.176,0:22:52.714 Do you have tool for that? What? 0:22:53.961,0:22:54.957 NuGet? 0:22:54.957,0:22:56.854 Like the soft chewy (??) 0:22:58.944,0:23:00.720 Never mind, I'm not going there. 0:23:09.766,0:23:17.987 The graph you see on the screen is a graph of x^2. 0:23:18.477,0:23:20.371 That's just an x^2 graph. 0:23:21.242,0:23:23.102 But it's also something else. 0:23:23.134,0:23:29.186 It's the number of dependencies in a system. 0:23:29.276,0:23:33.748 Theoretical maximum number of dependencies, given a certain number of modules. 0:23:33.798,0:23:38.206 And you can see that the number of modules increases linearly 0:23:38.256,0:23:40.969 And the number of dependency increases with square. 0:23:44.473,0:23:48.699 The theoretical maximum number of coupling, which I show here 0:23:50.586,0:23:54.750 is proportional to the square of the number of modules. 0:23:54.786,0:24:01.275 Now of course we would never create a system that has every possible dependency in it. 0:24:02.578,0:24:03.733 Or would we? 0:24:06.355,0:24:08.209 Look at this curve. 0:24:09.181,0:24:19.898 This curve is the productivity of a team in comparison to the number of modules. 0:24:19.898,0:24:24.953 By the way this is completely arbitrary I just generated one of x squared curve here. 0:24:25.389,0:24:28.168 This is not me collecting actual data. 0:24:28.935,0:24:34.197 This is just me recollecting my experience with development teams. 0:24:34.197,0:24:38.003 They go slower and slower and slower over time. 0:24:38.035,0:24:39.495 Who's had this happened to them? 0:24:39.532,0:24:42.367 You start outgoing really fast. You can conquer the world. 0:24:42.416,0:24:45.923 A year later you slogging through some kind of horrible wet lands. 0:24:46.366,0:24:48.664 And you don't know what the heck has gone wrong. 0:24:48.721,0:24:52.936 But estimates that used to be on the order of one week are now three month long. 0:24:53.378,0:24:58.136 And by the way you blow all those estimates anyway and introduces more bugs than you fix. 0:24:58.212,0:25:04.435 That's the kind of problem that we have as we proceed a long development path. 0:25:04.480,0:25:09.831 And one of the reasons for that is accumulation of dependencies. 0:25:10.571,0:25:11.522 Why? 0:25:11.842,0:25:20.778 Well, that's the theoretical maximum dependency between modules. 0:25:20.823,0:25:22.847 This is the theoretical minimum. 0:25:23.172,0:25:28.910 If you're going to have an interconnected set of modules, there has to be some dependencies. 0:25:28.966,0:25:32.231 And the minimum set of dependencies is a tree structure. 0:25:32.231,0:25:35.620 Oh you can do some better with dynamically linking if you want to. 0:25:35.620,0:25:39.531 But for the most part, you gonna have a small number of dependencies. 0:25:39.573,0:25:42.272 How many do we have? 1. 2. 3. 4. 5. 6. 0:25:42.272,0:25:44.587 6 out of 7 modules. 0:25:44.627,0:25:46.659 Whereas here you've got 0:25:46.659,0:25:50.570 Well, I think that's half of 49. 0:25:50.570,0:25:54.202 It can't be half of 49 because that would be happy half dependency. 0:25:54.257,0:25:58.264 Maybe it's just a plain 49. I don't know what it is. It's a large number. 0:25:58.349,0:26:01.067 It's some relative of N squared. 0:26:01.133,0:26:03.280 Maybe it's one half n squared plus one half n. 0:26:03.362,0:26:04.893 Something like that. 0:26:04.923,0:26:07.859 It's a very large number of dependencies. 0:26:07.892,0:26:10.906 We don't want this. We do want that. 0:26:10.974,0:26:13.134 We strive very hard to get here. 0:26:13.168,0:26:21.088 But then, some shmuck does that. 0:26:24.111,0:26:26.011 Visual Studio doesn't allow this. 0:26:27.014,0:26:28.507 Uh! Inside solution. 0:26:29.029,0:26:34.189 Inside solution. The DLLs cannot have cycles between their graphs. 0:26:34.243,0:26:35.019 That's good. 0:26:35.086,0:26:36.004 Don't want cycles. 0:26:36.473,0:26:38.744 Between separate solutions there's no guarantee. 0:26:38.778,0:26:40.359 So you have multiple solutions. 0:26:40.407,0:26:45.270 If you're linking with things that come out of different solutions, you can still have cycles in the graph. 0:26:45.304,0:26:50.766 If you get cycles in the graph, it looks like it adds only one extra dependency. 0:26:51.385,0:26:52.776 But actually it adds more. 0:26:52.817,0:26:57.299 Because 6 now depends upon 2. Because 1 depends upon 2. 0:26:57.371,0:26:59.139 And dependency is transitive. 0:26:59.230,0:27:04.568 So 6 also depends upon 4 and 5. And 6 depends upon 3 and 7. 0:27:04.771,0:27:06.851 In fact, 6 depends upon all of them. 0:27:07.561,0:27:13.921 So number of dependencies multiplies dramatically as soon as you have a cycle. 0:27:21.943,0:27:23.726 This is the n squared graph again. 0:27:25.092,0:27:28.693 This is also a graph of C++ compile time. 0:27:28.759,0:27:31.253 As you add modules. 0:27:31.352,0:27:34.100 Compile time and the link time if you're doing static linking 0:27:34.100,0:27:35.737 But even if you're not static linking, 0:27:35.793,0:27:39.881 just compile time grows with the square of the number of modules, 0:27:39.935,0:27:44.671 if you have a fully connected network of modules. 0:27:44.736,0:27:52.241 What that mean is that your '#include' or your import statements or your using statements can be traced in a cycle. 0:27:53.119,0:27:58.560 And if you have that, then you gonna wind up with this big increase in compile time. 0:27:58.594,0:28:00.859 C++ in particular would do this. 0:28:00.949,0:28:02.659 Java and .NET don't. 0:28:03.917,0:28:06.240 Their compile time is based on a different metric. 0:28:06.240,0:28:12.053 They don't go reading source files. The way C++ does. 0:28:12.105,0:28:15.349 Java and .NET read binary files to get their declarations. 0:28:15.385,0:28:18.574 C++ reads source files to get his declarations. 0:28:18.615,0:28:23.778 And so if you had a cycle in C++, you got punished. 0:28:25.281,0:28:27.059 By a big compile time. 0:28:27.125,0:28:28.832 And a massive one. 0:28:28.900,0:28:30.244 It would go up with square. 0:28:30.292,0:28:33.036 So you would had couple of modules your compile time will double. 0:28:33.036,0:28:35.560 And that made us do something about it. 0:28:36.190,0:28:38.804 Who knows who Ward Cunningham is? 0:28:39.549,0:28:40.459 Oh, a few of you do. 0:28:40.494,0:28:41.964 Good. And the rest of you. 0:28:42.014,0:28:43.392 He's the guy who invented Wikis. 0:28:43.462,0:28:46.579 Ward Cunningham invented Wikis. 0:28:46.623,0:28:51.552 He's the guy who helped Kent Beck invent pair programming, test-driven development, 0:28:51.637,0:28:53.158 And most of the agile stuff. 0:28:53.207,0:28:57.016 Get to know who Ward Cunningham. He is very interesting fellow. 0:28:57.049,0:28:58.832 Smalltalk Programmer from a long ago. 0:28:58.877,0:29:00.634 And I asked Ward once. 0:29:00.686,0:29:03.304 "Why did Smalltalk died, Ward?" 0:29:03.367,0:29:10.085 And he said, "Smalltalk died because it was so easy to make a mess." 0:29:10.834,0:29:12.810 "You, C++ programmer,” 0:29:12.846,0:29:14.382 I was a C++ programmer at that time. 0:29:14.458,0:29:16.678 "You, C++ programmers are lucky." 0:29:16.729,0:29:19.467 "Your language punishes you if make a mess." 0:29:19.960,0:29:21.830 "Smalltalk didn't punish you." 0:29:23.425,0:29:26.515 Well, neither does Java. Neither does C#. 0:29:26.965,0:29:28.502 They don't punish you anymore. 0:29:28.570,0:29:30.997 It's very easy to make a very large mess. 0:29:31.368,0:29:34.879 And get a very tangled structure and not know you're doing it. 0:29:34.910,0:29:38.958 Fortunately Visual Studio keeps some of the cycles out of your graph. 0:29:44.173,0:29:49.045 We would like that level of productivity, which is n Log N. 0:29:49.109,0:29:52.376 Rather than this level of productivity. That's an n squared. 0:29:52.776,0:29:59.683 And one of the ways to help with that is to manage the dependencies between our components. 0:30:01.753,0:30:06.973 Then something happened to us in the late 90s and into the 2000s. 0:30:06.973,0:30:10.136 Network speed started increasing dramatically. 0:30:10.635,0:30:15.790 Now a days, it's not hard at all to download a GB in a couple of seconds, 0:30:15.870,0:30:17.661 And to upload a GB in 10 seconds. 0:30:17.726,0:30:19.335 That's pretty easy now a days. 0:30:19.386,0:30:21.706 Back in the early days it was much harder. 0:30:22.031,0:30:28.315 So, back in the early days we thought shipping individual DLL was going to be a benefit. 0:30:28.535,0:30:31.939 Now a days we just kind of gather them all together and ship the one big wad. 0:30:32.237,0:30:35.835 Why? Well because network speed is fast enough. We can do it. 0:30:35.835,0:30:40.311 We can treat our batch of DLLs just like it was statically linked. 0:30:41.661,0:30:43.208 But there's another issue. 0:30:44.215,0:30:45.744 How many of you work in teams? 0:30:47.252,0:30:49.511 Oh look at that. Everybody works in teams. 0:30:50.551,0:30:54.415 So, you come in at 8 in the morning. 0:30:55.883,0:30:59.277 You got a test to perform. 0:30:59.346,0:31:02.371 You work all day to get all your stuff working. 0:31:02.488,0:31:03.728 All works by end of the day. 0:31:03.766,0:31:04.907 You check it in and go home. 0:31:04.961,0:31:07.271 Come back the next day all your stuff is broken. 0:31:07.328,0:31:08.086 Why? 0:31:09.766,0:31:12.402 Somebody stayed later than you. 0:31:13.452,0:31:15.836 And changed something you depend upon. 0:31:16.626,0:31:21.774 And so you work all day long to fix whatever the problem was. 0:31:21.774,0:31:24.409 You go home and come back the next day and your stuff is broken again. 0:31:24.523,0:31:26.390 How many times can you go around that loop? 0:31:27.398,0:31:30.942 Lots of time. This is a problem of large teams. 0:31:31.048,0:31:34.662 Large teams will start to step on each other. 0:31:34.745,0:31:36.862 And of course we've invented tools to help us. 0:31:36.862,0:31:38.921 We've got source code control systems. 0:31:38.921,0:31:41.559 And we've got all kinds of good stuff to help us with this. 0:31:41.799,0:31:47.395 But we still can step all over each other, unless we manage our projects well. 0:31:47.814,0:31:52.414 So, how can we manage our projects well? 0:31:55.951,0:31:57.741 There is a principle. 0:32:06.670,0:32:10.849 A principle called Acyclic Dependencies Principle. 0:32:13.189,0:32:18.585 The Acyclic dependencies principle says, "If you have a set of components" 0:32:18.618,0:32:22.764 "You would like to be able to arrange without any cycles in the dependency graph." 0:32:22.849,0:32:25.957 Now, for whole bunch of reasons we've already talked about one of them. 0:32:26.023,0:32:30.402 Which is compile time. We've talked about another which is just dependency load. 0:32:30.402,0:32:31.599 Here is another. 0:32:33.727,0:32:38.577 Alarm would like to release its version of alarm. 0:32:38.986,0:32:43.013 The team that's working on the Alarm would like to make release 1.0. 0:32:43.144,0:32:48.812 They've got nobody that they depend upon. 0:32:48.812,0:32:52.349 So they are completely free to make any release they want. 0:32:52.401,0:32:56.011 So they release their version of 1.0. Alarm 1.0. 0:32:56.011,0:32:58.006 They start working on alarm 1.1. 0:32:58.896,0:33:02.169 But now Alarm 1.0 has been released. 0:33:02.220,0:33:05.977 Which means that Elevator and Conveyor can make their release. 0:33:06.916,0:33:12.386 And once Elevator and Conveyor made their releases they can start to work on 1.1. 0:33:12.419,0:33:15.740 But now Transport can make its release. 0:33:15.776,0:33:17.759 You can see what's happening here. Right? 0:33:17.806,0:33:21.079 The version numbers bubble up from the bottom. 0:33:21.148,0:33:27.448 1.0 gets created here. Then there. Then there. Here. Here. And finally there. 0:33:27.497,0:33:30.021 The version numbers bubble up from the bottom. 0:33:30.053,0:33:32.633 If you look at it closely, you'll realize that 0:33:32.633,0:33:37.550 the version numbers follows exact same path as the build. The compile. 0:33:37.615,0:33:42.422 Dependencies are running in that direction. 0:33:43.318,0:33:50.357 And now, some poor shmuck does this. 0:33:50.454,0:33:52.601 Who's this? 0:33:52.703,0:33:54.192 Well that was me. I did that. 0:33:54.303,0:33:58.542 I had an alarm subsystem I was working on. 0:33:58.542,0:34:02.255 And I needed it to put a message on the display and the control panel. 0:34:02.329,0:34:06.963 There happened to be a class up here that had a function called Display. 0:34:06.963,0:34:10.025 And I thought, "Oh! I should just call it." So I called it. 0:34:10.025,0:34:13.315 This was not in a language that restrict me from cycles. 0:34:13.315,0:34:17.092 And so it compiled and everything was fine and all worked okay. 0:34:18.482,0:34:23.495 And then the next day I had a group of angry developers come to my cubicles with club 0:34:23.542,0:34:25.243 And tell me "What the hell did you do?" 0:34:25.652,0:34:32.592 I said, "Well, I just called the control panel and display class that has display function in it." 0:34:32.628,0:34:34.553 "I needed to put this message on the screen." 0:34:34.587,0:34:35.763 And they said, "You can't do that." 0:34:36.351,0:34:37.908 Why can't we do that? 0:34:39.777,0:34:41.172 First of all, 0:34:43.752,0:34:47.603 what order should we build those modules in? 0:34:49.893,0:34:52.737 You'd like to build them bottom up. 0:34:53.853,0:34:55.666 But now there's no bottom. 0:34:55.717,0:34:58.090 So there's no correct build order. 0:34:58.341,0:35:01.242 If you have cycles in the component graph, 0:35:01.608,0:35:06.485 there is no correct build order for the modules in that system. 0:35:06.524,0:35:11.136 And therefore the execution of that system is undefined. 0:35:11.676,0:35:14.992 What does undefined mean? What's the definition of undefined? 0:35:16.210,0:35:17.867 Works in the lab. 0:35:19.656,0:35:24.308 Anything undefined will work until you actually deploy it somewhere. Then it will fail. 0:35:25.442,0:35:29.006 You can get systems to fail rather badly by having this cycles. 0:35:29.043,0:35:30.945 This is pretty common in Java. 0:35:31.044,0:35:35.951 If you have a system of Java that has cycles in it. 0:35:35.951,0:35:37.061 You can build it. 0:35:37.093,0:35:39.021 Although there is no correct build order. 0:35:39.129,0:35:41.327 Then you run your test. And test will fail. 0:35:41.540,0:35:44.626 Then you build it again. That will choose different build order. 0:35:44.661,0:35:45.804 And maybe the test will pass. 0:35:45.855,0:35:49.166 I know of companies that put their build in a loop until test pass. 0:35:54.627,0:35:56.380 But the problem is worse than that. 0:35:56.923,0:36:03.659 Because conveyor would like to make their release. 0:36:03.690,0:36:05.879 They want to release 1.1. 0:36:05.911,0:36:11.089 Now for them to release 1.1, they have to test with alarm 1.1. 0:36:11.885,0:36:17.858 But alarm 1.1 is waiting for control panel 1.1, which is waiting for transport 1.1 0:36:17.904,0:36:21.646 which is waiting for conveyor 1.1, which is the one trying to release. 0:36:21.646,0:36:27.729 So there's no way to make the release without checking all of that source code out into one place. 0:36:27.818,0:36:31.004 Integrating. Anybody remember integration. 0:36:31.037,0:36:32.305 The joys of integration. 0:36:32.354,0:36:37.126 Integrate the whole system and then make it work. 0:36:37.945,0:36:41.044 And while you're doing that you gonna be stepping all over each other. 0:36:41.354,0:36:49.582 So, if this cycle will bring back the problem of coming in 8 in the morning and find everything doesn't work. 0:36:50.164,0:36:52.095 But it's worse than that. 0:36:52.717,0:36:58.439 Because in order to test conveyor I need alarm. 0:36:58.472,0:37:02.409 Which needs control panel which needs revenue, which need the database. 0:37:02.499,0:37:06.248 The database takes 45 minutes to load and then it crashes. 0:37:06.528,0:37:08.966 I can't run my tests. 0:37:09.026,0:37:13.999 Ant the guys in conveyor saying, "Why the heck do I need the database?" 0:37:14.150,0:37:17.344 "Well, you need the database because of this strange dependency structure." 0:37:17.504,0:37:21.891 Anybody ever look at the number of DLLs that got loaded and scratch head and say, 0:37:21.891,0:37:23.811 "How come I need those?" 0:37:23.849,0:37:26.895 Anybody in C++ world have ever link line? 0:37:26.999,0:37:28.962 And wonder "what's all this stuff in the link line?" 0:37:29.005,0:37:30.530 "How come I need all that stuff?" 0:37:30.564,0:37:32.993 Right? You got cycles in the dependency graphs. 0:37:33.026,0:37:34.532 It's bringing in all kinds of gunk. 0:37:34.599,0:37:42.656 So the first principle of components is no cycles in the components. 0:37:42.695,0:37:45.059 What if you want to do this? 0:37:45.835,0:37:51.747 What if you really want to call some function from down here that lives up there? 0:37:51.747,0:37:53.107 How you gonna do it? 0:37:55.377,0:37:57.370 Well, you can put out another component. 0:37:58.446,0:37:59.868 That's one way to do it. 0:37:59.939,0:38:03.339 Here I took that class out of the control panel. 0:38:03.373,0:38:05.327 I put it in the display component. 0:38:05.327,0:38:07.961 Then the alarm component can talk to the display component. 0:38:07.961,0:38:10.255 The control panel can talk to the display component. 0:38:10.516,0:38:12.199 I can keep the cycles out. 0:38:12.263,0:38:14.242 That's common enough technique. 0:38:14.287,0:38:16.061 Remember, these are all DLLs. 0:38:16.114,0:38:23.034 So number of DLLs in your system will start to grow as people want to add cycles to the dependency graph. 0:38:23.086,0:38:24.603 Maybe. 0:38:25.019,0:38:28.364 Although there's another way to resolve the cycle. 0:38:30.440,0:38:33.076 You can use dependency inversion. 0:38:33.124,0:38:40.010 I could put an interface. A display interface. 0:38:40.064,0:38:42.278 In the alarm subsystem. 0:38:42.330,0:38:44.778 And have the control panel implemented it. 0:38:45.764,0:38:48.321 That turns the dependency around. 0:38:49.643,0:38:52.663 And changes a cycle into a straight tree. 0:38:59.790,0:39:01.324 What's OO? 0:39:04.009,0:39:06.269 What is Object Orientation? 0:39:08.802,0:39:10.474 Why do we like it? 0:39:10.538,0:39:14.936 How come all of our languages are object oriented languages? 0:39:14.936,0:39:16.884 We've been doing this for 30 years. We gotta know. 0:39:16.952,0:39:18.560 (Someone says) "Models the real world." 0:39:18.560,0:39:20.193 Models the real world! Thank you! 0:39:20.193,0:39:22.727 I planted him here so that he would say that. 0:39:22.727,0:39:24.924 So then I could rip him to shred. 0:39:24.974,0:39:26.852 No, that's absurd. 0:39:26.852,0:39:31.641 And that whole idea that OO has better way to model real world is plain non-sense. 0:39:31.712,0:39:35.366 It's something. Some guy concocted long time ago 0:39:35.450,0:39:39.479 To convince his manager to spend 12,000$ on C++ compiler. 0:39:39.512,0:39:42.092 Cause he couldn't figure out any other ways to get his manager to do it. 0:39:42.144,0:39:46.391 12,000$. Early C++ compiler costed a lot of money. 0:39:46.391,0:39:48.092 "12,000$. I'm not spending that for a compiler." 0:39:48.092,0:39:49.961 "Well, it will help me model the real world!" 0:39:49.961,0:39:53.086 "Oh. Okay then." 0:39:53.125,0:39:57.739 This whole notion of modeling the real world is downright silly. 0:39:57.771,0:40:04.560 What in the world is OO other than a bunch of functions using a bunch of data structure? Right? 0:40:04.560,0:40:06.822 Encapsulated. Okay fine. Encapsulated. 0:40:06.822,0:40:09.407 But bunch of functions using bunch of data structures. 0:40:09.407,0:40:11.590 How is that different from Non OO? 0:40:13.393,0:40:15.497 The answer to that is not easy to describe. 0:40:16.282,0:40:18.067 How that's different? 0:40:18.129,0:40:21.940 Well, okay. We kind of put the data structures in the functions together. 0:40:21.994,0:40:23.659 But we always used to do that. 0:40:24.161,0:40:26.806 Old C programmers used to that all the time. 0:40:27.058,0:40:29.959 Data structures in programs always went together. 0:40:29.959,0:40:33.588 There is a famous book called 'Algorithms plus data structures equals programs.' 0:40:34.290,0:40:36.530 Data structures now (??) working together. 0:40:36.583,0:40:39.288 So nothing really fancy about OO there. 0:40:39.288,0:40:43.754 There is one thing that OO gave us that we did not have before. 0:40:43.754,0:40:45.537 Because it wasn't safe. 0:40:45.597,0:40:47.267 And that's polymorphism. 0:40:47.304,0:40:50.987 Very very convenient polymorphism. 0:40:51.024,0:40:53.266 We used to have it in C. 0:40:53.924,0:40:57.898 Device independence in any operating system is an example of polymorphism. 0:40:57.947,0:41:02.791 If you can write a program, you don't need to know what device that program is gonna use. 0:41:02.862,0:41:04.842 It's a clearly polymorphic interface. 0:41:05.568,0:41:08.694 But that's dangerous in most languages. 0:41:08.762,0:41:10.472 Or it was back in those days. 0:41:10.472,0:41:12.262 Because you have to fiddle with pointers to functions. 0:41:12.262,0:41:13.533 And that was always dangerous. 0:41:14.638,0:41:18.563 What OO gave us was very very convenient polymorphism. 0:41:18.639,0:41:20.773 Polymorphism without thinking about it. 0:41:20.773,0:41:23.674 Java in particular all the methods are polymorphic. 0:41:23.674,0:41:25.108 There's no choice. 0:41:25.175,0:41:29.289 C#, you have choice. You can use that funny virtual keyword. 0:41:29.322,0:41:35.234 C++ programmers you've got a choice. You better use that virtual keyword. Especially on your destructors. 0:41:35.871,0:41:38.933 But most of us we don't even pay attention anymore. 0:41:38.933,0:41:42.007 All our functions are polymorphic. We don't even think about it. 0:41:42.055,0:41:42.936 Why? 0:41:44.166,0:41:49.384 Because when a function is polymorphic something amazing happens. 0:41:49.964,0:41:55.192 The flow of control goes down towards to derivatives. 0:41:55.242,0:41:59.150 But the source code dependency goes back towards base. 0:41:59.828,0:42:07.917 We can take a source code dependency and turn it around without changing the run time dependency. 0:42:07.917,0:42:10.110 How do you get DLLs? 0:42:10.110,0:42:11.872 How do you get components? 0:42:11.872,0:42:13.614 You isolate them. 0:42:13.614,0:42:16.954 But you have to maintain the run time dependency. 0:42:21.441,0:42:22.710 Visual Studio people 0:42:24.865,0:42:27.552 Are you using ReSharper? 0:42:28.532,0:42:30.060 Who is? ReSharper? 0:42:30.091,0:42:31.576 Look at that. Everybody. 0:42:32.816,0:42:35.606 Does Visual Studio know about ReSharper? 0:42:38.009,0:42:38.645 No. 0:42:38.718,0:42:42.338 Does Visual Studio call ReSharper? 0:42:43.465,0:42:44.725 Yes. 0:42:44.790,0:42:49.106 The flow of control goes from Visual Studio into ReSharper. 0:42:49.106,0:42:54.477 There are function calls in Visual Studio that their way into ReSharper. 0:42:54.477,0:43:00.686 But there is no source code dependency that moves from Visual Studio into ReSharper. 0:43:00.686,0:43:03.086 Because they've been inverted the dependencies. 0:43:04.025,0:43:09.912 You can create DLLs that your application will call. 0:43:09.945,0:43:12.495 But your application doesn't know it exist. 0:43:12.527,0:43:15.585 And you do that by inverting dependencies. 0:43:15.864,0:43:17.072 Turn them around. 0:43:17.156,0:43:19.280 So this is one nice way to do that. 0:43:19.652,0:43:28.943 Now the control panel is a plug-in to the alarm system. 0:43:29.025,0:43:31.590 The alarm system doesn't know the control panel exists. 0:43:31.590,0:43:35.765 The control panel is a plug-in. 0:43:35.813,0:43:38.609 And the alarm system would accept any kind of plug-in. 0:43:38.609,0:43:42.568 A lot of different things to do implement this display function here. 0:43:42.568,0:43:45.262 So we could have a lot of different things that we alarmed. 0:43:52.942,0:43:55.184 What would rather depend upon? 0:44:01.501,0:44:04.620 A component that was stable? 0:44:07.014,0:44:08.996 Or a component that was unstable? 0:44:10.785,0:44:12.145 Trick questions. 0:44:12.195,0:44:17.812 Right? Everybody knows that you want to depend on something that's stable. 0:44:22.582,0:44:25.278 But now let me define stability. 0:44:28.542,0:44:30.590 Is my laser stable? 0:44:34.332,0:44:36.273 It's not changing. 0:44:38.883,0:44:40.569 But is it stable? 0:44:40.614,0:44:43.667 Stability is not a Boolean. 0:44:43.732,0:44:46.330 Stability is a continuous variable. 0:44:46.379,0:44:50.612 And it is defined as the amount of work required to make a change. 0:44:50.657,0:44:53.396 If it takes a lot of work to make a change, it's stable. 0:44:53.433,0:44:56.250 If it takes very little work to make a change, it's unstable. 0:44:56.301,0:45:00.212 That is unstable. 0:45:00.283,0:45:03.767 Cause it doesn't take much work to make a change to its state. 0:45:03.825,0:45:08.630 This. Well I won't say that it's stable. 0:45:08.736,0:45:11.505 Cause it would take much work to upset it. 0:45:11.542,0:45:14.952 And this whole stage doesn't feel very stable to me. 0:45:15.780,0:45:18.945 So I may have to be careful about the way I move. 0:45:18.976,0:45:21.597 So let me ask the question again. 0:45:21.632,0:45:24.712 What would you rather depend upon? 0:45:24.766,0:45:26.956 Something easy to change? 0:45:26.997,0:45:28.735 Or something hard to change? 0:45:28.774,0:45:33.115 Modify the source code. 0:45:33.725,0:45:35.199 What would you rather depend upon? 0:45:35.199,0:45:39.812 A module whose source code was hard to change or a module whose source code was easy to change? 0:45:42.290,0:45:43.366 Same answer. 0:45:43.439,0:45:45.699 You wanna depend upon thing that hard to change. 0:45:45.731,0:45:48.997 And the reason behind that is very simple. 0:45:48.997,0:45:51.956 Do you mind depending on string? 0:45:51.988,0:45:52.725 No. 0:45:52.725,0:45:54.946 Why don't you mind depending on string? 0:45:54.946,0:45:58.409 Cause if those guys ever change string, they'll be held to pay. 0:45:59.679,0:46:01.405 They would suffer more than you. 0:46:01.619,0:46:04.157 That's the equation that we're talking about here. 0:46:04.157,0:46:06.488 You are happy to do depend upon something, 0:46:06.528,0:46:11.525 if it will hurt the authors of that thing more to change it than hurts you. 0:46:11.564,0:46:13.814 That's the equation. 0:46:13.854,0:46:15.598 You are happy to depend upon things 0:46:15.598,0:46:19.202 as long as you're not likely to change or at least the bastards gonna pay if they change. 0:46:19.202,0:46:25.356 So alright, we don't want to depend on things that are easy to change. 0:46:27.384,0:46:28.906 Think about that very carefully. 0:46:28.906,0:46:32.846 I don't want to depend on something easy to change. 0:46:34.594,0:46:40.272 Do we design parts of our system so that they will be easy to change? 0:46:42.648,0:46:43.785 Yes. 0:46:44.137,0:46:49.977 What parts of our system do we most want to be easy to change? 0:46:53.137,0:46:54.321 The GUI. 0:46:56.888,0:46:58.286 GUIs are volatile. 0:46:58.286,0:47:01.589 They change for no good reason at all. 0:47:01.622,0:47:05.068 People will change GUI just because they feel like it. 0:47:05.105,0:47:07.851 There will be some committee (??) to say, 0:47:07.851,0:47:09.743 "You know, our system look so old." 0:47:09.780,0:47:11.500 What the hell does that mean? 0:47:11.500,0:47:14.542 "Our system look so old, we need to give it a face lift." 0:47:14.902,0:47:19.376 "Marketing people have decided, we’ve gotta have whole new look and feel." 0:47:19.410,0:47:21.035 "Not gonna change any behavior." 0:47:21.090,0:47:22.895 "Just look and feel of the GUI." 0:47:22.927,0:47:25.044 GUI has to be easy to change. 0:47:25.044,0:47:28.509 The modules that hold that source code have to be easy to change 0:47:28.549,0:47:33.005 And that means that none of you modules should depend on the GUI. 0:47:33.627,0:47:36.668 No source code dependency should land on the GUI. 0:47:37.533,0:47:41.976 Your components should not have dependencies that land on the GUI. 0:47:42.029,0:47:45.183 GUI components have to depend upon the application. 0:47:45.226,0:47:48.528 Application component cannot depend upon the GUI. 0:47:49.110,0:47:53.207 Otherwise you wind up with the systems that wear the GUIs hard to change. 0:47:53.254,0:47:56.567 How many of you test your systems? 0:47:56.617,0:47:57.882 Automated test. 0:47:58.844,0:47:59.910 Through the GUI. 0:48:02.644,0:48:03.858 Got a couple of people. 0:48:04.807,0:48:06.618 You write test code through the GUI. 0:48:07.383,0:48:11.009 You are depending upon something that supposed to be easy to change. 0:48:11.058,0:48:13.231 You'll make it hard to change. 0:48:13.296,0:48:15.598 If you test your system through the GUI. 0:48:15.667,0:48:19.399 I have a client who have 15,000 tests all go through the GUI. 0:48:19.432,0:48:20.850 Same client, by the way. 0:48:20.934,0:48:22.070 Same one went out of the business. 0:48:22.102,0:48:25.786 15,000 tests through the GUI. 0:48:25.838,0:48:29.291 He had so many tests he didn't know what they were anymore. 0:48:29.324,0:48:30.828 He just knew they all had to pass. 0:48:30.863,0:48:32.783 If somebody touch the GUI 0:48:32.819,0:48:35.233 a thousand of those test would break. 0:48:35.283,0:48:37.060 He couldn't find the time to fix them. 0:48:37.108,0:48:39.223 So he came up with real simple rule. 0:48:39.265,0:48:40.797 What do you think that rule was? 0:48:40.851,0:48:43.575 No body touches the GUI. 0:48:43.611,0:48:47.117 They made the GUI hard to change. 0:48:47.532,0:48:51.696 The other thing of course could happened there is that you could lose your tests. 0:48:52.566,0:48:58.428 You spend a man year putting together nice automated test suite that go through the GUI. 0:48:58.468,0:49:01.944 And then somebody decides, "We need a face lift on our site." 0:49:01.984,0:49:04.359 "Pull all out the old GUI and put a brand new GUI" 0:49:04.404,0:49:05.969 And all those tests are gone. 0:49:06.000,0:49:09.706 And you get to rewrite them again, but you've got other systems you gotta test. 0:49:09.748,0:49:11.771 Don't test through the GUI. 0:49:11.809,0:49:13.777 Don't do anything through the GUI. 0:49:13.777,0:49:19.387 All dependencies point away from the GUI. 0:49:19.450,0:49:22.799 What other things do we want to be easy to change? 0:49:22.881,0:49:26.047 The database. 0:49:26.047,0:49:28.340 We want the database to be easy to change. 0:49:28.340,0:49:32.347 We want to be able to make changes to database without rippling through the whole applications. 0:49:33.814,0:49:37.646 All dependencies you should point away from the database. 0:49:37.646,0:49:40.613 Put the database in a component with all the dependencies pointing outwards. 0:49:40.681,0:49:44.228 Put the GUI into a component with all the dependencies pointing outwards. 0:49:46.310,0:49:54.150 I don't want to depend on anything that is unstable. 0:49:54.701,0:49:58.444 How can we measure instability? 0:50:02.013,0:50:03.818 See this guy up here? 0:50:04.997,0:50:06.322 That component up there? 0:50:06.750,0:50:08.926 Is he Stable? Or Unstable? 0:50:09.001,0:50:13.261 He's got lots of incoming dependencies. 0:50:13.329,0:50:15.624 No outgoing dependencies. 0:50:15.687,0:50:17.099 He's hard to change. 0:50:17.152,0:50:20.353 If I make a change to him, it impacts all those guys. 0:50:20.404,0:50:24.940 So this component here is responsible to those guys. 0:50:25.010,0:50:28.996 Oh and this component here is independent. 0:50:29.077,0:50:30.892 It doesn't depend on anybody. 0:50:30.892,0:50:32.803 It's responsible and independent. 0:50:32.803,0:50:33.852 I's an adult. 0:50:36.724,0:50:39.079 Stable. Adult. 0:50:40.048,0:50:41.089 This guy. 0:50:41.619,0:50:44.444 He depends on lots of other components. 0:50:44.953,0:50:46.787 No body depends upon him. 0:50:46.840,0:50:48.367 Is he responsible? 0:50:48.434,0:50:49.643 And dependent? 0:50:49.682,0:50:51.274 He's teenager. 0:50:52.014,0:50:53.581 And he's unstable. 0:50:54.058,0:50:57.624 These are the two extreme kinds of components. 0:50:57.683,0:51:00.395 At the two sides of component spectrum. 0:51:00.429,0:51:02.870 You've got the adults that highly stable. 0:51:02.937,0:51:06.786 And you’ve got the teenager who are highly unstable. 0:51:06.878,0:51:09.071 The unstable ones are easy to change. 0:51:09.154,0:51:11.685 That's what we wanna put all of our little code. 0:51:12.391,0:51:15.128 The stable ones are hard to change. 0:51:16.378,0:51:22.870 We can measure that stability by creating a metric. 0:51:22.902,0:51:25.828 That metric is a metric that I call "I" 0:51:26.816,0:51:33.597 'I' is equal to the fan-out. Number of outgoing dependencies. 0:51:33.669,0:51:37.095 Divided by the fan-in plus the fan-out. 0:51:37.183,0:51:40.231 And if you think about that for very long. 0:51:40.263,0:51:43.563 You'll realize that 'I' is a metric that goes from 0 to 1. 0:51:43.647,0:51:46.835 0 being stable. 1 being unstable. 0:51:46.869,0:51:50.026 0 being an adult. 1 being a teenager. 0:51:50.092,0:51:53.337 It’s all about the dependencies. 0:51:53.370,0:51:59.273 And now we can re-phrase the principle to say this. 0:52:05.664,0:52:13.948 Every dependency in a component graph should point at something more stable than it is. 0:52:14.348,0:52:21.748 Or, if use the metric, these arrow should point in the direction of decreasing 'I'. 0:52:21.827,0:52:25.394 Decreasing instability. Increasing stability. 0:52:25.426,0:52:30.656 And you can do the math on just the fan-ins and fan-outs and verify that's correct. 0:52:31.576,0:52:36.733 Why was the cycle bad idea? 0:52:37.981,0:52:41.441 Something stable depended on something unstable. 0:52:44.864,0:52:48.128 But that leaves us with a problem. 0:52:48.167,0:52:49.920 And the problem is this. 0:52:54.953,0:52:56.228 What's that guy? 0:52:57.662,0:52:59.327 Stable? Or unstable? 0:53:01.337,0:53:02.724 He's really stable. 0:53:02.774,0:53:05.103 He's sitting down here the bottom of the graph. 0:53:05.175,0:53:07.800 Everything over here depends on him. 0:53:08.595,0:53:10.422 He's very hard to change. 0:53:10.764,0:53:14.927 If I touch that component, all these other components will be affected by. 0:53:14.927,0:53:18.348 For no other reason than the release number changes. 0:53:23.941,0:53:29.017 That means the stuffs down here at the bottom of graph is very difficult to work with. 0:53:30.887,0:53:33.373 But there's an escape to that. 0:53:33.725,0:53:35.338 Back to polymorphism. 0:53:36.750,0:53:42.927 How can you make something easy to extend? 0:53:43.791,0:53:46.479 Even though it's hard to modify. 0:53:48.710,0:53:50.260 You make it abstract. 0:53:51.098,0:53:54.422 Abstract classes can be extended trivially. 0:53:55.209,0:53:57.365 Without having it modified. 0:53:57.456,0:54:00.423 You can add new features to a system 0:54:00.472,0:54:05.741 if those new features live inside the derivatives of base classes. 0:54:06.201,0:54:08.904 So the final principle is this. 0:54:09.760,0:54:16.153 We would like abstractness to increase as we go down the zeros. (??) 0:54:16.185,0:54:18.480 Stuff up here concrete. 0:54:18.513,0:54:20.310 Unstable and concrete. 0:54:20.310,0:54:23.135 Stuff down here abstract and stable. 0:54:23.135,0:54:30.237 Abstractness becomes more and more prevalent as we go down this tree. 0:54:32.090,0:54:39.393 In fact, we could say that abstractness is a number 0:54:39.425,0:54:46.424 which is the number of abstract classes divided by the total number of classes in a component. 0:54:46.895,0:54:50.355 And if you did that, you get this number 'A' which goes 0 to 1. 0:54:50.355,0:54:51.672 0 being concrete. 0:54:51.708,0:54:54.826 1 being entirely abstract. Composed of nothing but interfaces. 0:54:54.878,0:54:58.622 And then we can do this very interesting thing. 0:54:58.698,0:55:09.120 We can say that for any particular component 'A' plus 'I' should equal 1. 0:55:09.152,0:55:13.091 Either it's abstract where 'A' is 1. 0:55:13.129,0:55:15.504 And stable where 'I' is 0. 0:55:15.541,0:55:19.557 Or it is instable where 'I' is 1. 0:55:19.606,0:55:21.130 And concrete where 'A' is 0. 0:55:21.130,0:55:23.375 'A' plus 'I' equals 1. 0:55:23.423,0:55:26.733 The magic formula of components. 'A' plus 'I' equals 1. 0:55:26.733,0:55:30.863 Now you've got the adults up here which are abstract 0:55:30.897,0:55:33.340 And everybody depends upon them. So they are stable. 0:55:33.378,0:55:35.859 You've got the teenagers down here. 0:55:37.254,0:55:41.781 Everybody that's got no incoming dependencies but they're very concrete. 0:55:41.815,0:55:43.602 What do you got here? 0:55:43.635,0:55:47.142 This is the line 'A' plus 'I' equals 1. 0:55:48.472,0:55:53.458 This is where we would like our components to sit if they can sit. One of those two end points. 0:55:53.499,0:55:54.376 Why? 0:55:55.583,0:55:59.496 Well, what's up here? 0:56:00.981,0:56:03.951 Highly abstract. Nobody depends upon on it. 0:56:05.366,0:56:08.097 An interface that nobody implements. Useless. 0:56:08.729,0:56:11.022 This is the zone of uselessness. 0:56:11.067,0:56:14.316 We don't want our components going that way. 0:56:14.388,0:56:15.600 What's down here? 0:56:17.040,0:56:19.658 Very concrete. Everybody depends upon on it. 0:56:20.230,0:56:21.560 Database schemas. 0:56:23.292,0:56:25.212 Concrete. Everybody depends upon them. 0:56:25.262,0:56:26.519 Fun to change. 0:56:27.371,0:56:29.629 Right? We don't want things down here. 0:56:29.669,0:56:31.019 This is the zone of pain. 0:56:31.713,0:56:36.199 We would like our components to be as far from those 2 points as possible. 0:56:36.199,0:56:39.298 Ideally if we could get them here and here that would be best. 0:56:39.333,0:56:42.253 But it turns out the components are persnickety that way. 0:56:42.304,0:56:45.450 So at least we'd like them to be sitting along this line. 0:56:45.962,0:56:48.414 Or close to the line. 0:56:48.914,0:56:51.407 Which leaves us the one last metric. 0:56:52.574,0:56:53.566 'D' 0:56:54.316,0:56:56.975 How far away is a component from the line? 0:56:57.594,0:57:02.086 Well, 'D' could be the absolute value of 'A' plus 'I' minus 1. 0:57:02.086,0:57:04.714 You can do the math on this. It's not very difficult. 0:57:04.714,0:57:07.210 'D' is the metric that goes from 0 to 1. 0:57:07.460,0:57:09.574 0 means that right on the line. 0:57:09.607,0:57:11.638 1 means that one of the two bad end points. 0:57:12.111,0:57:14.831 If you wanna know which end point you can take the absolute value signs off. 0:57:14.831,0:57:16.361 But I don't care. 0:57:16.481,0:57:22.408 You can measure 'D' by looking at the fan-in and the fan-out of the component. 0:57:22.437,0:57:23.996 Measuring its abstractness. 0:57:24.075,0:57:27.696 Doing the math is not very difficult math to do. 0:57:27.733,0:57:33.595 And find out whether your component sits nicely on that line. 0:57:34.044,0:57:40.423 If it does then it is abstract as it is depended upon. 0:57:41.387,0:57:46.815 If it doesn't that means either it's very abstract and not depended on 0:57:46.885,0:57:49.023 or very concrete and heavily depended upon. 0:57:49.023,0:57:50.361 Both of which are very bad ideas. 0:57:51.455,0:57:55.190 There are lots of tools that automatically calculate these metrics for you. 0:57:55.261,0:57:58.665 If you ever used NDepend. That will calculate the metrics for you. 0:57:58.698,0:58:02.580 If you ever used any of the other static analysis tools, 0:58:02.658,0:58:06.184 they can generate all these metrics. I. D. All of them for you. 0:58:06.255,0:58:09.529 So that you can look at your components and see if they fit. 0:58:09.568,0:58:14.219 And then think about what should be easy to change. 0:58:14.825,0:58:17.924 Things that are easy to change should be in teenagers. 0:58:19.047,0:58:23.650 Things that are hard to change should be in adults that are abstract. 0:58:23.650,0:58:27.629 Concrete teenagers hold the stuff that's easy to change. 0:58:28.283,0:58:31.796 Abstract adults hold the stuff that's hard to change. 0:58:32.967,0:58:34.178 Any questions? 0:58:36.316,0:58:40.364 We started with PDP-8 assembly code and got here. 0:58:42.809,0:58:44.617 Any questions? No? 0:58:45.151,0:58:45.653 Good. 0:58:46.559,0:58:47.809 Oh, damn. 0:58:49.760,0:58:51.276 It's alright. It's okay. 0:58:51.393,0:58:56.854 (Someone is questioning.) 0:58:56.854,0:58:57.486 Yep. 0:58:57.486,0:59:03.080 (Someone is questioning) 0:59:03.080,0:59:04.955 2 versions. 0:59:04.955,0:59:07.015 (Someone is questioning) 0:59:07.015,0:59:10.351 Yeah, 2 versions. Same component. You kill the programmers. 0:59:10.540,0:59:11.189 Yeah. 0:59:11.599,0:59:15.284 Don't have multiple versions of same component in you system please. 0:59:15.320,0:59:16.923 That's DLL Hell. 0:59:17.847,0:59:19.909 Anybody else? Yeah. 0:59:21.349,0:59:24.025 Where do you place...? Very very good question. 0:59:24.025,0:59:26.186 String class sits right there. 0:59:26.952,0:59:31.841 It's in the worst possible place but nobody ever changes it. So we don't care. 0:59:32.118,0:59:35.767 This is all about the stuff we are actively developing. 0:59:35.809,0:59:37.831 The stuff that is being changed. 0:59:38.061,0:59:42.786 So we pay very close attention to the stuff that's in our libraries that are changing. 0:59:42.786,0:59:45.880 The stuff that we get from other libraries that's not changing. 0:59:45.918,0:59:49.029 Or the stuff that's in our old libraries that's not changing. 0:59:49.066,0:59:50.470 We not gonna pay attention to that here. 0:59:50.513,0:59:52.332 A lot of that stuff may live here. 0:59:52.332,0:59:53.456 And that's okay. 0:59:53.456,0:59:54.923 None of it's gonna live here. 0:59:55.733,0:59:57.620 Well, some of it might. 0:59:57.620,0:59:59.589 Anybody pull out any dead code? 0:59:59.624,1:00:01.948 Abstract classes that nobody implements? 1:00:02.007,1:00:04.869 Yeah, okay. So maybe you see some stuffs there. 1:00:04.901,1:00:11.720 But String, Vector, a lot of libraries live down here we don't care because they're not volatile. 1:00:11.756,1:00:16.272 Think of another axis is coming out from this graph, right, towards you. 1:00:16.306,1:00:18.368 That's the axis of volatility. 1:00:18.368,1:00:21.573 This is a slice where volatility is close to 1. 1:00:22.123,1:00:24.836 The stuff where volatility is 0, we don't care about it. 1:00:26.136,1:00:27.084 Anybody else? 1:00:27.963,1:00:29.200 Yo! In the back.