1 00:00:04,001 --> 00:00:07,507 Ready? Is Sound On? 2 00:00:08,922 --> 00:00:10,753 Cool. Alright. So. 3 00:00:22,778 --> 00:00:25,208 Do you see that red dot? 4 00:00:30,020 --> 00:00:31,743 Why is it red? 5 00:00:35,418 --> 00:00:36,934 It's dangerous. 6 00:00:37,798 --> 00:00:41,339 I like that answer. Watch out! Take me to the Cuba. 7 00:00:43,073 --> 00:00:51,915 Yeah, I've had the security people restricted me from going in the airports, because I'm carrying lasers with me. 8 00:00:51,988 --> 00:00:55,109 They have, you know, sign on and it says dangerous. 9 00:00:56,990 --> 00:00:59,148 But, why is that red? 10 00:01:01,035 --> 00:01:02,399 I have a green laser. 11 00:01:02,469 --> 00:01:05,432 Hey, you know, you gotta have lasers. 12 00:01:06,280 --> 00:01:09,323 Alright? I carry three of them with me. 13 00:01:11,184 --> 00:01:15,861 One of them is red. I always keep them in my back pack with the batteries (??). 14 00:01:15,901 --> 00:01:17,887 Or turned around actually. 15 00:01:18,277 --> 00:01:22,806 So this is my red laser. You can get a red laser for twelve dollars. 16 00:01:24,341 --> 00:01:25,436 There it is. Red laser. 17 00:01:25,460 --> 00:01:28,763 Nice. And I got a green laser. 18 00:01:30,029 --> 00:01:31,272 This one is nice one. 19 00:01:33,062 --> 00:01:34,684 A pretty bright one too. 20 00:01:34,752 --> 00:01:39,001 Not bright enough to do anything interesting, but bright. 21 00:01:39,075 --> 00:01:41,025 There is little adjustment in here. 22 00:01:41,025 --> 00:01:44,585 You can cut a component out and put a different register in here. 23 00:01:44,595 --> 00:01:47,797 Then you can get almost of quarter of Watt out of it. 24 00:01:47,847 --> 00:01:50,857 The battery drains pretty fast. You can pop a balloon with it. 25 00:01:51,668 --> 00:01:54,919 I mean that's cool. Boom. 26 00:01:57,124 --> 00:02:00,599 But this is my favorite laser. 27 00:02:02,496 --> 00:02:05,139 And I like this one because 28 00:02:06,698 --> 00:02:12,734 Well, can you see that? 29 00:02:14,716 --> 00:02:19,295 Little tiny violet dot. Do you see that up there? 30 00:02:20,906 --> 00:02:24,869 See if I can show it to you here. Oh! That’s nice and bright. 31 00:02:25,269 --> 00:02:27,833 On my thing here. That's nice and bright. 32 00:02:28,344 --> 00:02:31,192 But over there, you can hardly see it. 33 00:02:31,445 --> 00:02:33,524 Can you see this thing? No. 34 00:02:33,559 --> 00:02:35,886 Can you see it here? No, not too much. 35 00:02:36,492 --> 00:02:39,445 No, can't see it there much. 36 00:02:39,477 --> 00:02:48,820 But, I found this once. 37 00:02:51,325 --> 00:02:57,433 Just a marker. Litter laser doesn't do too much to the marker. 38 00:02:57,465 --> 00:02:59,458 But the lid! 39 00:03:02,153 --> 00:03:05,457 And look! It's yellow! 40 00:03:05,529 --> 00:03:07,331 It's not blue! 41 00:03:08,210 --> 00:03:11,093 And then see that little orange thing there? 42 00:03:11,093 --> 00:03:13,747 Watch this! I gotta aim it carefully. 43 00:03:14,353 --> 00:03:17,780 Wow! It's orange. 44 00:03:17,838 --> 00:03:19,988 What kind of laser is this? 45 00:03:22,060 --> 00:03:26,491 This is a laser of some other color. 46 00:03:33,884 --> 00:03:41,141 My glasses are the kind that turn dark in the sun light. 47 00:03:44,719 --> 00:03:47,650 I don't know if you can tell. But now there are all dark. 48 00:03:47,688 --> 00:03:50,853 Alright? And I can't see any of you. 49 00:03:50,917 --> 00:03:53,470 This is an ultra violet laser. 50 00:03:53,560 --> 00:03:57,504 They don't bill it as such. You can buy them on amazon. 17$. 51 00:03:57,504 --> 00:04:01,100 They say it's a violet laser. They lie. 52 00:04:01,368 --> 00:04:06,948 It's much cooler than violet laser. It's an ultra violet laser. 53 00:04:06,948 --> 00:04:09,637 Everybody has to have an ultraviolet laser. 54 00:04:09,703 --> 00:04:12,649 It's completely useless as a laser pointer. 55 00:04:12,701 --> 00:04:16,997 But you can draw nice little pictures on you glasses with it. 56 00:04:18,598 --> 00:04:21,843 Oh~ I got my name. 57 00:04:24,672 --> 00:04:26,507 Alright. Whatever. 58 00:04:29,240 --> 00:04:31,126 Look at the code on the screen. 59 00:04:32,639 --> 00:04:34,428 Anybody recognize that code? 60 00:04:35,765 --> 00:04:38,325 I can't see it because my glasses are all dark. 61 00:04:38,771 --> 00:04:40,798 Anybody recognize that code? 62 00:04:42,267 --> 00:04:44,242 That's PDP-8 code. 63 00:04:44,945 --> 00:04:48,863 That what code looked like in 1970s. 64 00:04:48,928 --> 00:04:54,753 That's kind of code I was writing when I was slightly older teenager. 65 00:04:55,825 --> 00:04:58,618 And then on into my twenties as well. 66 00:05:00,074 --> 00:05:03,543 This statement right there. 67 00:05:03,979 --> 00:05:06,305 Anybody know what that means? 68 00:05:07,940 --> 00:05:13,611 That's the memory address which this program would be loaded. 69 00:05:15,334 --> 00:05:20,159 We used to write the address our program into our program. 70 00:05:21,160 --> 00:05:23,551 This program would be loaded at address 200. 71 00:05:24,245 --> 00:05:26,996 And we put the data at address 300. 72 00:05:27,042 --> 00:05:28,052 How about that? 73 00:05:28,669 --> 00:05:32,636 And it makes perfect sense. Of course you would know where programs getting get loaded. 74 00:05:32,668 --> 00:05:34,836 I mean who else is gonna decide that for you? 75 00:05:34,905 --> 00:05:37,708 You are the programmer. You have control over memory. 76 00:05:39,471 --> 00:05:41,323 Now, this works fine. 77 00:05:43,026 --> 00:05:45,572 I'll show you a sequence of pictures here. 78 00:05:46,268 --> 00:05:50,080 Let's see. Yeah, that's a nice one. 79 00:05:50,151 --> 00:05:55,087 Hello. No, that's not the one what I wanted. 80 00:05:56,140 --> 00:06:01,655 That's because nowadays when you open up documents 81 00:06:02,386 --> 00:06:09,623 It opens up every document that's been opened by that application. 82 00:06:10,509 --> 00:06:12,138 Don't save that. 83 00:06:12,177 --> 00:06:14,630 That's the one I wanted, right there. 84 00:06:17,049 --> 00:06:20,356 Imagine you are programmer who's writing this kind of code. 85 00:06:20,899 --> 00:06:23,826 And you've got a program like this one. 86 00:06:24,626 --> 00:06:28,010 My program lives here. It starts at address 200. 87 00:06:28,900 --> 00:06:32,107 And there's a subroutine library that somebody else has written. 88 00:06:32,524 --> 00:06:35,145 By the way subroutine libraries were not real common. 89 00:06:35,229 --> 00:06:37,768 You usually wrote your own subroutine back in those days. 90 00:06:37,818 --> 00: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." 91 00:06:45,637 --> 00:06:50,378 And you think, "Well, just compile them in with my code" 92 00:06:50,411 --> 00:06:51,663 That's what we used to do. 93 00:06:51,695 --> 00:06:53,496 You just take the source code and jam it together. 94 00:06:53,531 --> 00:06:55,465 What was the problem with that? 95 00:06:58,735 --> 00:07:02,218 We were talking about the 1970s here. Right? 96 00:07:02,314 --> 00:07:05,566 Those programs were contained on paper tape. 97 00:07:06,124 --> 00:07:10,498 Paper tapes is being 50 characters per second, if you were lucky. 98 00:07:10,534 --> 00:07:19,939 And so increasing the size of your source code lengthened the size of your compile by minutes. 99 00:07:20,346 --> 00:07:26,642 So after a while these subroutine libraries got too long to continue to add your source code. 100 00:07:26,642 --> 00:07:35,124 So what we did is we would compiled the subroutine library and we would loaded at location 1200. 101 00:07:35,847 --> 00:07:42,367 Then what we could do is we could have a binary file which got loaded at 1200. 102 00:07:42,417 --> 00:07:45,363 And we could have our program at 200. 103 00:07:45,396 --> 00:07:49,044 And we did have a little file that all the symbols in it. 104 00:07:49,122 --> 00:07:55,016 So the symbols would tell us which subroutine was loaded where. 105 00:07:55,016 --> 00:08:03,131 So we knew the Get subroutine was at 205 and the Put subroutine was at 210 and so on. 106 00:08:03,518 --> 00:08:06,998 And our symbols would get compiled in with the program 107 00:08:07,032 --> 00:08:09,907 The subroutine would be loaded separately. And everything worked fine. 108 00:08:12,236 --> 00:08:14,215 What's the problem with this? 109 00:08:15,705 --> 00:08:19,428 When is the last time you saw a program that stayed small? 110 00:08:20,839 --> 00:08:22,122 They grow! 111 00:08:22,634 --> 00:08:26,489 And after a while, well let's see. 112 00:08:28,017 --> 00:08:29,632 I got another picture here. 113 00:08:34,783 --> 00:08:36,475 Yeah, that's that one. 114 00:08:40,664 --> 00:08:43,767 Oh yeah, a program that got too big. 115 00:08:43,767 --> 00:08:47,278 It overwrites the subroutines. This doesn't work. 116 00:08:49,171 --> 00:08:56,041 When your program overwrites the subroutines, your program still thinks that the subroutines are there. 117 00:08:56,073 --> 00:09:02,337 So when it calls the location 1205 it actually jumps into some arbitrary part of you code. 118 00:09:02,577 --> 00:09:04,491 You didn't know this happened of course. 119 00:09:04,510 --> 00:09:08,095 Until finally you debugged it and realized. "Oh, my programs got too big!" 120 00:09:08,914 --> 00:09:11,360 What's the solution to this? 121 00:09:13,744 --> 00:09:17,567 You are programmers, you can come up with the solution to this. 122 00:09:20,598 --> 00:09:23,282 Jump around the subroutine library. 123 00:09:23,954 --> 00:09:27,486 Right? You put it Jump right there to jump over here. 124 00:09:28,322 --> 00:09:31,370 Of course the subroutine library gets bigger too. 125 00:09:32,140 --> 00:09:39,809 And so after a while. Let's see if I've got that picture right. 126 00:09:39,842 --> 00:09:42,093 How about that one? Yeah, that's the one. 127 00:09:42,505 --> 00:09:45,243 After a while you get that problem. 128 00:09:48,209 --> 00:09:50,504 We actually faced to this problems. 129 00:09:51,014 --> 00:09:53,910 We actually had to deal with this stuff. 130 00:09:53,946 --> 00:09:55,702 And you know how we solved it? 131 00:09:59,595 --> 00:10:04,698 We came up with relocatable code. 132 00:10:04,730 --> 00:10:10,495 We said "You know what? This idea of putting absolute address in the program is killing us." 133 00:10:10,528 --> 00:10:17,440 "What we really like to do is compile our programs without telling them where they're going to be loaded." 134 00:10:17,813 --> 00:10:20,630 "And then we'll tell the loader where to load them" 135 00:10:21,435 --> 00:10:23,141 Now there's problem with that. 136 00:10:23,632 --> 00:10:29,658 Because that means that your binary files cannot really be binary. 137 00:10:29,705 --> 00:10:38,706 They have to have codes in them to tell you that certain address are not actually addresses. They are offsets. 138 00:10:39,030 --> 00:10:47,994 And the loader has to find every address that's marked as an offset and add the start address to it. 139 00:10:49,321 --> 00:10:51,940 But that works. We had relocatable loaders. 140 00:10:51,988 --> 00:10:54,619 We made this relocatable binaries and loaders. 141 00:10:54,619 --> 00:10:57,034 But now you've got another problem. 142 00:10:57,234 --> 00:11:00,415 Because how do you know where the subroutines are. 143 00:11:00,447 --> 00:11:05,737 If the subroutines are moving all over the place, how do you know where the subroutines are? 144 00:11:06,007 --> 00:11:11,043 So now you have to add more information to the binary file. 145 00:11:11,264 --> 00:11:19,687 This binary file you thought just binary of your program is now becoming very bizarre files. 146 00:11:19,726 --> 00:11:21,301 It's got all kinds of gunky in it. 147 00:11:21,372 --> 00:11:28,293 Now you have to put the names of the subroutine library into the binary file of the subroutines. 148 00:11:28,357 --> 00:11:32,468 And you have to show what address they will get loaded at 149 00:11:32,523 --> 00:11:37,614 And relocatable loader has to remember where it put those addresses 150 00:11:37,682 --> 00:11:42,622 And then in the program you have to have another thing in there. 151 00:11:42,694 --> 00:11:47,250 That says "Hey, I need to know where this programs gonna be loaded" 152 00:11:47,250 --> 00:11:53,432 "And the loader has to link the subroutine library of the program." 153 00:11:57,322 --> 00:12:00,831 Computers were slow in those days. 154 00:12:00,899 --> 00:12:02,548 Disk drivers were very slow. 155 00:12:02,626 --> 00:12:04,539 And there wasn't a lot of disk memory. 156 00:12:04,621 --> 00:12:08,102 You were lucky if you had megabytes of disk. 157 00:12:08,173 --> 00:12:14,636 And the seek arm took a long time and the rotational latency was high. 158 00:12:14,673 --> 00:12:18,136 So link times took a long time. 159 00:12:18,201 --> 00:12:22,206 Especially as we got more and more libraries. 160 00:12:22,257 --> 00:12:23,743 More and bigger program. 161 00:12:23,784 --> 00:12:26,032 Link time could take an hour. 162 00:12:26,082 --> 00:12:28,448 Anybody have a link that took an hour? 163 00:12:28,480 --> 00:12:30,845 Anybody here working in the 80s? 164 00:12:30,880 --> 00:12:32,694 Oh no! You got one now! 165 00:12:32,776 --> 00:12:35,263 You must be C++ programmer. 166 00:12:36,524 --> 00:12:38,661 That says so, right on your shirt. 167 00:12:38,701 --> 00:12:40,747 OSLO C++ Users Group. 168 00:12:41,137 --> 00:12:42,647 Long link times. 169 00:12:45,358 --> 00:12:50,458 Even in the 70s we had that problem. Although it was much smaller programs. 170 00:12:50,500 --> 00:12:57,964 So the solution to that was to separate the link pace from the load pace. 171 00:12:57,964 --> 00:13:02,302 We would link as a second compile step. 172 00:13:02,302 --> 00:13:07,435 And that would produce a final relocatable file that had all the linkage were resolved. 173 00:13:07,468 --> 00:13:10,141 And then we could load it at run time. 174 00:13:10,141 --> 00:13:12,488 Ant that was relatively fast enough. 175 00:13:13,287 --> 00:13:17,964 And for years and years and years. We lived with this 2 step process. 176 00:13:18,015 --> 00:13:24,358 Compile down to binary files then link all the binary files into an executable. 177 00:13:24,401 --> 00:13:26,497 And then you can load the executable. 178 00:13:26,531 --> 00:13:29,877 And that solved problem until the 90s. 179 00:13:29,942 --> 00:13:33,540 In the 90s something happened. 180 00:13:33,588 --> 00:13:36,238 It was called Moore's Law. 181 00:13:36,772 --> 00:13:38,009 What's Moore's law? 182 00:13:39,302 --> 00:13:43,558 The speed of processors will double every 18 month. 183 00:13:43,671 --> 00:13:52,960 Now apply that from about 1970 when the speed of our processors were half a million instructions per second. 184 00:13:53,640 --> 00:13:56,959 And keep that going forward until the 1990s. 185 00:13:57,025 --> 00:13:59,999 Well that's 20 years, how many 18 cycles is that? 186 00:14:00,048 --> 00:14:02,176 Well, 18 month cycle is that? 187 00:14:02,176 --> 00:14:03,981 That's about 15 cycles. 188 00:14:03,981 --> 00:14:07,257 So we have 2^15 increase in speed. 189 00:14:08,369 --> 00:14:09,286 Think about that. 190 00:14:09,338 --> 00:14:11,523 2^15 increase in speed. What is that? 191 00:14:11,602 --> 00:14:13,700 That's increase about 32000! 192 00:14:13,700 --> 00:14:15,171 That's about right too. 193 00:14:15,223 --> 00:14:18,751 Cause we went from about a half MHz to 2.8 GHz. 194 00:14:18,786 --> 00:14:21,746 Well, maybe 1 GHz by the late 90s. 195 00:14:21,787 --> 00:14:24,907 By that time disks were going faster too. 196 00:14:24,941 --> 00:14:27,232 We spun up a lot faster in the road. 197 00:14:27,300 --> 00:14:31,782 The heads weren't moving as far, we were getting a lot more bits around rim too. 198 00:14:31,830 --> 00:14:38,692 We could get hundreds of MBs on a disk. Oh! 199 00:14:40,512 --> 00:14:44,219 And somebody made a bright thought. 200 00:14:44,270 --> 00:14:46,157 Somebody had a bright thought that 201 00:14:47,454 --> 00:14:50,440 "We don't have to do the link separately anymore." 202 00:14:51,042 --> 00:14:54,378 "We can do the link at the same time we load." 203 00:14:54,424 --> 00:14:56,582 Anybody remember the ActiveX? 204 00:14:56,621 --> 00:14:58,946 Anybody remember OLE? 205 00:14:59,546 --> 00:15:01,917 What does DLL stands for? 206 00:15:04,119 --> 00:15:08,215 Dynamically linked library. 207 00:15:08,258 --> 00:15:11,120 Which means it's linked at load time. 208 00:15:11,153 --> 00:15:14,817 The link step got moved back into the loader. 209 00:15:15,699 --> 00:15:19,203 And we have the situation we have today. 210 00:15:20,762 --> 00:15:22,616 Who's .NET programmer, here? 211 00:15:23,668 --> 00:15:25,037 Look at that. A lot of people. 212 00:15:25,070 --> 00:15:28,122 Java programmer! Raise your hands. 213 00:15:28,189 --> 00:15:29,952 Not so many. How come? 214 00:15:31,001 --> 00:15:35,314 How come it's all .NET? Oh maybe because it's a .NET kind of conference? Huh? 215 00:15:36,034 --> 00:15:41,840 So, in .NET you got DLLs. 216 00:15:41,872 --> 00:15:43,732 Dynamically Linked Libraries. 217 00:15:43,765 --> 00:15:45,922 In Java, you got Jar files. 218 00:15:45,969 --> 00:15:50,940 But they are still dynamically linked libraries. Same idea. Same purpose. 219 00:15:51,780 --> 00:15:56,055 In C++, if you do in the Microsoft thing you still got DLLs. 220 00:15:56,088 --> 00:15:58,850 If you don in UNIX thing you've got shared libraries. 221 00:15:58,850 --> 00:16:01,031 They are still dynamically linked libraries. 222 00:16:01,080 --> 00:16:05,131 Our mode of operation now a days is too dynamic linked libraries. 223 00:16:05,165 --> 00:16:07,867 That's how we got here. 224 00:16:11,980 --> 00:16:13,626 How many DLLs do you have? 225 00:16:15,342 --> 00:16:18,575 Guys with the solutions, Visual Studio solutions. 226 00:16:18,608 --> 00:16:20,415 How many projects? 227 00:16:21,315 --> 00:16:23,550 60? That's not bad. 228 00:16:23,550 --> 00:16:25,017 Who's got more than 60? 229 00:16:25,060 --> 00:16:26,597 Oh, look at that. 230 00:16:26,635 --> 00:16:28,094 Who's got more than 200? 231 00:16:30,942 --> 00:16:33,132 And do you know why? 232 00:16:33,215 --> 00:16:38,055 You separate your code into different DLLs? 233 00:16:38,886 --> 00:16:40,692 Let me ask that question differently. 234 00:16:41,272 --> 00:16:43,624 When you deploy your application, 235 00:16:44,590 --> 00:16:50,366 Do you gather up all the DLLs and just ship the wad? 236 00:16:52,521 --> 00:16:57,677 If you do then why are you dynamically linking them? 237 00:16:57,728 --> 00:16:59,395 Statically link them. 238 00:17:00,269 --> 00:17:04,820 Why would you bother with dynamic linking? If you just gonna take all those DLLs. 239 00:17:04,887 --> 00:17:07,260 Gather them up into one gigantic wad. 240 00:17:07,313 --> 00:17:10,359 Throw the big wad into directory. And says, "It's my system." 241 00:17:11,996 --> 00:17:16,857 Why dynamically link if you not going to dynamically deploy? 242 00:17:17,540 --> 00:17:21,675 Why did we come up with dynamically linked library? 243 00:17:21,743 --> 00:17:28,603 We came up with dynamically linked library so that we could dynamically deploy our applications. 244 00:17:29,093 --> 00:17:30,155 Why? 245 00:17:32,571 --> 00:17:35,630 Well, we gonna get to network speed. Hang on in a minute. 246 00:17:35,676 --> 00:17:38,946 Cause network speed has huge impact on this all thing. 247 00:17:38,996 --> 00:17:43,985 Mid 90s I've got a client. He's got a 250MB executable. 248 00:17:43,985 --> 00:17:46,594 In the mid-90s that was big program. Now it' not. 249 00:17:47,267 --> 00:17:51,733 But then 250MB was big deal, you could not fit it on a CD. 250 00:17:52,250 --> 00:17:57,127 This was CAD system. He shipped it to the company like Ford. 251 00:17:57,127 --> 00:18:01,548 Ford would use it to design gears and levers. Stuff like that. 252 00:18:02,876 --> 00:18:04,331 He statically linked it. 253 00:18:05,035 --> 00:18:11,207 He would deploy the executable to his clients by burning it on several CDs. 254 00:18:11,844 --> 00:18:15,109 If he changed one line of code, 255 00:18:16,782 --> 00:18:26,422 He had to recompile, re-link, re-burn all the CDs and deploy all the CDs to all his clients. 256 00:18:27,237 --> 00:18:29,756 And you can imagine how it cost him a fair bit of money. 257 00:18:31,981 --> 00:18:34,189 I went there in the mid-90s. 258 00:18:34,246 --> 00:18:36,615 And encountered them at a time 259 00:18:36,665 --> 00:18:44,005 when they were trying to chop up their executable into this new Idea, DLLs. 260 00:18:44,262 --> 00:18:48,902 Because they realized that if they had dynamically linked libraries 261 00:18:48,902 --> 00:18:52,166 Then they could change a line of code 262 00:18:52,205 --> 00:18:56,740 And ideally you would only have to ship that DLL. 263 00:18:57,545 --> 00:19:01,125 You could e-mail it!. Back in those days that was a big deal. 264 00:19:01,168 --> 00:19:03,370 You couldn't e-mail 250MB in those days. 265 00:19:03,439 --> 00:19:07,631 Now a days you can as long as the guy you're talking to got a reasonable e-mail server. 266 00:19:07,703 --> 00:19:17,166 But back in those days e-mailing 250MB was impossible, so they could e-mail the 100KB of DLL. 267 00:19:17,219 --> 00:19:20,060 And so that was very very desirable for them. 268 00:19:20,060 --> 00:19:22,163 They worked for month and month and month. 269 00:19:22,188 --> 00:19:24,972 Chopping their application up in the little tiny bits, 270 00:19:25,010 --> 00:19:26,933 turning them all into bunch of DLLs 271 00:19:27,021 --> 00:19:29,465 And that when they realized their critical mistake. 272 00:19:30,557 --> 00:19:35,474 The critical mistake was that chopping your system up into bunch of arbitrary DLLs 273 00:19:35,474 --> 00:19:39,293 doesn’t do you a damn bit of good if they all depend on each other. 274 00:19:40,189 --> 00:19:42,742 If they are all depend on each other then you can... 275 00:19:51,828 --> 00:19:56,005 Was anybody just in Scott Meyer's talk here? 276 00:19:56,091 --> 00:19:58,434 The last talk he just gave an hour ago? 277 00:19:58,466 --> 00:20:01,075 He was talking about the problem of keyholes. 278 00:20:01,126 --> 00:20:07,846 Problem of keyholes is that we arbitrarily constrain someone for no good reason. 279 00:20:07,894 --> 00:20:09,813 Just arbitrary constrain them. 280 00:20:09,849 --> 00:20:14,522 So for example, have you ever seen a text box on a GUI? 281 00:20:14,572 --> 00:20:16,453 That was just too short? 282 00:20:16,521 --> 00:20:21,868 And you had typed bunch of stuffs in it and it wouldn't let you resize the window? 283 00:20:21,868 --> 00:20:25,885 It wouldn't let you scroll and you just had to type blind? 284 00:20:25,930 --> 00:20:29,602 Or maybe the text with scroll but you wouldn't be able to see the beginning of it? 285 00:20:29,656 --> 00:20:34,728 He was mentioning the keyhole problem. 286 00:20:34,795 --> 00:20:38,273 And I know that something just happened here. 287 00:20:39,093 --> 00:20:43,362 Apparently I'm not allowed not touch my computer for more than 5 minutes. 288 00:20:43,412 --> 00:20:48,041 I must apparently touch my computer otherwise I'll be punished. 289 00:20:52,043 --> 00:20:54,513 What was I talking about? Oh yeah, DLLs. 290 00:20:54,513 --> 00:20:58,225 So this guy, he put all his DLLs together. 291 00:20:58,276 --> 00:21:00,500 He forgot that DLLs depend upon each other. 292 00:21:00,534 --> 00:21:04,391 His goal was to be able to touch a line of code 293 00:21:04,423 --> 00:21:07,752 And just ship that DLL that was affected. 294 00:21:07,821 --> 00:21:12,386 But he found that all the '#includes', C++ guys know what I'm talking about 295 00:21:12,450 --> 00:21:15,307 All the '#includes' form the horrible network. 296 00:21:15,358 --> 00:21:18,146 And he had to recompile and redeploy everything anyway. 297 00:21:18,218 --> 00:21:19,680 They went out of business. 298 00:21:22,666 --> 00:21:27,814 The purpose of my talk today, now that I'm getting around to it 299 00:21:29,349 --> 00:21:31,336 is to talk about components. 300 00:21:31,381 --> 00:21:33,408 The problem of component design. 301 00:21:33,480 --> 00:21:36,167 And the first thing we gonna do is to define a component. 302 00:21:36,213 --> 00:21:38,665 What's a component? Component is DLL. 303 00:21:39,475 --> 00:21:42,531 When I talk about the word component what I mean is DLL. 304 00:21:42,565 --> 00:21:47,002 Very particular kind of DLL. A dynamically deployable DLL. 305 00:21:49,185 --> 00:21:52,573 A dynamically deployable DLL. 306 00:21:53,473 --> 00:21:55,929 Why would we want dynamically deploy? 307 00:21:56,816 --> 00:21:59,877 Well, because we would like to be able to change one line of code 308 00:21:59,926 --> 00:22:03,113 Just ship the one DLL that changed and ignore all the others. 309 00:22:03,163 --> 00:22:05,399 What's DLL hell? 310 00:22:05,448 --> 00:22:09,273 A term invented, I believe, by Microsoft 311 00:22:10,135 --> 00:22:12,442 to describe their own situation. 312 00:22:12,509 --> 00:22:17,506 And was to be completely cured by .NET. 313 00:22:17,540 --> 00:22:22,185 Anybody remember that line? "Dear .NET cures DLL hell." 314 00:22:22,185 --> 00:22:27,531 Hu Hu Hu. No, it doesn’t cure DLL hell. 315 00:22:27,541 --> 00:22:32,285 DLL hell is the problem that we've got all these little components with different version numbers 316 00:22:32,285 --> 00:22:35,084 And nobody hell knows which one go should together 317 00:22:35,150 --> 00:22:38,669 So we invented this module maintenance tools like Maven. 318 00:22:38,742 --> 00:22:40,642 What are you guys using in .NET? 319 00:22:41,176 --> 00:22:45,925 What's the tool that lets you keep all of your DLLs are in line. 320 00:22:45,974 --> 00:22:50,143 So you know that download version 1 of that one and version 3 of that one. 321 00:22:50,176 --> 00:22:52,714 Do you have tool for that? What? 322 00:22:53,961 --> 00:22:54,957 NuGet? 323 00:22:54,957 --> 00:22:56,854 Like the soft chewy (??) 324 00:22:58,944 --> 00:23:00,720 Never mind, I'm not going there. 325 00:23:09,766 --> 00:23:17,987 The graph you see on the screen is a graph of x^2. 326 00:23:18,477 --> 00:23:20,371 That's just an x^2 graph. 327 00:23:21,242 --> 00:23:23,102 But it's also something else. 328 00:23:23,134 --> 00:23:29,186 It's the number of dependencies in a system. 329 00:23:29,276 --> 00:23:33,748 Theoretical maximum number of dependencies, given a certain number of modules. 330 00:23:33,798 --> 00:23:38,206 And you can see that the number of modules increases linearly 331 00:23:38,256 --> 00:23:40,969 And the number of dependency increases with square. 332 00:23:44,473 --> 00:23:48,699 The theoretical maximum number of coupling, which I show here 333 00:23:50,586 --> 00:23:54,750 is proportional to the square of the number of modules. 334 00:23:54,786 --> 00:24:01,275 Now of course we would never create a system that has every possible dependency in it. 335 00:24:02,578 --> 00:24:03,733 Or would we? 336 00:24:06,355 --> 00:24:08,209 Look at this curve. 337 00:24:09,181 --> 00:24:19,898 This curve is the productivity of a team in comparison to the number of modules. 338 00:24:19,898 --> 00:24:24,953 By the way this is completely arbitrary I just generated one of x squared curve here. 339 00:24:25,389 --> 00:24:28,168 This is not me collecting actual data. 340 00:24:28,935 --> 00:24:34,197 This is just me recollecting my experience with development teams. 341 00:24:34,197 --> 00:24:38,003 They go slower and slower and slower over time. 342 00:24:38,035 --> 00:24:39,495 Who's had this happened to them? 343 00:24:39,532 --> 00:24:42,367 You start outgoing really fast. You can conquer the world. 344 00:24:42,416 --> 00:24:45,923 A year later you slogging through some kind of horrible wet lands. 345 00:24:46,366 --> 00:24:48,664 And you don't know what the heck has gone wrong. 346 00:24:48,721 --> 00:24:52,936 But estimates that used to be on the order of one week are now three month long. 347 00:24:53,378 --> 00:24:58,136 And by the way you blow all those estimates anyway and introduces more bugs than you fix. 348 00:24:58,212 --> 00:25:04,435 That's the kind of problem that we have as we proceed a long development path. 349 00:25:04,480 --> 00:25:09,831 And one of the reasons for that is accumulation of dependencies. 350 00:25:10,571 --> 00:25:11,522 Why? 351 00:25:11,842 --> 00:25:20,778 Well, that's the theoretical maximum dependency between modules. 352 00:25:20,823 --> 00:25:22,847 This is the theoretical minimum. 353 00:25:23,172 --> 00:25:28,910 If you're going to have an interconnected set of modules, there has to be some dependencies. 354 00:25:28,966 --> 00:25:32,231 And the minimum set of dependencies is a tree structure. 355 00:25:32,231 --> 00:25:35,620 Oh you can do some better with dynamically linking if you want to. 356 00:25:35,620 --> 00:25:39,531 But for the most part, you gonna have a small number of dependencies. 357 00:25:39,573 --> 00:25:42,272 How many do we have? 1. 2. 3. 4. 5. 6. 358 00:25:42,272 --> 00:25:44,587 6 out of 7 modules. 359 00:25:44,627 --> 00:25:46,659 Whereas here you've got 360 00:25:46,659 --> 00:25:50,570 Well, I think that's half of 49. 361 00:25:50,570 --> 00:25:54,202 It can't be half of 49 because that would be happy half dependency. 362 00:25:54,257 --> 00:25:58,264 Maybe it's just a plain 49. I don't know what it is. It's a large number. 363 00:25:58,349 --> 00:26:01,067 It's some relative of N squared. 364 00:26:01,133 --> 00:26:03,280 Maybe it's one half n squared plus one half n. 365 00:26:03,362 --> 00:26:04,893 Something like that. 366 00:26:04,923 --> 00:26:07,859 It's a very large number of dependencies. 367 00:26:07,892 --> 00:26:10,906 We don't want this. We do want that. 368 00:26:10,974 --> 00:26:13,134 We strive very hard to get here. 369 00:26:13,168 --> 00:26:21,088 But then, some shmuck does that. 370 00:26:24,111 --> 00:26:26,011 Visual Studio doesn't allow this. 371 00:26:27,014 --> 00:26:28,507 Uh! Inside solution. 372 00:26:29,029 --> 00:26:34,189 Inside solution. The DLLs cannot have cycles between their graphs. 373 00:26:34,243 --> 00:26:35,019 That's good. 374 00:26:35,086 --> 00:26:36,004 Don't want cycles. 375 00:26:36,473 --> 00:26:38,744 Between separate solutions there's no guarantee. 376 00:26:38,778 --> 00:26:40,359 So you have multiple solutions. 377 00:26:40,407 --> 00:26:45,270 If you're linking with things that come out of different solutions, you can still have cycles in the graph. 378 00:26:45,304 --> 00:26:50,766 If you get cycles in the graph, it looks like it adds only one extra dependency. 379 00:26:51,385 --> 00:26:52,776 But actually it adds more. 380 00:26:52,817 --> 00:26:57,299 Because 6 now depends upon 2. Because 1 depends upon 2. 381 00:26:57,371 --> 00:26:59,139 And dependency is transitive. 382 00:26:59,230 --> 00:27:04,568 So 6 also depends upon 4 and 5. And 6 depends upon 3 and 7. 383 00:27:04,771 --> 00:27:06,851 In fact, 6 depends upon all of them. 384 00:27:07,561 --> 00:27:13,921 So number of dependencies multiplies dramatically as soon as you have a cycle. 385 00:27:21,943 --> 00:27:23,726 This is the n squared graph again. 386 00:27:25,092 --> 00:27:28,693 This is also a graph of C++ compile time. 387 00:27:28,759 --> 00:27:31,253 As you add modules. 388 00:27:31,352 --> 00:27:34,100 Compile time and the link time if you're doing static linking 389 00:27:34,100 --> 00:27:35,737 But even if you're not static linking, 390 00:27:35,793 --> 00:27:39,881 just compile time grows with the square of the number of modules, 391 00:27:39,935 --> 00:27:44,671 if you have a fully connected network of modules. 392 00:27:44,736 --> 00:27:52,241 What that mean is that your '#include' or your import statements or your using statements can be traced in a cycle. 393 00:27:53,119 --> 00:27:58,560 And if you have that, then you gonna wind up with this big increase in compile time. 394 00:27:58,594 --> 00:28:00,859 C++ in particular would do this. 395 00:28:00,949 --> 00:28:02,659 Java and .NET don't. 396 00:28:03,917 --> 00:28:06,240 Their compile time is based on a different metric. 397 00:28:06,240 --> 00:28:12,053 They don't go reading source files. The way C++ does. 398 00:28:12,105 --> 00:28:15,349 Java and .NET read binary files to get their declarations. 399 00:28:15,385 --> 00:28:18,574 C++ reads source files to get his declarations. 400 00:28:18,615 --> 00:28:23,778 And so if you had a cycle in C++, you got punished. 401 00:28:25,281 --> 00:28:27,059 By a big compile time. 402 00:28:27,125 --> 00:28:28,832 And a massive one. 403 00:28:28,900 --> 00:28:30,244 It would go up with square. 404 00:28:30,292 --> 00:28:33,036 So you would had couple of modules your compile time will double. 405 00:28:33,036 --> 00:28:35,560 And that made us do something about it. 406 00:28:36,190 --> 00:28:38,804 Who knows who Ward Cunningham is? 407 00:28:39,549 --> 00:28:40,459 Oh, a few of you do. 408 00:28:40,494 --> 00:28:41,964 Good. And the rest of you. 409 00:28:42,014 --> 00:28:43,392 He's the guy who invented Wikis. 410 00:28:43,462 --> 00:28:46,579 Ward Cunningham invented Wikis. 411 00:28:46,623 --> 00:28:51,552 He's the guy who helped Kent Beck invent pair programming, test-driven development, 412 00:28:51,637 --> 00:28:53,158 And most of the agile stuff. 413 00:28:53,207 --> 00:28:57,016 Get to know who Ward Cunningham. He is very interesting fellow. 414 00:28:57,049 --> 00:28:58,832 Smalltalk Programmer from a long ago. 415 00:28:58,877 --> 00:29:00,634 And I asked Ward once. 416 00:29:00,686 --> 00:29:03,304 "Why did Smalltalk died, Ward?" 417 00:29:03,367 --> 00:29:10,085 And he said, "Smalltalk died because it was so easy to make a mess." 418 00:29:10,834 --> 00:29:12,810 "You, C++ programmer,” 419 00:29:12,846 --> 00:29:14,382 I was a C++ programmer at that time. 420 00:29:14,458 --> 00:29:16,678 "You, C++ programmers are lucky." 421 00:29:16,729 --> 00:29:19,467 "Your language punishes you if make a mess." 422 00:29:19,960 --> 00:29:21,830 "Smalltalk didn't punish you." 423 00:29:23,425 --> 00:29:26,515 Well, neither does Java. Neither does C#. 424 00:29:26,965 --> 00:29:28,502 They don't punish you anymore. 425 00:29:28,570 --> 00:29:30,997 It's very easy to make a very large mess. 426 00:29:31,368 --> 00:29:34,879 And get a very tangled structure and not know you're doing it. 427 00:29:34,910 --> 00:29:38,958 Fortunately Visual Studio keeps some of the cycles out of your graph. 428 00:29:44,173 --> 00:29:49,045 We would like that level of productivity, which is n Log N. 429 00:29:49,109 --> 00:29:52,376 Rather than this level of productivity. That's an n squared. 430 00:29:52,776 --> 00:29:59,683 And one of the ways to help with that is to manage the dependencies between our components. 431 00:30:01,753 --> 00:30:06,973 Then something happened to us in the late 90s and into the 2000s. 432 00:30:06,973 --> 00:30:10,136 Network speed started increasing dramatically. 433 00:30:10,635 --> 00:30:15,790 Now a days, it's not hard at all to download a GB in a couple of seconds, 434 00:30:15,870 --> 00:30:17,661 And to upload a GB in 10 seconds. 435 00:30:17,726 --> 00:30:19,335 That's pretty easy now a days. 436 00:30:19,386 --> 00:30:21,706 Back in the early days it was much harder. 437 00:30:22,031 --> 00:30:28,315 So, back in the early days we thought shipping individual DLL was going to be a benefit. 438 00:30:28,535 --> 00:30:31,939 Now a days we just kind of gather them all together and ship the one big wad. 439 00:30:32,237 --> 00:30:35,835 Why? Well because network speed is fast enough. We can do it. 440 00:30:35,835 --> 00:30:40,311 We can treat our batch of DLLs just like it was statically linked. 441 00:30:41,661 --> 00:30:43,208 But there's another issue. 442 00:30:44,215 --> 00:30:45,744 How many of you work in teams? 443 00:30:47,252 --> 00:30:49,511 Oh look at that. Everybody works in teams. 444 00:30:50,551 --> 00:30:54,415 So, you come in at 8 in the morning. 445 00:30:55,883 --> 00:30:59,277 You got a test to perform. 446 00:30:59,346 --> 00:31:02,371 You work all day to get all your stuff working. 447 00:31:02,488 --> 00:31:03,728 All works by end of the day. 448 00:31:03,766 --> 00:31:04,907 You check it in and go home. 449 00:31:04,961 --> 00:31:07,271 Come back the next day all your stuff is broken. 450 00:31:07,328 --> 00:31:08,086 Why? 451 00:31:09,766 --> 00:31:12,402 Somebody stayed later than you. 452 00:31:13,452 --> 00:31:15,836 And changed something you depend upon. 453 00:31:16,626 --> 00:31:21,774 And so you work all day long to fix whatever the problem was. 454 00:31:21,774 --> 00:31:24,409 You go home and come back the next day and your stuff is broken again. 455 00:31:24,523 --> 00:31:26,390 How many times can you go around that loop? 456 00:31:27,398 --> 00:31:30,942 Lots of time. This is a problem of large teams. 457 00:31:31,048 --> 00:31:34,662 Large teams will start to step on each other. 458 00:31:34,745 --> 00:31:36,862 And of course we've invented tools to help us. 459 00:31:36,862 --> 00:31:38,921 We've got source code control systems. 460 00:31:38,921 --> 00:31:41,559 And we've got all kinds of good stuff to help us with this. 461 00:31:41,799 --> 00:31:47,395 But we still can step all over each other, unless we manage our projects well. 462 00:31:47,814 --> 00:31:52,414 So, how can we manage our projects well? 463 00:31:55,951 --> 00:31:57,741 There is a principle. 464 00:32:06,670 --> 00:32:10,849 A principle called Acyclic Dependencies Principle. 465 00:32:13,189 --> 00:32:18,585 The Acyclic dependencies principle says, "If you have a set of components" 466 00:32:18,618 --> 00:32:22,764 "You would like to be able to arrange without any cycles in the dependency graph." 467 00:32:22,849 --> 00:32:25,957 Now, for whole bunch of reasons we've already talked about one of them. 468 00:32:26,023 --> 00:32:30,402 Which is compile time. We've talked about another which is just dependency load. 469 00:32:30,402 --> 00:32:31,599 Here is another. 470 00:32:33,727 --> 00:32:38,577 Alarm would like to release its version of alarm. 471 00:32:38,986 --> 00:32:43,013 The team that's working on the Alarm would like to make release 1.0. 472 00:32:43,144 --> 00:32:48,812 They've got nobody that they depend upon. 473 00:32:48,812 --> 00:32:52,349 So they are completely free to make any release they want. 474 00:32:52,401 --> 00:32:56,011 So they release their version of 1.0. Alarm 1.0. 475 00:32:56,011 --> 00:32:58,006 They start working on alarm 1.1. 476 00:32:58,896 --> 00:33:02,169 But now Alarm 1.0 has been released. 477 00:33:02,220 --> 00:33:05,977 Which means that Elevator and Conveyor can make their release. 478 00:33:06,916 --> 00:33:12,386 And once Elevator and Conveyor made their releases they can start to work on 1.1. 479 00:33:12,419 --> 00:33:15,740 But now Transport can make its release. 480 00:33:15,776 --> 00:33:17,759 You can see what's happening here. Right? 481 00:33:17,806 --> 00:33:21,079 The version numbers bubble up from the bottom. 482 00:33:21,148 --> 00:33:27,448 1.0 gets created here. Then there. Then there. Here. Here. And finally there. 483 00:33:27,497 --> 00:33:30,021 The version numbers bubble up from the bottom. 484 00:33:30,053 --> 00:33:32,633 If you look at it closely, you'll realize that 485 00:33:32,633 --> 00:33:37,550 the version numbers follows exact same path as the build. The compile. 486 00:33:37,615 --> 00:33:42,422 Dependencies are running in that direction. 487 00:33:43,318 --> 00:33:50,357 And now, some poor shmuck does this. 488 00:33:50,454 --> 00:33:52,601 Who's this? 489 00:33:52,703 --> 00:33:54,192 Well that was me. I did that. 490 00:33:54,303 --> 00:33:58,542 I had an alarm subsystem I was working on. 491 00:33:58,542 --> 00:34:02,255 And I needed it to put a message on the display and the control panel. 492 00:34:02,329 --> 00:34:06,963 There happened to be a class up here that had a function called Display. 493 00:34:06,963 --> 00:34:10,025 And I thought, "Oh! I should just call it." So I called it. 494 00:34:10,025 --> 00:34:13,315 This was not in a language that restrict me from cycles. 495 00:34:13,315 --> 00:34:17,092 And so it compiled and everything was fine and all worked okay. 496 00:34:18,482 --> 00:34:23,495 And then the next day I had a group of angry developers come to my cubicles with club 497 00:34:23,542 --> 00:34:25,243 And tell me "What the hell did you do?" 498 00:34:25,652 --> 00:34:32,592 I said, "Well, I just called the control panel and display class that has display function in it." 499 00:34:32,628 --> 00:34:34,553 "I needed to put this message on the screen." 500 00:34:34,587 --> 00:34:35,763 And they said, "You can't do that." 501 00:34:36,351 --> 00:34:37,908 Why can't we do that? 502 00:34:39,777 --> 00:34:41,172 First of all, 503 00:34:43,752 --> 00:34:47,603 what order should we build those modules in? 504 00:34:49,893 --> 00:34:52,737 You'd like to build them bottom up. 505 00:34:53,853 --> 00:34:55,666 But now there's no bottom. 506 00:34:55,717 --> 00:34:58,090 So there's no correct build order. 507 00:34:58,341 --> 00:35:01,242 If you have cycles in the component graph, 508 00:35:01,608 --> 00:35:06,485 there is no correct build order for the modules in that system. 509 00:35:06,524 --> 00:35:11,136 And therefore the execution of that system is undefined. 510 00:35:11,676 --> 00:35:14,992 What does undefined mean? What's the definition of undefined? 511 00:35:16,210 --> 00:35:17,867 Works in the lab. 512 00:35:19,656 --> 00:35:24,308 Anything undefined will work until you actually deploy it somewhere. Then it will fail. 513 00:35:25,442 --> 00:35:29,006 You can get systems to fail rather badly by having this cycles. 514 00:35:29,043 --> 00:35:30,945 This is pretty common in Java. 515 00:35:31,044 --> 00:35:35,951 If you have a system of Java that has cycles in it. 516 00:35:35,951 --> 00:35:37,061 You can build it. 517 00:35:37,093 --> 00:35:39,021 Although there is no correct build order. 518 00:35:39,129 --> 00:35:41,327 Then you run your test. And test will fail. 519 00:35:41,540 --> 00:35:44,626 Then you build it again. That will choose different build order. 520 00:35:44,661 --> 00:35:45,804 And maybe the test will pass. 521 00:35:45,855 --> 00:35:49,166 I know of companies that put their build in a loop until test pass. 522 00:35:54,627 --> 00:35:56,380 But the problem is worse than that. 523 00:35:56,923 --> 00:36:03,659 Because conveyor would like to make their release. 524 00:36:03,690 --> 00:36:05,879 They want to release 1.1. 525 00:36:05,911 --> 00:36:11,089 Now for them to release 1.1, they have to test with alarm 1.1. 526 00:36:11,885 --> 00:36:17,858 But alarm 1.1 is waiting for control panel 1.1, which is waiting for transport 1.1 527 00:36:17,904 --> 00:36:21,646 which is waiting for conveyor 1.1, which is the one trying to release. 528 00:36:21,646 --> 00:36:27,729 So there's no way to make the release without checking all of that source code out into one place. 529 00:36:27,818 --> 00:36:31,004 Integrating. Anybody remember integration. 530 00:36:31,037 --> 00:36:32,305 The joys of integration. 531 00:36:32,354 --> 00:36:37,126 Integrate the whole system and then make it work. 532 00:36:37,945 --> 00:36:41,044 And while you're doing that you gonna be stepping all over each other. 533 00:36:41,354 --> 00: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. 534 00:36:50,164 --> 00:36:52,095 But it's worse than that. 535 00:36:52,717 --> 00:36:58,439 Because in order to test conveyor I need alarm. 536 00:36:58,472 --> 00:37:02,409 Which needs control panel which needs revenue, which need the database. 537 00:37:02,499 --> 00:37:06,248 The database takes 45 minutes to load and then it crashes. 538 00:37:06,528 --> 00:37:08,966 I can't run my tests. 539 00:37:09,026 --> 00:37:13,999 Ant the guys in conveyor saying, "Why the heck do I need the database?" 540 00:37:14,150 --> 00:37:17,344 "Well, you need the database because of this strange dependency structure." 541 00:37:17,504 --> 00:37:21,891 Anybody ever look at the number of DLLs that got loaded and scratch head and say, 542 00:37:21,891 --> 00:37:23,811 "How come I need those?" 543 00:37:23,849 --> 00:37:26,895 Anybody in C++ world have ever link line? 544 00:37:26,999 --> 00:37:28,962 And wonder "what's all this stuff in the link line?" 545 00:37:29,005 --> 00:37:30,530 "How come I need all that stuff?" 546 00:37:30,564 --> 00:37:32,993 Right? You got cycles in the dependency graphs. 547 00:37:33,026 --> 00:37:34,532 It's bringing in all kinds of gunk. 548 00:37:34,599 --> 00:37:42,656 So the first principle of components is no cycles in the components. 549 00:37:42,695 --> 00:37:45,059 What if you want to do this? 550 00:37:45,835 --> 00:37:51,747 What if you really want to call some function from down here that lives up there? 551 00:37:51,747 --> 00:37:53,107 How you gonna do it? 552 00:37:55,377 --> 00:37:57,370 Well, you can put out another component. 553 00:37:58,446 --> 00:37:59,868 That's one way to do it. 554 00:37:59,939 --> 00:38:03,339 Here I took that class out of the control panel. 555 00:38:03,373 --> 00:38:05,327 I put it in the display component. 556 00:38:05,327 --> 00:38:07,961 Then the alarm component can talk to the display component. 557 00:38:07,961 --> 00:38:10,255 The control panel can talk to the display component. 558 00:38:10,516 --> 00:38:12,199 I can keep the cycles out. 559 00:38:12,263 --> 00:38:14,242 That's common enough technique. 560 00:38:14,287 --> 00:38:16,061 Remember, these are all DLLs. 561 00:38:16,114 --> 00:38:23,034 So number of DLLs in your system will start to grow as people want to add cycles to the dependency graph. 562 00:38:23,086 --> 00:38:24,603 Maybe. 563 00:38:25,019 --> 00:38:28,364 Although there's another way to resolve the cycle. 564 00:38:30,440 --> 00:38:33,076 You can use dependency inversion. 565 00:38:33,124 --> 00:38:40,010 I could put an interface. A display interface. 566 00:38:40,064 --> 00:38:42,278 In the alarm subsystem. 567 00:38:42,330 --> 00:38:44,778 And have the control panel implemented it. 568 00:38:45,764 --> 00:38:48,321 That turns the dependency around. 569 00:38:49,643 --> 00:38:52,663 And changes a cycle into a straight tree. 570 00:38:59,790 --> 00:39:01,324 What's OO? 571 00:39:04,009 --> 00:39:06,269 What is Object Orientation? 572 00:39:08,802 --> 00:39:10,474 Why do we like it? 573 00:39:10,538 --> 00:39:14,936 How come all of our languages are object oriented languages? 574 00:39:14,936 --> 00:39:16,884 We've been doing this for 30 years. We gotta know. 575 00:39:16,952 --> 00:39:18,560 (Someone says) "Models the real world." 576 00:39:18,560 --> 00:39:20,193 Models the real world! Thank you! 577 00:39:20,193 --> 00:39:22,727 I planted him here so that he would say that. 578 00:39:22,727 --> 00:39:24,924 So then I could rip him to shred. 579 00:39:24,974 --> 00:39:26,852 No, that's absurd. 580 00:39:26,852 --> 00:39:31,641 And that whole idea that OO has better way to model real world is plain non-sense. 581 00:39:31,712 --> 00:39:35,366 It's something. Some guy concocted long time ago 582 00:39:35,450 --> 00:39:39,479 To convince his manager to spend 12,000$ on C++ compiler. 583 00:39:39,512 --> 00:39:42,092 Cause he couldn't figure out any other ways to get his manager to do it. 584 00:39:42,144 --> 00:39:46,391 12,000$. Early C++ compiler costed a lot of money. 585 00:39:46,391 --> 00:39:48,092 "12,000$. I'm not spending that for a compiler." 586 00:39:48,092 --> 00:39:49,961 "Well, it will help me model the real world!" 587 00:39:49,961 --> 00:39:53,086 "Oh. Okay then." 588 00:39:53,125 --> 00:39:57,739 This whole notion of modeling the real world is downright silly. 589 00:39:57,771 --> 00:40:04,560 What in the world is OO other than a bunch of functions using a bunch of data structure? Right? 590 00:40:04,560 --> 00:40:06,822 Encapsulated. Okay fine. Encapsulated. 591 00:40:06,822 --> 00:40:09,407 But bunch of functions using bunch of data structures. 592 00:40:09,407 --> 00:40:11,590 How is that different from Non OO? 593 00:40:13,393 --> 00:40:15,497 The answer to that is not easy to describe. 594 00:40:16,282 --> 00:40:18,067 How that's different? 595 00:40:18,129 --> 00:40:21,940 Well, okay. We kind of put the data structures in the functions together. 596 00:40:21,994 --> 00:40:23,659 But we always used to do that. 597 00:40:24,161 --> 00:40:26,806 Old C programmers used to that all the time. 598 00:40:27,058 --> 00:40:29,959 Data structures in programs always went together. 599 00:40:29,959 --> 00:40:33,588 There is a famous book called 'Algorithms plus data structures equals programs.' 600 00:40:34,290 --> 00:40:36,530 Data structures now (??) working together. 601 00:40:36,583 --> 00:40:39,288 So nothing really fancy about OO there. 602 00:40:39,288 --> 00:40:43,754 There is one thing that OO gave us that we did not have before. 603 00:40:43,754 --> 00:40:45,537 Because it wasn't safe. 604 00:40:45,597 --> 00:40:47,267 And that's polymorphism. 605 00:40:47,304 --> 00:40:50,987 Very very convenient polymorphism. 606 00:40:51,024 --> 00:40:53,266 We used to have it in C. 607 00:40:53,924 --> 00:40:57,898 Device independence in any operating system is an example of polymorphism. 608 00:40:57,947 --> 00:41:02,791 If you can write a program, you don't need to know what device that program is gonna use. 609 00:41:02,862 --> 00:41:04,842 It's a clearly polymorphic interface. 610 00:41:05,568 --> 00:41:08,694 But that's dangerous in most languages. 611 00:41:08,762 --> 00:41:10,472 Or it was back in those days. 612 00:41:10,472 --> 00:41:12,262 Because you have to fiddle with pointers to functions. 613 00:41:12,262 --> 00:41:13,533 And that was always dangerous. 614 00:41:14,638 --> 00:41:18,563 What OO gave us was very very convenient polymorphism. 615 00:41:18,639 --> 00:41:20,773 Polymorphism without thinking about it. 616 00:41:20,773 --> 00:41:23,674 Java in particular all the methods are polymorphic. 617 00:41:23,674 --> 00:41:25,108 There's no choice. 618 00:41:25,175 --> 00:41:29,289 C#, you have choice. You can use that funny virtual keyword. 619 00:41:29,322 --> 00:41:35,234 C++ programmers you've got a choice. You better use that virtual keyword. Especially on your destructors. 620 00:41:35,871 --> 00:41:38,933 But most of us we don't even pay attention anymore. 621 00:41:38,933 --> 00:41:42,007 All our functions are polymorphic. We don't even think about it. 622 00:41:42,055 --> 00:41:42,936 Why? 623 00:41:44,166 --> 00:41:49,384 Because when a function is polymorphic something amazing happens. 624 00:41:49,964 --> 00:41:55,192 The flow of control goes down towards to derivatives. 625 00:41:55,242 --> 00:41:59,150 But the source code dependency goes back towards base. 626 00:41:59,828 --> 00:42:07,917 We can take a source code dependency and turn it around without changing the run time dependency. 627 00:42:07,917 --> 00:42:10,110 How do you get DLLs? 628 00:42:10,110 --> 00:42:11,872 How do you get components? 629 00:42:11,872 --> 00:42:13,614 You isolate them. 630 00:42:13,614 --> 00:42:16,954 But you have to maintain the run time dependency. 631 00:42:21,441 --> 00:42:22,710 Visual Studio people 632 00:42:24,865 --> 00:42:27,552 Are you using ReSharper? 633 00:42:28,532 --> 00:42:30,060 Who is? ReSharper? 634 00:42:30,091 --> 00:42:31,576 Look at that. Everybody. 635 00:42:32,816 --> 00:42:35,606 Does Visual Studio know about ReSharper? 636 00:42:38,009 --> 00:42:38,645 No. 637 00:42:38,718 --> 00:42:42,338 Does Visual Studio call ReSharper? 638 00:42:43,465 --> 00:42:44,725 Yes. 639 00:42:44,790 --> 00:42:49,106 The flow of control goes from Visual Studio into ReSharper. 640 00:42:49,106 --> 00:42:54,477 There are function calls in Visual Studio that their way into ReSharper. 641 00:42:54,477 --> 00:43:00,686 But there is no source code dependency that moves from Visual Studio into ReSharper. 642 00:43:00,686 --> 00:43:03,086 Because they've been inverted the dependencies. 643 00:43:04,025 --> 00:43:09,912 You can create DLLs that your application will call. 644 00:43:09,945 --> 00:43:12,495 But your application doesn't know it exist. 645 00:43:12,527 --> 00:43:15,585 And you do that by inverting dependencies. 646 00:43:15,864 --> 00:43:17,072 Turn them around. 647 00:43:17,156 --> 00:43:19,280 So this is one nice way to do that. 648 00:43:19,652 --> 00:43:28,943 Now the control panel is a plug-in to the alarm system. 649 00:43:29,025 --> 00:43:31,590 The alarm system doesn't know the control panel exists. 650 00:43:31,590 --> 00:43:35,765 The control panel is a plug-in. 651 00:43:35,813 --> 00:43:38,609 And the alarm system would accept any kind of plug-in. 652 00:43:38,609 --> 00:43:42,568 A lot of different things to do implement this display function here. 653 00:43:42,568 --> 00:43:45,262 So we could have a lot of different things that we alarmed. 654 00:43:52,942 --> 00:43:55,184 What would rather depend upon? 655 00:44:01,501 --> 00:44:04,620 A component that was stable? 656 00:44:07,014 --> 00:44:08,996 Or a component that was unstable? 657 00:44:10,785 --> 00:44:12,145 Trick questions. 658 00:44:12,195 --> 00:44:17,812 Right? Everybody knows that you want to depend on something that's stable. 659 00:44:22,582 --> 00:44:25,278 But now let me define stability. 660 00:44:28,542 --> 00:44:30,590 Is my laser stable? 661 00:44:34,332 --> 00:44:36,273 It's not changing. 662 00:44:38,883 --> 00:44:40,569 But is it stable? 663 00:44:40,614 --> 00:44:43,667 Stability is not a Boolean. 664 00:44:43,732 --> 00:44:46,330 Stability is a continuous variable. 665 00:44:46,379 --> 00:44:50,612 And it is defined as the amount of work required to make a change. 666 00:44:50,657 --> 00:44:53,396 If it takes a lot of work to make a change, it's stable. 667 00:44:53,433 --> 00:44:56,250 If it takes very little work to make a change, it's unstable. 668 00:44:56,301 --> 00:45:00,212 That is unstable. 669 00:45:00,283 --> 00:45:03,767 Cause it doesn't take much work to make a change to its state. 670 00:45:03,825 --> 00:45:08,630 This. Well I won't say that it's stable. 671 00:45:08,736 --> 00:45:11,505 Cause it would take much work to upset it. 672 00:45:11,542 --> 00:45:14,952 And this whole stage doesn't feel very stable to me. 673 00:45:15,780 --> 00:45:18,945 So I may have to be careful about the way I move. 674 00:45:18,976 --> 00:45:21,597 So let me ask the question again. 675 00:45:21,632 --> 00:45:24,712 What would you rather depend upon? 676 00:45:24,766 --> 00:45:26,956 Something easy to change? 677 00:45:26,997 --> 00:45:28,735 Or something hard to change? 678 00:45:28,774 --> 00:45:33,115 Modify the source code. 679 00:45:33,725 --> 00:45:35,199 What would you rather depend upon? 680 00:45:35,199 --> 00:45:39,812 A module whose source code was hard to change or a module whose source code was easy to change? 681 00:45:42,290 --> 00:45:43,366 Same answer. 682 00:45:43,439 --> 00:45:45,699 You wanna depend upon thing that hard to change. 683 00:45:45,731 --> 00:45:48,997 And the reason behind that is very simple. 684 00:45:48,997 --> 00:45:51,956 Do you mind depending on string? 685 00:45:51,988 --> 00:45:52,725 No. 686 00:45:52,725 --> 00:45:54,946 Why don't you mind depending on string? 687 00:45:54,946 --> 00:45:58,409 Cause if those guys ever change string, they'll be held to pay. 688 00:45:59,679 --> 00:46:01,405 They would suffer more than you. 689 00:46:01,619 --> 00:46:04,157 That's the equation that we're talking about here. 690 00:46:04,157 --> 00:46:06,488 You are happy to do depend upon something, 691 00:46:06,528 --> 00:46:11,525 if it will hurt the authors of that thing more to change it than hurts you. 692 00:46:11,564 --> 00:46:13,814 That's the equation. 693 00:46:13,854 --> 00:46:15,598 You are happy to depend upon things 694 00:46:15,598 --> 00:46:19,202 as long as you're not likely to change or at least the bastards gonna pay if they change. 695 00:46:19,202 --> 00:46:25,356 So alright, we don't want to depend on things that are easy to change. 696 00:46:27,384 --> 00:46:28,906 Think about that very carefully. 697 00:46:28,906 --> 00:46:32,846 I don't want to depend on something easy to change. 698 00:46:34,594 --> 00:46:40,272 Do we design parts of our system so that they will be easy to change? 699 00:46:42,648 --> 00:46:43,785 Yes. 700 00:46:44,137 --> 00:46:49,977 What parts of our system do we most want to be easy to change? 701 00:46:53,137 --> 00:46:54,321 The GUI. 702 00:46:56,888 --> 00:46:58,286 GUIs are volatile. 703 00:46:58,286 --> 00:47:01,589 They change for no good reason at all. 704 00:47:01,622 --> 00:47:05,068 People will change GUI just because they feel like it. 705 00:47:05,105 --> 00:47:07,851 There will be some committee (??) to say, 706 00:47:07,851 --> 00:47:09,743 "You know, our system look so old." 707 00:47:09,780 --> 00:47:11,500 What the hell does that mean? 708 00:47:11,500 --> 00:47:14,542 "Our system look so old, we need to give it a face lift." 709 00:47:14,902 --> 00:47:19,376 "Marketing people have decided, we’ve gotta have whole new look and feel." 710 00:47:19,410 --> 00:47:21,035 "Not gonna change any behavior." 711 00:47:21,090 --> 00:47:22,895 "Just look and feel of the GUI." 712 00:47:22,927 --> 00:47:25,044 GUI has to be easy to change. 713 00:47:25,044 --> 00:47:28,509 The modules that hold that source code have to be easy to change 714 00:47:28,549 --> 00:47:33,005 And that means that none of you modules should depend on the GUI. 715 00:47:33,627 --> 00:47:36,668 No source code dependency should land on the GUI. 716 00:47:37,533 --> 00:47:41,976 Your components should not have dependencies that land on the GUI. 717 00:47:42,029 --> 00:47:45,183 GUI components have to depend upon the application. 718 00:47:45,226 --> 00:47:48,528 Application component cannot depend upon the GUI. 719 00:47:49,110 --> 00:47:53,207 Otherwise you wind up with the systems that wear the GUIs hard to change. 720 00:47:53,254 --> 00:47:56,567 How many of you test your systems? 721 00:47:56,617 --> 00:47:57,882 Automated test. 722 00:47:58,844 --> 00:47:59,910 Through the GUI. 723 00:48:02,644 --> 00:48:03,858 Got a couple of people. 724 00:48:04,807 --> 00:48:06,618 You write test code through the GUI. 725 00:48:07,383 --> 00:48:11,009 You are depending upon something that supposed to be easy to change. 726 00:48:11,058 --> 00:48:13,231 You'll make it hard to change. 727 00:48:13,296 --> 00:48:15,598 If you test your system through the GUI. 728 00:48:15,667 --> 00:48:19,399 I have a client who have 15,000 tests all go through the GUI. 729 00:48:19,432 --> 00:48:20,850 Same client, by the way. 730 00:48:20,934 --> 00:48:22,070 Same one went out of the business. 731 00:48:22,102 --> 00:48:25,786 15,000 tests through the GUI. 732 00:48:25,838 --> 00:48:29,291 He had so many tests he didn't know what they were anymore. 733 00:48:29,324 --> 00:48:30,828 He just knew they all had to pass. 734 00:48:30,863 --> 00:48:32,783 If somebody touch the GUI 735 00:48:32,819 --> 00:48:35,233 a thousand of those test would break. 736 00:48:35,283 --> 00:48:37,060 He couldn't find the time to fix them. 737 00:48:37,108 --> 00:48:39,223 So he came up with real simple rule. 738 00:48:39,265 --> 00:48:40,797 What do you think that rule was? 739 00:48:40,851 --> 00:48:43,575 No body touches the GUI. 740 00:48:43,611 --> 00:48:47,117 They made the GUI hard to change. 741 00:48:47,532 --> 00:48:51,696 The other thing of course could happened there is that you could lose your tests. 742 00:48:52,566 --> 00:48:58,428 You spend a man year putting together nice automated test suite that go through the GUI. 743 00:48:58,468 --> 00:49:01,944 And then somebody decides, "We need a face lift on our site." 744 00:49:01,984 --> 00:49:04,359 "Pull all out the old GUI and put a brand new GUI" 745 00:49:04,404 --> 00:49:05,969 And all those tests are gone. 746 00:49:06,000 --> 00:49:09,706 And you get to rewrite them again, but you've got other systems you gotta test. 747 00:49:09,748 --> 00:49:11,771 Don't test through the GUI. 748 00:49:11,809 --> 00:49:13,777 Don't do anything through the GUI. 749 00:49:13,777 --> 00:49:19,387 All dependencies point away from the GUI. 750 00:49:19,450 --> 00:49:22,799 What other things do we want to be easy to change? 751 00:49:22,881 --> 00:49:26,047 The database. 752 00:49:26,047 --> 00:49:28,340 We want the database to be easy to change. 753 00:49:28,340 --> 00:49:32,347 We want to be able to make changes to database without rippling through the whole applications. 754 00:49:33,814 --> 00:49:37,646 All dependencies you should point away from the database. 755 00:49:37,646 --> 00:49:40,613 Put the database in a component with all the dependencies pointing outwards. 756 00:49:40,681 --> 00:49:44,228 Put the GUI into a component with all the dependencies pointing outwards. 757 00:49:46,310 --> 00:49:54,150 I don't want to depend on anything that is unstable. 758 00:49:54,701 --> 00:49:58,444 How can we measure instability? 759 00:50:02,013 --> 00:50:03,818 See this guy up here? 760 00:50:04,997 --> 00:50:06,322 That component up there? 761 00:50:06,750 --> 00:50:08,926 Is he Stable? Or Unstable? 762 00:50:09,001 --> 00:50:13,261 He's got lots of incoming dependencies. 763 00:50:13,329 --> 00:50:15,624 No outgoing dependencies. 764 00:50:15,687 --> 00:50:17,099 He's hard to change. 765 00:50:17,152 --> 00:50:20,353 If I make a change to him, it impacts all those guys. 766 00:50:20,404 --> 00:50:24,940 So this component here is responsible to those guys. 767 00:50:25,010 --> 00:50:28,996 Oh and this component here is independent. 768 00:50:29,077 --> 00:50:30,892 It doesn't depend on anybody. 769 00:50:30,892 --> 00:50:32,803 It's responsible and independent. 770 00:50:32,803 --> 00:50:33,852 I's an adult. 771 00:50:36,724 --> 00:50:39,079 Stable. Adult. 772 00:50:40,048 --> 00:50:41,089 This guy. 773 00:50:41,619 --> 00:50:44,444 He depends on lots of other components. 774 00:50:44,953 --> 00:50:46,787 No body depends upon him. 775 00:50:46,840 --> 00:50:48,367 Is he responsible? 776 00:50:48,434 --> 00:50:49,643 And dependent? 777 00:50:49,682 --> 00:50:51,274 He's teenager. 778 00:50:52,014 --> 00:50:53,581 And he's unstable. 779 00:50:54,058 --> 00:50:57,624 These are the two extreme kinds of components. 780 00:50:57,683 --> 00:51:00,395 At the two sides of component spectrum. 781 00:51:00,429 --> 00:51:02,870 You've got the adults that highly stable. 782 00:51:02,937 --> 00:51:06,786 And you’ve got the teenager who are highly unstable. 783 00:51:06,878 --> 00:51:09,071 The unstable ones are easy to change. 784 00:51:09,154 --> 00:51:11,685 That's what we wanna put all of our little code. 785 00:51:12,391 --> 00:51:15,128 The stable ones are hard to change. 786 00:51:16,378 --> 00:51:22,870 We can measure that stability by creating a metric. 787 00:51:22,902 --> 00:51:25,828 That metric is a metric that I call "I" 788 00:51:26,816 --> 00:51:33,597 'I' is equal to the fan-out. Number of outgoing dependencies. 789 00:51:33,669 --> 00:51:37,095 Divided by the fan-in plus the fan-out. 790 00:51:37,183 --> 00:51:40,231 And if you think about that for very long. 791 00:51:40,263 --> 00:51:43,563 You'll realize that 'I' is a metric that goes from 0 to 1. 792 00:51:43,647 --> 00:51:46,835 0 being stable. 1 being unstable. 793 00:51:46,869 --> 00:51:50,026 0 being an adult. 1 being a teenager. 794 00:51:50,092 --> 00:51:53,337 It’s all about the dependencies. 795 00:51:53,370 --> 00:51:59,273 And now we can re-phrase the principle to say this. 796 00:52:05,664 --> 00:52:13,948 Every dependency in a component graph should point at something more stable than it is. 797 00:52:14,348 --> 00:52:21,748 Or, if use the metric, these arrow should point in the direction of decreasing 'I'. 798 00:52:21,827 --> 00:52:25,394 Decreasing instability. Increasing stability. 799 00:52:25,426 --> 00:52:30,656 And you can do the math on just the fan-ins and fan-outs and verify that's correct. 800 00:52:31,576 --> 00:52:36,733 Why was the cycle bad idea? 801 00:52:37,981 --> 00:52:41,441 Something stable depended on something unstable. 802 00:52:44,864 --> 00:52:48,128 But that leaves us with a problem. 803 00:52:48,167 --> 00:52:49,920 And the problem is this. 804 00:52:54,953 --> 00:52:56,228 What's that guy? 805 00:52:57,662 --> 00:52:59,327 Stable? Or unstable? 806 00:53:01,337 --> 00:53:02,724 He's really stable. 807 00:53:02,774 --> 00:53:05,103 He's sitting down here the bottom of the graph. 808 00:53:05,175 --> 00:53:07,800 Everything over here depends on him. 809 00:53:08,595 --> 00:53:10,422 He's very hard to change. 810 00:53:10,764 --> 00:53:14,927 If I touch that component, all these other components will be affected by. 811 00:53:14,927 --> 00:53:18,348 For no other reason than the release number changes. 812 00:53:23,941 --> 00:53:29,017 That means the stuffs down here at the bottom of graph is very difficult to work with. 813 00:53:30,887 --> 00:53:33,373 But there's an escape to that. 814 00:53:33,725 --> 00:53:35,338 Back to polymorphism. 815 00:53:36,750 --> 00:53:42,927 How can you make something easy to extend? 816 00:53:43,791 --> 00:53:46,479 Even though it's hard to modify. 817 00:53:48,710 --> 00:53:50,260 You make it abstract. 818 00:53:51,098 --> 00:53:54,422 Abstract classes can be extended trivially. 819 00:53:55,209 --> 00:53:57,365 Without having it modified. 820 00:53:57,456 --> 00:54:00,423 You can add new features to a system 821 00:54:00,472 --> 00:54:05,741 if those new features live inside the derivatives of base classes. 822 00:54:06,201 --> 00:54:08,904 So the final principle is this. 823 00:54:09,760 --> 00:54:16,153 We would like abstractness to increase as we go down the zeros. (??) 824 00:54:16,185 --> 00:54:18,480 Stuff up here concrete. 825 00:54:18,513 --> 00:54:20,310 Unstable and concrete. 826 00:54:20,310 --> 00:54:23,135 Stuff down here abstract and stable. 827 00:54:23,135 --> 00:54:30,237 Abstractness becomes more and more prevalent as we go down this tree. 828 00:54:32,090 --> 00:54:39,393 In fact, we could say that abstractness is a number 829 00:54:39,425 --> 00:54:46,424 which is the number of abstract classes divided by the total number of classes in a component. 830 00:54:46,895 --> 00:54:50,355 And if you did that, you get this number 'A' which goes 0 to 1. 831 00:54:50,355 --> 00:54:51,672 0 being concrete. 832 00:54:51,708 --> 00:54:54,826 1 being entirely abstract. Composed of nothing but interfaces. 833 00:54:54,878 --> 00:54:58,622 And then we can do this very interesting thing. 834 00:54:58,698 --> 00:55:09,120 We can say that for any particular component 'A' plus 'I' should equal 1. 835 00:55:09,152 --> 00:55:13,091 Either it's abstract where 'A' is 1. 836 00:55:13,129 --> 00:55:15,504 And stable where 'I' is 0. 837 00:55:15,541 --> 00:55:19,557 Or it is instable where 'I' is 1. 838 00:55:19,606 --> 00:55:21,130 And concrete where 'A' is 0. 839 00:55:21,130 --> 00:55:23,375 'A' plus 'I' equals 1. 840 00:55:23,423 --> 00:55:26,733 The magic formula of components. 'A' plus 'I' equals 1. 841 00:55:26,733 --> 00:55:30,863 Now you've got the adults up here which are abstract 842 00:55:30,897 --> 00:55:33,340 And everybody depends upon them. So they are stable. 843 00:55:33,378 --> 00:55:35,859 You've got the teenagers down here. 844 00:55:37,254 --> 00:55:41,781 Everybody that's got no incoming dependencies but they're very concrete. 845 00:55:41,815 --> 00:55:43,602 What do you got here? 846 00:55:43,635 --> 00:55:47,142 This is the line 'A' plus 'I' equals 1. 847 00:55:48,472 --> 00:55:53,458 This is where we would like our components to sit if they can sit. One of those two end points. 848 00:55:53,499 --> 00:55:54,376 Why? 849 00:55:55,583 --> 00:55:59,496 Well, what's up here? 850 00:56:00,981 --> 00:56:03,951 Highly abstract. Nobody depends upon on it. 851 00:56:05,366 --> 00:56:08,097 An interface that nobody implements. Useless. 852 00:56:08,729 --> 00:56:11,022 This is the zone of uselessness. 853 00:56:11,067 --> 00:56:14,316 We don't want our components going that way. 854 00:56:14,388 --> 00:56:15,600 What's down here? 855 00:56:17,040 --> 00:56:19,658 Very concrete. Everybody depends upon on it. 856 00:56:20,230 --> 00:56:21,560 Database schemas. 857 00:56:23,292 --> 00:56:25,212 Concrete. Everybody depends upon them. 858 00:56:25,262 --> 00:56:26,519 Fun to change. 859 00:56:27,371 --> 00:56:29,629 Right? We don't want things down here. 860 00:56:29,669 --> 00:56:31,019 This is the zone of pain. 861 00:56:31,713 --> 00:56:36,199 We would like our components to be as far from those 2 points as possible. 862 00:56:36,199 --> 00:56:39,298 Ideally if we could get them here and here that would be best. 863 00:56:39,333 --> 00:56:42,253 But it turns out the components are persnickety that way. 864 00:56:42,304 --> 00:56:45,450 So at least we'd like them to be sitting along this line. 865 00:56:45,962 --> 00:56:48,414 Or close to the line. 866 00:56:48,914 --> 00:56:51,407 Which leaves us the one last metric. 867 00:56:52,574 --> 00:56:53,566 'D' 868 00:56:54,316 --> 00:56:56,975 How far away is a component from the line? 869 00:56:57,594 --> 00:57:02,086 Well, 'D' could be the absolute value of 'A' plus 'I' minus 1. 870 00:57:02,086 --> 00:57:04,714 You can do the math on this. It's not very difficult. 871 00:57:04,714 --> 00:57:07,210 'D' is the metric that goes from 0 to 1. 872 00:57:07,460 --> 00:57:09,574 0 means that right on the line. 873 00:57:09,607 --> 00:57:11,638 1 means that one of the two bad end points. 874 00:57:12,111 --> 00:57:14,831 If you wanna know which end point you can take the absolute value signs off. 875 00:57:14,831 --> 00:57:16,361 But I don't care. 876 00:57:16,481 --> 00:57:22,408 You can measure 'D' by looking at the fan-in and the fan-out of the component. 877 00:57:22,437 --> 00:57:23,996 Measuring its abstractness. 878 00:57:24,075 --> 00:57:27,696 Doing the math is not very difficult math to do. 879 00:57:27,733 --> 00:57:33,595 And find out whether your component sits nicely on that line. 880 00:57:34,044 --> 00:57:40,423 If it does then it is abstract as it is depended upon. 881 00:57:41,387 --> 00:57:46,815 If it doesn't that means either it's very abstract and not depended on 882 00:57:46,885 --> 00:57:49,023 or very concrete and heavily depended upon. 883 00:57:49,023 --> 00:57:50,361 Both of which are very bad ideas. 884 00:57:51,455 --> 00:57:55,190 There are lots of tools that automatically calculate these metrics for you. 885 00:57:55,261 --> 00:57:58,665 If you ever used NDepend. That will calculate the metrics for you. 886 00:57:58,698 --> 00:58:02,580 If you ever used any of the other static analysis tools, 887 00:58:02,658 --> 00:58:06,184 they can generate all these metrics. I. D. All of them for you. 888 00:58:06,255 --> 00:58:09,529 So that you can look at your components and see if they fit. 889 00:58:09,568 --> 00:58:14,219 And then think about what should be easy to change. 890 00:58:14,825 --> 00:58:17,924 Things that are easy to change should be in teenagers. 891 00:58:19,047 --> 00:58:23,650 Things that are hard to change should be in adults that are abstract. 892 00:58:23,650 --> 00:58:27,629 Concrete teenagers hold the stuff that's easy to change. 893 00:58:28,283 --> 00:58:31,796 Abstract adults hold the stuff that's hard to change. 894 00:58:32,967 --> 00:58:34,178 Any questions? 895 00:58:36,316 --> 00:58:40,364 We started with PDP-8 assembly code and got here. 896 00:58:42,809 --> 00:58:44,617 Any questions? No? 897 00:58:45,151 --> 00:58:45,653 Good. 898 00:58:46,559 --> 00:58:47,809 Oh, damn. 899 00:58:49,760 --> 00:58:51,276 It's alright. It's okay. 900 00:58:51,393 --> 00:58:56,854 (Someone is questioning.) 901 00:58:56,854 --> 00:58:57,486 Yep. 902 00:58:57,486 --> 00:59:03,080 (Someone is questioning) 903 00:59:03,080 --> 00:59:04,955 2 versions. 904 00:59:04,955 --> 00:59:07,015 (Someone is questioning) 905 00:59:07,015 --> 00:59:10,351 Yeah, 2 versions. Same component. You kill the programmers. 906 00:59:10,540 --> 00:59:11,189 Yeah. 907 00:59:11,599 --> 00:59:15,284 Don't have multiple versions of same component in you system please. 908 00:59:15,320 --> 00:59:16,923 That's DLL Hell. 909 00:59:17,847 --> 00:59:19,909 Anybody else? Yeah. 910 00:59:21,349 --> 00:59:24,025 Where do you place...? Very very good question. 911 00:59:24,025 --> 00:59:26,186 String class sits right there. 912 00:59:26,952 --> 00:59:31,841 It's in the worst possible place but nobody ever changes it. So we don't care. 913 00:59:32,118 --> 00:59:35,767 This is all about the stuff we are actively developing. 914 00:59:35,809 --> 00:59:37,831 The stuff that is being changed. 915 00:59:38,061 --> 00:59:42,786 So we pay very close attention to the stuff that's in our libraries that are changing. 916 00:59:42,786 --> 00:59:45,880 The stuff that we get from other libraries that's not changing. 917 00:59:45,918 --> 00:59:49,029 Or the stuff that's in our old libraries that's not changing. 918 00:59:49,066 --> 00:59:50,470 We not gonna pay attention to that here. 919 00:59:50,513 --> 00:59:52,332 A lot of that stuff may live here. 920 00:59:52,332 --> 00:59:53,456 And that's okay. 921 00:59:53,456 --> 00:59:54,923 None of it's gonna live here. 922 00:59:55,733 --> 00:59:57,620 Well, some of it might. 923 00:59:57,620 --> 00:59:59,589 Anybody pull out any dead code? 924 00:59:59,624 --> 01:00:01,948 Abstract classes that nobody implements? 925 01:00:02,007 --> 01:00:04,869 Yeah, okay. So maybe you see some stuffs there. 926 01:00:04,901 --> 01:00:11,720 But String, Vector, a lot of libraries live down here we don't care because they're not volatile. 927 01:00:11,756 --> 01:00:16,272 Think of another axis is coming out from this graph, right, towards you. 928 01:00:16,306 --> 01:00:18,368 That's the axis of volatility. 929 01:00:18,368 --> 01:00:21,573 This is a slice where volatility is close to 1. 930 01:00:22,123 --> 01:00:24,836 The stuff where volatility is 0, we don't care about it. 931 01:00:26,136 --> 01:00:27,084 Anybody else? 932 01:00:27,963 --> 01:00:29,200 Yo! In the back.