Robert C. Martin: Principles of Component Design.
-
0:04 - 0:08Ready? Is Sound On?
-
0:09 - 0:11Cool. Alright. So.
-
0:23 - 0:25Do you see that red dot?
-
0:30 - 0:32Why is it red?
-
0:35 - 0:37It's dangerous.
-
0:38 - 0:41I like that answer. Watch out! Take me to the Cuba.
-
0:43 - 0:52Yeah, I've had the security people restricted me from going in the airports, because I'm carrying lasers with me.
-
0:52 - 0:55They have, you know, sign on and it says dangerous.
-
0:57 - 0:59But, why is that red?
-
1:01 - 1:02I have a green laser.
-
1:02 - 1:05Hey, you know, you gotta have lasers.
-
1:06 - 1:09Alright? I carry three of them with me.
-
1:11 - 1:16One of them is red. I always keep them in my back pack with the batteries (??).
-
1:16 - 1:18Or turned around actually.
-
1:18 - 1:23So this is my red laser. You can get a red laser for twelve dollars.
-
1:24 - 1:25There it is. Red laser.
-
1:25 - 1:29Nice. And I got a green laser.
-
1:30 - 1:31This one is nice one.
-
1:33 - 1:35A pretty bright one too.
-
1:35 - 1:39Not bright enough to do anything interesting, but bright.
-
1:39 - 1:41There is little adjustment in here.
-
1:41 - 1:45You can cut a component out and put a different register in here.
-
1:45 - 1:48Then you can get almost of quarter of Watt out of it.
-
1:48 - 1:51The battery drains pretty fast. You can pop a balloon with it.
-
1:52 - 1:55I mean that's cool. Boom.
-
1:57 - 2:01But this is my favorite laser.
-
2:02 - 2:05And I like this one because
-
2:07 - 2:13Well, can you see that?
-
2:15 - 2:19Little tiny violet dot. Do you see that up there?
-
2:21 - 2:25See if I can show it to you here. Oh! That’s nice and bright.
-
2:25 - 2:28On my thing here. That's nice and bright.
-
2:28 - 2:31But over there, you can hardly see it.
-
2:31 - 2:34Can you see this thing? No.
-
2:34 - 2:36Can you see it here? No, not too much.
-
2:36 - 2:39No, can't see it there much.
-
2:39 - 2:49But, I found this once.
-
2:51 - 2:57Just a marker. Litter laser doesn't do too much to the marker.
-
2:57 - 2:59But the lid!
-
3:02 - 3:05And look! It's yellow!
-
3:06 - 3:07It's not blue!
-
3:08 - 3:11And then see that little orange thing there?
-
3:11 - 3:14Watch this! I gotta aim it carefully.
-
3:14 - 3:18Wow! It's orange.
-
3:18 - 3:20What kind of laser is this?
-
3:22 - 3:26This is a laser of some other color.
-
3:34 - 3:41My glasses are the kind that turn dark in the sun light.
-
3:45 - 3:48I don't know if you can tell. But now there are all dark.
-
3:48 - 3:51Alright? And I can't see any of you.
-
3:51 - 3:53This is an ultra violet laser.
-
3:54 - 3:58They don't bill it as such. You can buy them on amazon. 17$.
-
3:58 - 4:01They say it's a violet laser. They lie.
-
4:01 - 4:07It's much cooler than violet laser. It's an ultra violet laser.
-
4:07 - 4:10Everybody has to have an ultraviolet laser.
-
4:10 - 4:13It's completely useless as a laser pointer.
-
4:13 - 4:17But you can draw nice little pictures on you glasses with it.
-
4:19 - 4:22Oh~ I got my name.
-
4:25 - 4:27Alright. Whatever.
-
4:29 - 4:31Look at the code on the screen.
-
4:33 - 4:34Anybody recognize that code?
-
4:36 - 4:38I can't see it because my glasses are all dark.
-
4:39 - 4:41Anybody recognize that code?
-
4:42 - 4:44That's PDP-8 code.
-
4:45 - 4:49That what code looked like in 1970s.
-
4:49 - 4:55That's kind of code I was writing when I was slightly older teenager.
-
4:56 - 4:59And then on into my twenties as well.
-
5:00 - 5:04This statement right there.
-
5:04 - 5:06Anybody know what that means?
-
5:08 - 5:14That's the memory address which this program would be loaded.
-
5:15 - 5:20We used to write the address our program into our program.
-
5:21 - 5:24This program would be loaded at address 200.
-
5:24 - 5:27And we put the data at address 300.
-
5:27 - 5:28How about that?
-
5:29 - 5:33And it makes perfect sense. Of course you would know where programs getting get loaded.
-
5:33 - 5:35I mean who else is gonna decide that for you?
-
5:35 - 5:38You are the programmer. You have control over memory.
-
5:39 - 5:41Now, this works fine.
-
5:43 - 5:46I'll show you a sequence of pictures here.
-
5:46 - 5:50Let's see. Yeah, that's a nice one.
-
5:50 - 5:55Hello. No, that's not the one what I wanted.
-
5:56 - 6:02That's because nowadays when you open up documents
-
6:02 - 6:10It opens up every document that's been opened by that application.
-
6:11 - 6:12Don't save that.
-
6:12 - 6:15That's the one I wanted, right there.
-
6:17 - 6:20Imagine you are programmer who's writing this kind of code.
-
6:21 - 6:24And you've got a program like this one.
-
6:25 - 6:28My program lives here. It starts at address 200.
-
6:29 - 6:32And there's a subroutine library that somebody else has written.
-
6:33 - 6:35By the way subroutine libraries were not real common.
-
6:35 - 6:38You usually wrote your own subroutine back in those days.
-
6:38 - 6:46But after a while a few guys write some useful subroutines. You think "You know, I should have those in my program too."
-
6:46 - 6:50And you think, "Well, just compile them in with my code"
-
6:50 - 6:52That's what we used to do.
-
6:52 - 6:53You just take the source code and jam it together.
-
6:54 - 6:55What was the problem with that?
-
6:59 - 7:02We were talking about the 1970s here. Right?
-
7:02 - 7:06Those programs were contained on paper tape.
-
7:06 - 7:10Paper tapes is being 50 characters per second, if you were lucky.
-
7:11 - 7:20And so increasing the size of your source code lengthened the size of your compile by minutes.
-
7:20 - 7:27So after a while these subroutine libraries got too long to continue to add your source code.
-
7:27 - 7:35So what we did is we would compiled the subroutine library and we would loaded at location 1200.
-
7:36 - 7:42Then what we could do is we could have a binary file which got loaded at 1200.
-
7:42 - 7:45And we could have our program at 200.
-
7:45 - 7:49And we did have a little file that all the symbols in it.
-
7:49 - 7:55So the symbols would tell us which subroutine was loaded where.
-
7:55 - 8:03So we knew the Get subroutine was at 205 and the Put subroutine was at 210 and so on.
-
8:04 - 8:07And our symbols would get compiled in with the program
-
8:07 - 8:10The subroutine would be loaded separately. And everything worked fine.
-
8:12 - 8:14What's the problem with this?
-
8:16 - 8:19When is the last time you saw a program that stayed small?
-
8:21 - 8:22They grow!
-
8:23 - 8:26And after a while, well let's see.
-
8:28 - 8:30I got another picture here.
-
8:35 - 8:36Yeah, that's that one.
-
8:41 - 8:44Oh yeah, a program that got too big.
-
8:44 - 8:47It overwrites the subroutines. This doesn't work.
-
8:49 - 8:56When your program overwrites the subroutines, your program still thinks that the subroutines are there.
-
8:56 - 9:02So when it calls the location 1205 it actually jumps into some arbitrary part of you code.
-
9:03 - 9:04You didn't know this happened of course.
-
9:05 - 9:08Until finally you debugged it and realized. "Oh, my programs got too big!"
-
9:09 - 9:11What's the solution to this?
-
9:14 - 9:18You are programmers, you can come up with the solution to this.
-
9:21 - 9:23Jump around the subroutine library.
-
9:24 - 9:27Right? You put it Jump right there to jump over here.
-
9:28 - 9:31Of course the subroutine library gets bigger too.
-
9:32 - 9:40And so after a while. Let's see if I've got that picture right.
-
9:40 - 9:42How about that one? Yeah, that's the one.
-
9:43 - 9:45After a while you get that problem.
-
9:48 - 9:51We actually faced to this problems.
-
9:51 - 9:54We actually had to deal with this stuff.
-
9:54 - 9:56And you know how we solved it?
-
10:00 - 10:05We came up with relocatable code.
-
10:05 - 10:10We said "You know what? This idea of putting absolute address in the program is killing us."
-
10:11 - 10:17"What we really like to do is compile our programs without telling them where they're going to be loaded."
-
10:18 - 10:21"And then we'll tell the loader where to load them"
-
10:21 - 10:23Now there's problem with that.
-
10:24 - 10:30Because that means that your binary files cannot really be binary.
-
10:30 - 10:39They have to have codes in them to tell you that certain address are not actually addresses. They are offsets.
-
10:39 - 10:48And the loader has to find every address that's marked as an offset and add the start address to it.
-
10:49 - 10:52But that works. We had relocatable loaders.
-
10:52 - 10:55We made this relocatable binaries and loaders.
-
10:55 - 10:57But now you've got another problem.
-
10:57 - 11:00Because how do you know where the subroutines are.
-
11:00 - 11:06If the subroutines are moving all over the place, how do you know where the subroutines are?
-
11:06 - 11:11So now you have to add more information to the binary file.
-
11:11 - 11:20This binary file you thought just binary of your program is now becoming very bizarre files.
-
11:20 - 11:21It's got all kinds of gunky in it.
-
11:21 - 11:28Now you have to put the names of the subroutine library into the binary file of the subroutines.
-
11:28 - 11:32And you have to show what address they will get loaded at
-
11:33 - 11:38And relocatable loader has to remember where it put those addresses
-
11:38 - 11:43And then in the program you have to have another thing in there.
-
11:43 - 11:47That says "Hey, I need to know where this programs gonna be loaded"
-
11:47 - 11:53"And the loader has to link the subroutine library of the program."
-
11:57 - 12:01Computers were slow in those days.
-
12:01 - 12:03Disk drivers were very slow.
-
12:03 - 12:05And there wasn't a lot of disk memory.
-
12:05 - 12:08You were lucky if you had megabytes of disk.
-
12:08 - 12:15And the seek arm took a long time and the rotational latency was high.
-
12:15 - 12:18So link times took a long time.
-
12:18 - 12:22Especially as we got more and more libraries.
-
12:22 - 12:24More and bigger program.
-
12:24 - 12:26Link time could take an hour.
-
12:26 - 12:28Anybody have a link that took an hour?
-
12:28 - 12:31Anybody here working in the 80s?
-
12:31 - 12:33Oh no! You got one now!
-
12:33 - 12:35You must be C++ programmer.
-
12:37 - 12:39That says so, right on your shirt.
-
12:39 - 12:41OSLO C++ Users Group.
-
12:41 - 12:43Long link times.
-
12:45 - 12:50Even in the 70s we had that problem. Although it was much smaller programs.
-
12:50 - 12:58So the solution to that was to separate the link pace from the load pace.
-
12:58 - 13:02We would link as a second compile step.
-
13:02 - 13:07And that would produce a final relocatable file that had all the linkage were resolved.
-
13:07 - 13:10And then we could load it at run time.
-
13:10 - 13:12Ant that was relatively fast enough.
-
13:13 - 13:18And for years and years and years. We lived with this 2 step process.
-
13:18 - 13:24Compile down to binary files then link all the binary files into an executable.
-
13:24 - 13:26And then you can load the executable.
-
13:27 - 13:30And that solved problem until the 90s.
-
13:30 - 13:34In the 90s something happened.
-
13:34 - 13:36It was called Moore's Law.
-
13:37 - 13:38What's Moore's law?
-
13:39 - 13:44The speed of processors will double every 18 month.
-
13:44 - 13:53Now apply that from about 1970 when the speed of our processors were half a million instructions per second.
-
13:54 - 13:57And keep that going forward until the 1990s.
-
13:57 - 14:00Well that's 20 years, how many 18 cycles is that?
-
14:00 - 14:02Well, 18 month cycle is that?
-
14:02 - 14:04That's about 15 cycles.
-
14:04 - 14:07So we have 2^15 increase in speed.
-
14:08 - 14:09Think about that.
-
14:09 - 14:122^15 increase in speed. What is that?
-
14:12 - 14:14That's increase about 32000!
-
14:14 - 14:15That's about right too.
-
14:15 - 14:19Cause we went from about a half MHz to 2.8 GHz.
-
14:19 - 14:22Well, maybe 1 GHz by the late 90s.
-
14:22 - 14:25By that time disks were going faster too.
-
14:25 - 14:27We spun up a lot faster in the road.
-
14:27 - 14:32The heads weren't moving as far, we were getting a lot more bits around rim too.
-
14:32 - 14:39We could get hundreds of MBs on a disk. Oh!
-
14:41 - 14:44And somebody made a bright thought.
-
14:44 - 14:46Somebody had a bright thought that
-
14:47 - 14:50"We don't have to do the link separately anymore."
-
14:51 - 14:54"We can do the link at the same time we load."
-
14:54 - 14:57Anybody remember the ActiveX?
-
14:57 - 14:59Anybody remember OLE?
-
15:00 - 15:02What does DLL stands for?
-
15:04 - 15:08Dynamically linked library.
-
15:08 - 15:11Which means it's linked at load time.
-
15:11 - 15:15The link step got moved back into the loader.
-
15:16 - 15:19And we have the situation we have today.
-
15:21 - 15:23Who's .NET programmer, here?
-
15:24 - 15:25Look at that. A lot of people.
-
15:25 - 15:28Java programmer! Raise your hands.
-
15:28 - 15:30Not so many. How come?
-
15:31 - 15:35How come it's all .NET? Oh maybe because it's a .NET kind of conference? Huh?
-
15:36 - 15:42So, in .NET you got DLLs.
-
15:42 - 15:44Dynamically Linked Libraries.
-
15:44 - 15:46In Java, you got Jar files.
-
15:46 - 15:51But they are still dynamically linked libraries. Same idea. Same purpose.
-
15:52 - 15:56In C++, if you do in the Microsoft thing you still got DLLs.
-
15:56 - 15:59If you don in UNIX thing you've got shared libraries.
-
15:59 - 16:01They are still dynamically linked libraries.
-
16:01 - 16:05Our mode of operation now a days is too dynamic linked libraries.
-
16:05 - 16:08That's how we got here.
-
16:12 - 16:14How many DLLs do you have?
-
16:15 - 16:19Guys with the solutions, Visual Studio solutions.
-
16:19 - 16:20How many projects?
-
16:21 - 16:2460? That's not bad.
-
16:24 - 16:25Who's got more than 60?
-
16:25 - 16:27Oh, look at that.
-
16:27 - 16:28Who's got more than 200?
-
16:31 - 16:33And do you know why?
-
16:33 - 16:38You separate your code into different DLLs?
-
16:39 - 16:41Let me ask that question differently.
-
16:41 - 16:44When you deploy your application,
-
16:45 - 16:50Do you gather up all the DLLs and just ship the wad?
-
16:53 - 16:58If you do then why are you dynamically linking them?
-
16:58 - 16:59Statically link them.
-
17:00 - 17:05Why would you bother with dynamic linking? If you just gonna take all those DLLs.
-
17:05 - 17:07Gather them up into one gigantic wad.
-
17:07 - 17:10Throw the big wad into directory. And says, "It's my system."
-
17:12 - 17:17Why dynamically link if you not going to dynamically deploy?
-
17:18 - 17:22Why did we come up with dynamically linked library?
-
17:22 - 17:29We came up with dynamically linked library so that we could dynamically deploy our applications.
-
17:29 - 17:30Why?
-
17:33 - 17:36Well, we gonna get to network speed. Hang on in a minute.
-
17:36 - 17:39Cause network speed has huge impact on this all thing.
-
17:39 - 17:44Mid 90s I've got a client. He's got a 250MB executable.
-
17:44 - 17:47In the mid-90s that was big program. Now it' not.
-
17:47 - 17:52But then 250MB was big deal, you could not fit it on a CD.
-
17:52 - 17:57This was CAD system. He shipped it to the company like Ford.
-
17:57 - 18:02Ford would use it to design gears and levers. Stuff like that.
-
18:03 - 18:04He statically linked it.
-
18:05 - 18:11He would deploy the executable to his clients by burning it on several CDs.
-
18:12 - 18:15If he changed one line of code,
-
18:17 - 18:26He had to recompile, re-link, re-burn all the CDs and deploy all the CDs to all his clients.
-
18:27 - 18:30And you can imagine how it cost him a fair bit of money.
-
18:32 - 18:34I went there in the mid-90s.
-
18:34 - 18:37And encountered them at a time
-
18:37 - 18:44when they were trying to chop up their executable into this new Idea, DLLs.
-
18:44 - 18:49Because they realized that if they had dynamically linked libraries
-
18:49 - 18:52Then they could change a line of code
-
18:52 - 18:57And ideally you would only have to ship that DLL.
-
18:58 - 19:01You could e-mail it!. Back in those days that was a big deal.
-
19:01 - 19:03You couldn't e-mail 250MB in those days.
-
19:03 - 19:08Now a days you can as long as the guy you're talking to got a reasonable e-mail server.
-
19:08 - 19:17But back in those days e-mailing 250MB was impossible, so they could e-mail the 100KB of DLL.
-
19:17 - 19:20And so that was very very desirable for them.
-
19:20 - 19:22They worked for month and month and month.
-
19:22 - 19:25Chopping their application up in the little tiny bits,
-
19:25 - 19:27turning them all into bunch of DLLs
-
19:27 - 19:29And that when they realized their critical mistake.
-
19:31 - 19:35The critical mistake was that chopping your system up into bunch of arbitrary DLLs
-
19:35 - 19:39doesn’t do you a damn bit of good if they all depend on each other.
-
19:40 - 19:43If they are all depend on each other then you can...
-
19:52 - 19:56Was anybody just in Scott Meyer's talk here?
-
19:56 - 19:58The last talk he just gave an hour ago?
-
19:58 - 20:01He was talking about the problem of keyholes.
-
20:01 - 20:08Problem of keyholes is that we arbitrarily constrain someone for no good reason.
-
20:08 - 20:10Just arbitrary constrain them.
-
20:10 - 20:15So for example, have you ever seen a text box on a GUI?
-
20:15 - 20:16That was just too short?
-
20:17 - 20:22And you had typed bunch of stuffs in it and it wouldn't let you resize the window?
-
20:22 - 20:26It wouldn't let you scroll and you just had to type blind?
-
20:26 - 20:30Or maybe the text with scroll but you wouldn't be able to see the beginning of it?
-
20:30 - 20:35He was mentioning the keyhole problem.
-
20:35 - 20:38And I know that something just happened here.
-
20:39 - 20:43Apparently I'm not allowed not touch my computer for more than 5 minutes.
-
20:43 - 20:48I must apparently touch my computer otherwise I'll be punished.
-
20:52 - 20:55What was I talking about? Oh yeah, DLLs.
-
20:55 - 20:58So this guy, he put all his DLLs together.
-
20:58 - 21:00He forgot that DLLs depend upon each other.
-
21:01 - 21:04His goal was to be able to touch a line of code
-
21:04 - 21:08And just ship that DLL that was affected.
-
21:08 - 21:12But he found that all the '#includes', C++ guys know what I'm talking about
-
21:12 - 21:15All the '#includes' form the horrible network.
-
21:15 - 21:18And he had to recompile and redeploy everything anyway.
-
21:18 - 21:20They went out of business.
-
21:23 - 21:28The purpose of my talk today, now that I'm getting around to it
-
21:29 - 21:31is to talk about components.
-
21:31 - 21:33The problem of component design.
-
21:33 - 21:36And the first thing we gonna do is to define a component.
-
21:36 - 21:39What's a component? Component is DLL.
-
21:39 - 21:43When I talk about the word component what I mean is DLL.
-
21:43 - 21:47Very particular kind of DLL. A dynamically deployable DLL.
-
21:49 - 21:53A dynamically deployable DLL.
-
21:53 - 21:56Why would we want dynamically deploy?
-
21:57 - 22:00Well, because we would like to be able to change one line of code
-
22:00 - 22:03Just ship the one DLL that changed and ignore all the others.
-
22:03 - 22:05What's DLL hell?
-
22:05 - 22:09A term invented, I believe, by Microsoft
-
22:10 - 22:12to describe their own situation.
-
22:13 - 22:18And was to be completely cured by .NET.
-
22:18 - 22:22Anybody remember that line? "Dear .NET cures DLL hell."
-
22:22 - 22:28Hu Hu Hu. No, it doesn’t cure DLL hell.
-
22:28 - 22:32DLL hell is the problem that we've got all these little components with different version numbers
-
22:32 - 22:35And nobody hell knows which one go should together
-
22:35 - 22:39So we invented this module maintenance tools like Maven.
-
22:39 - 22:41What are you guys using in .NET?
-
22:41 - 22:46What's the tool that lets you keep all of your DLLs are in line.
-
22:46 - 22:50So you know that download version 1 of that one and version 3 of that one.
-
22:50 - 22:53Do you have tool for that? What?
-
22:54 - 22:55NuGet?
-
22:55 - 22:57Like the soft chewy (??)
-
22:59 - 23:01Never mind, I'm not going there.
-
23:10 - 23:18The graph you see on the screen is a graph of x^2.
-
23:18 - 23:20That's just an x^2 graph.
-
23:21 - 23:23But it's also something else.
-
23:23 - 23:29It's the number of dependencies in a system.
-
23:29 - 23:34Theoretical maximum number of dependencies, given a certain number of modules.
-
23:34 - 23:38And you can see that the number of modules increases linearly
-
23:38 - 23:41And the number of dependency increases with square.
-
23:44 - 23:49The theoretical maximum number of coupling, which I show here
-
23:51 - 23:55is proportional to the square of the number of modules.
-
23:55 - 24:01Now of course we would never create a system that has every possible dependency in it.
-
24:03 - 24:04Or would we?
-
24:06 - 24:08Look at this curve.
-
24:09 - 24:20This curve is the productivity of a team in comparison to the number of modules.
-
24:20 - 24:25By the way this is completely arbitrary I just generated one of x squared curve here.
-
24:25 - 24:28This is not me collecting actual data.
-
24:29 - 24:34This is just me recollecting my experience with development teams.
-
24:34 - 24:38They go slower and slower and slower over time.
-
24:38 - 24:39Who's had this happened to them?
-
24:40 - 24:42You start outgoing really fast. You can conquer the world.
-
24:42 - 24:46A year later you slogging through some kind of horrible wet lands.
-
24:46 - 24:49And you don't know what the heck has gone wrong.
-
24:49 - 24:53But estimates that used to be on the order of one week are now three month long.
-
24:53 - 24:58And by the way you blow all those estimates anyway and introduces more bugs than you fix.
-
24:58 - 25:04That's the kind of problem that we have as we proceed a long development path.
-
25:04 - 25:10And one of the reasons for that is accumulation of dependencies.
-
25:11 - 25:12Why?
-
25:12 - 25:21Well, that's the theoretical maximum dependency between modules.
-
25:21 - 25:23This is the theoretical minimum.
-
25:23 - 25:29If you're going to have an interconnected set of modules, there has to be some dependencies.
-
25:29 - 25:32And the minimum set of dependencies is a tree structure.
-
25:32 - 25:36Oh you can do some better with dynamically linking if you want to.
-
25:36 - 25:40But for the most part, you gonna have a small number of dependencies.
-
25:40 - 25:42How many do we have? 1. 2. 3. 4. 5. 6.
-
25:42 - 25:456 out of 7 modules.
-
25:45 - 25:47Whereas here you've got
-
25:47 - 25:51Well, I think that's half of 49.
-
25:51 - 25:54It can't be half of 49 because that would be happy half dependency.
-
25:54 - 25:58Maybe it's just a plain 49. I don't know what it is. It's a large number.
-
25:58 - 26:01It's some relative of N squared.
-
26:01 - 26:03Maybe it's one half n squared plus one half n.
-
26:03 - 26:05Something like that.
-
26:05 - 26:08It's a very large number of dependencies.
-
26:08 - 26:11We don't want this. We do want that.
-
26:11 - 26:13We strive very hard to get here.
-
26:13 - 26:21But then, some shmuck does that.
-
26:24 - 26:26Visual Studio doesn't allow this.
-
26:27 - 26:29Uh! Inside solution.
-
26:29 - 26:34Inside solution. The DLLs cannot have cycles between their graphs.
-
26:34 - 26:35That's good.
-
26:35 - 26:36Don't want cycles.
-
26:36 - 26:39Between separate solutions there's no guarantee.
-
26:39 - 26:40So you have multiple solutions.
-
26:40 - 26:45If you're linking with things that come out of different solutions, you can still have cycles in the graph.
-
26:45 - 26:51If you get cycles in the graph, it looks like it adds only one extra dependency.
-
26:51 - 26:53But actually it adds more.
-
26:53 - 26:57Because 6 now depends upon 2. Because 1 depends upon 2.
-
26:57 - 26:59And dependency is transitive.
-
26:59 - 27:05So 6 also depends upon 4 and 5. And 6 depends upon 3 and 7.
-
27:05 - 27:07In fact, 6 depends upon all of them.
-
27:08 - 27:14So number of dependencies multiplies dramatically as soon as you have a cycle.
-
27:22 - 27:24This is the n squared graph again.
-
27:25 - 27:29This is also a graph of C++ compile time.
-
27:29 - 27:31As you add modules.
-
27:31 - 27:34Compile time and the link time if you're doing static linking
-
27:34 - 27:36But even if you're not static linking,
-
27:36 - 27:40just compile time grows with the square of the number of modules,
-
27:40 - 27:45if you have a fully connected network of modules.
-
27:45 - 27:52What that mean is that your '#include' or your import statements or your using statements can be traced in a cycle.
-
27:53 - 27:59And if you have that, then you gonna wind up with this big increase in compile time.
-
27:59 - 28:01C++ in particular would do this.
-
28:01 - 28:03Java and .NET don't.
-
28:04 - 28:06Their compile time is based on a different metric.
-
28:06 - 28:12They don't go reading source files. The way C++ does.
-
28:12 - 28:15Java and .NET read binary files to get their declarations.
-
28:15 - 28:19C++ reads source files to get his declarations.
-
28:19 - 28:24And so if you had a cycle in C++, you got punished.
-
28:25 - 28:27By a big compile time.
-
28:27 - 28:29And a massive one.
-
28:29 - 28:30It would go up with square.
-
28:30 - 28:33So you would had couple of modules your compile time will double.
-
28:33 - 28:36And that made us do something about it.
-
28:36 - 28:39Who knows who Ward Cunningham is?
-
28:40 - 28:40Oh, a few of you do.
-
28:40 - 28:42Good. And the rest of you.
-
28:42 - 28:43He's the guy who invented Wikis.
-
28:43 - 28:47Ward Cunningham invented Wikis.
-
28:47 - 28:52He's the guy who helped Kent Beck invent pair programming, test-driven development,
-
28:52 - 28:53And most of the agile stuff.
-
28:53 - 28:57Get to know who Ward Cunningham. He is very interesting fellow.
-
28:57 - 28:59Smalltalk Programmer from a long ago.
-
28:59 - 29:01And I asked Ward once.
-
29:01 - 29:03"Why did Smalltalk died, Ward?"
-
29:03 - 29:10And he said, "Smalltalk died because it was so easy to make a mess."
-
29:11 - 29:13"You, C++ programmer,”
-
29:13 - 29:14I was a C++ programmer at that time.
-
29:14 - 29:17"You, C++ programmers are lucky."
-
29:17 - 29:19"Your language punishes you if make a mess."
-
29:20 - 29:22"Smalltalk didn't punish you."
-
29:23 - 29:27Well, neither does Java. Neither does C#.
-
29:27 - 29:29They don't punish you anymore.
-
29:29 - 29:31It's very easy to make a very large mess.
-
29:31 - 29:35And get a very tangled structure and not know you're doing it.
-
29:35 - 29:39Fortunately Visual Studio keeps some of the cycles out of your graph.
-
29:44 - 29:49We would like that level of productivity, which is n Log N.
-
29:49 - 29:52Rather than this level of productivity. That's an n squared.
-
29:53 - 30:00And one of the ways to help with that is to manage the dependencies between our components.
-
30:02 - 30:07Then something happened to us in the late 90s and into the 2000s.
-
30:07 - 30:10Network speed started increasing dramatically.
-
30:11 - 30:16Now a days, it's not hard at all to download a GB in a couple of seconds,
-
30:16 - 30:18And to upload a GB in 10 seconds.
-
30:18 - 30:19That's pretty easy now a days.
-
30:19 - 30:22Back in the early days it was much harder.
-
30:22 - 30:28So, back in the early days we thought shipping individual DLL was going to be a benefit.
-
30:29 - 30:32Now a days we just kind of gather them all together and ship the one big wad.
-
30:32 - 30:36Why? Well because network speed is fast enough. We can do it.
-
30:36 - 30:40We can treat our batch of DLLs just like it was statically linked.
-
30:42 - 30:43But there's another issue.
-
30:44 - 30:46How many of you work in teams?
-
30:47 - 30:50Oh look at that. Everybody works in teams.
-
30:51 - 30:54So, you come in at 8 in the morning.
-
30:56 - 30:59You got a test to perform.
-
30:59 - 31:02You work all day to get all your stuff working.
-
31:02 - 31:04All works by end of the day.
-
31:04 - 31:05You check it in and go home.
-
31:05 - 31:07Come back the next day all your stuff is broken.
-
31:07 - 31:08Why?
-
31:10 - 31:12Somebody stayed later than you.
-
31:13 - 31:16And changed something you depend upon.
-
31:17 - 31:22And so you work all day long to fix whatever the problem was.
-
31:22 - 31:24You go home and come back the next day and your stuff is broken again.
-
31:25 - 31:26How many times can you go around that loop?
-
31:27 - 31:31Lots of time. This is a problem of large teams.
-
31:31 - 31:35Large teams will start to step on each other.
-
31:35 - 31:37And of course we've invented tools to help us.
-
31:37 - 31:39We've got source code control systems.
-
31:39 - 31:42And we've got all kinds of good stuff to help us with this.
-
31:42 - 31:47But we still can step all over each other, unless we manage our projects well.
-
31:48 - 31:52So, how can we manage our projects well?
-
31:56 - 31:58There is a principle.
-
32:07 - 32:11A principle called Acyclic Dependencies Principle.
-
32:13 - 32:19The Acyclic dependencies principle says, "If you have a set of components"
-
32:19 - 32:23"You would like to be able to arrange without any cycles in the dependency graph."
-
32:23 - 32:26Now, for whole bunch of reasons we've already talked about one of them.
-
32:26 - 32:30Which is compile time. We've talked about another which is just dependency load.
-
32:30 - 32:32Here is another.
-
32:34 - 32:39Alarm would like to release its version of alarm.
-
32:39 - 32:43The team that's working on the Alarm would like to make release 1.0.
-
32:43 - 32:49They've got nobody that they depend upon.
-
32:49 - 32:52So they are completely free to make any release they want.
-
32:52 - 32:56So they release their version of 1.0. Alarm 1.0.
-
32:56 - 32:58They start working on alarm 1.1.
-
32:59 - 33:02But now Alarm 1.0 has been released.
-
33:02 - 33:06Which means that Elevator and Conveyor can make their release.
-
33:07 - 33:12And once Elevator and Conveyor made their releases they can start to work on 1.1.
-
33:12 - 33:16But now Transport can make its release.
-
33:16 - 33:18You can see what's happening here. Right?
-
33:18 - 33:21The version numbers bubble up from the bottom.
-
33:21 - 33:271.0 gets created here. Then there. Then there. Here. Here. And finally there.
-
33:27 - 33:30The version numbers bubble up from the bottom.
-
33:30 - 33:33If you look at it closely, you'll realize that
-
33:33 - 33:38the version numbers follows exact same path as the build. The compile.
-
33:38 - 33:42Dependencies are running in that direction.
-
33:43 - 33:50And now, some poor shmuck does this.
-
33:50 - 33:53Who's this?
-
33:53 - 33:54Well that was me. I did that.
-
33:54 - 33:59I had an alarm subsystem I was working on.
-
33:59 - 34:02And I needed it to put a message on the display and the control panel.
-
34:02 - 34:07There happened to be a class up here that had a function called Display.
-
34:07 - 34:10And I thought, "Oh! I should just call it." So I called it.
-
34:10 - 34:13This was not in a language that restrict me from cycles.
-
34:13 - 34:17And so it compiled and everything was fine and all worked okay.
-
34:18 - 34:23And then the next day I had a group of angry developers come to my cubicles with club
-
34:24 - 34:25And tell me "What the hell did you do?"
-
34:26 - 34:33I said, "Well, I just called the control panel and display class that has display function in it."
-
34:33 - 34:35"I needed to put this message on the screen."
-
34:35 - 34:36And they said, "You can't do that."
-
34:36 - 34:38Why can't we do that?
-
34:40 - 34:41First of all,
-
34:44 - 34:48what order should we build those modules in?
-
34:50 - 34:53You'd like to build them bottom up.
-
34:54 - 34:56But now there's no bottom.
-
34:56 - 34:58So there's no correct build order.
-
34:58 - 35:01If you have cycles in the component graph,
-
35:02 - 35:06there is no correct build order for the modules in that system.
-
35:07 - 35:11And therefore the execution of that system is undefined.
-
35:12 - 35:15What does undefined mean? What's the definition of undefined?
-
35:16 - 35:18Works in the lab.
-
35:20 - 35:24Anything undefined will work until you actually deploy it somewhere. Then it will fail.
-
35:25 - 35:29You can get systems to fail rather badly by having this cycles.
-
35:29 - 35:31This is pretty common in Java.
-
35:31 - 35:36If you have a system of Java that has cycles in it.
-
35:36 - 35:37You can build it.
-
35:37 - 35:39Although there is no correct build order.
-
35:39 - 35:41Then you run your test. And test will fail.
-
35:42 - 35:45Then you build it again. That will choose different build order.
-
35:45 - 35:46And maybe the test will pass.
-
35:46 - 35:49I know of companies that put their build in a loop until test pass.
-
35:55 - 35:56But the problem is worse than that.
-
35:57 - 36:04Because conveyor would like to make their release.
-
36:04 - 36:06They want to release 1.1.
-
36:06 - 36:11Now for them to release 1.1, they have to test with alarm 1.1.
-
36:12 - 36:18But alarm 1.1 is waiting for control panel 1.1, which is waiting for transport 1.1
-
36:18 - 36:22which is waiting for conveyor 1.1, which is the one trying to release.
-
36:22 - 36:28So there's no way to make the release without checking all of that source code out into one place.
-
36:28 - 36:31Integrating. Anybody remember integration.
-
36:31 - 36:32The joys of integration.
-
36:32 - 36:37Integrate the whole system and then make it work.
-
36:38 - 36:41And while you're doing that you gonna be stepping all over each other.
-
36:41 - 36:50So, if this cycle will bring back the problem of coming in 8 in the morning and find everything doesn't work.
-
36:50 - 36:52But it's worse than that.
-
36:53 - 36:58Because in order to test conveyor I need alarm.
-
36:58 - 37:02Which needs control panel which needs revenue, which need the database.
-
37:02 - 37:06The database takes 45 minutes to load and then it crashes.
-
37:07 - 37:09I can't run my tests.
-
37:09 - 37:14Ant the guys in conveyor saying, "Why the heck do I need the database?"
-
37:14 - 37:17"Well, you need the database because of this strange dependency structure."
-
37:18 - 37:22Anybody ever look at the number of DLLs that got loaded and scratch head and say,
-
37:22 - 37:24"How come I need those?"
-
37:24 - 37:27Anybody in C++ world have ever link line?
-
37:27 - 37:29And wonder "what's all this stuff in the link line?"
-
37:29 - 37:31"How come I need all that stuff?"
-
37:31 - 37:33Right? You got cycles in the dependency graphs.
-
37:33 - 37:35It's bringing in all kinds of gunk.
-
37:35 - 37:43So the first principle of components is no cycles in the components.
-
37:43 - 37:45What if you want to do this?
-
37:46 - 37:52What if you really want to call some function from down here that lives up there?
-
37:52 - 37:53How you gonna do it?
-
37:55 - 37:57Well, you can put out another component.
-
37:58 - 38:00That's one way to do it.
-
38:00 - 38:03Here I took that class out of the control panel.
-
38:03 - 38:05I put it in the display component.
-
38:05 - 38:08Then the alarm component can talk to the display component.
-
38:08 - 38:10The control panel can talk to the display component.
-
38:11 - 38:12I can keep the cycles out.
-
38:12 - 38:14That's common enough technique.
-
38:14 - 38:16Remember, these are all DLLs.
-
38:16 - 38:23So number of DLLs in your system will start to grow as people want to add cycles to the dependency graph.
-
38:23 - 38:25Maybe.
-
38:25 - 38:28Although there's another way to resolve the cycle.
-
38:30 - 38:33You can use dependency inversion.
-
38:33 - 38:40I could put an interface. A display interface.
-
38:40 - 38:42In the alarm subsystem.
-
38:42 - 38:45And have the control panel implemented it.
-
38:46 - 38:48That turns the dependency around.
-
38:50 - 38:53And changes a cycle into a straight tree.
-
39:00 - 39:01What's OO?
-
39:04 - 39:06What is Object Orientation?
-
39:09 - 39:10Why do we like it?
-
39:11 - 39:15How come all of our languages are object oriented languages?
-
39:15 - 39:17We've been doing this for 30 years. We gotta know.
-
39:17 - 39:19(Someone says) "Models the real world."
-
39:19 - 39:20Models the real world! Thank you!
-
39:20 - 39:23I planted him here so that he would say that.
-
39:23 - 39:25So then I could rip him to shred.
-
39:25 - 39:27No, that's absurd.
-
39:27 - 39:32And that whole idea that OO has better way to model real world is plain non-sense.
-
39:32 - 39:35It's something. Some guy concocted long time ago
-
39:35 - 39:39To convince his manager to spend 12,000$ on C++ compiler.
-
39:40 - 39:42Cause he couldn't figure out any other ways to get his manager to do it.
-
39:42 - 39:4612,000$. Early C++ compiler costed a lot of money.
-
39:46 - 39:48"12,000$. I'm not spending that for a compiler."
-
39:48 - 39:50"Well, it will help me model the real world!"
-
39:50 - 39:53"Oh. Okay then."
-
39:53 - 39:58This whole notion of modeling the real world is downright silly.
-
39:58 - 40:05What in the world is OO other than a bunch of functions using a bunch of data structure? Right?
-
40:05 - 40:07Encapsulated. Okay fine. Encapsulated.
-
40:07 - 40:09But bunch of functions using bunch of data structures.
-
40:09 - 40:12How is that different from Non OO?
-
40:13 - 40:15The answer to that is not easy to describe.
-
40:16 - 40:18How that's different?
-
40:18 - 40:22Well, okay. We kind of put the data structures in the functions together.
-
40:22 - 40:24But we always used to do that.
-
40:24 - 40:27Old C programmers used to that all the time.
-
40:27 - 40:30Data structures in programs always went together.
-
40:30 - 40:34There is a famous book called 'Algorithms plus data structures equals programs.'
-
40:34 - 40:37Data structures now (??) working together.
-
40:37 - 40:39So nothing really fancy about OO there.
-
40:39 - 40:44There is one thing that OO gave us that we did not have before.
-
40:44 - 40:46Because it wasn't safe.
-
40:46 - 40:47And that's polymorphism.
-
40:47 - 40:51Very very convenient polymorphism.
-
40:51 - 40:53We used to have it in C.
-
40:54 - 40:58Device independence in any operating system is an example of polymorphism.
-
40:58 - 41:03If you can write a program, you don't need to know what device that program is gonna use.
-
41:03 - 41:05It's a clearly polymorphic interface.
-
41:06 - 41:09But that's dangerous in most languages.
-
41:09 - 41:10Or it was back in those days.
-
41:10 - 41:12Because you have to fiddle with pointers to functions.
-
41:12 - 41:14And that was always dangerous.
-
41:15 - 41:19What OO gave us was very very convenient polymorphism.
-
41:19 - 41:21Polymorphism without thinking about it.
-
41:21 - 41:24Java in particular all the methods are polymorphic.
-
41:24 - 41:25There's no choice.
-
41:25 - 41:29C#, you have choice. You can use that funny virtual keyword.
-
41:29 - 41:35C++ programmers you've got a choice. You better use that virtual keyword. Especially on your destructors.
-
41:36 - 41:39But most of us we don't even pay attention anymore.
-
41:39 - 41:42All our functions are polymorphic. We don't even think about it.
-
41:42 - 41:43Why?
-
41:44 - 41:49Because when a function is polymorphic something amazing happens.
-
41:50 - 41:55The flow of control goes down towards to derivatives.
-
41:55 - 41:59But the source code dependency goes back towards base.
-
42:00 - 42:08We can take a source code dependency and turn it around without changing the run time dependency.
-
42:08 - 42:10How do you get DLLs?
-
42:10 - 42:12How do you get components?
-
42:12 - 42:14You isolate them.
-
42:14 - 42:17But you have to maintain the run time dependency.
-
42:21 - 42:23Visual Studio people
-
42:25 - 42:28Are you using ReSharper?
-
42:29 - 42:30Who is? ReSharper?
-
42:30 - 42:32Look at that. Everybody.
-
42:33 - 42:36Does Visual Studio know about ReSharper?
-
42:38 - 42:39No.
-
42:39 - 42:42Does Visual Studio call ReSharper?
-
42:43 - 42:45Yes.
-
42:45 - 42:49The flow of control goes from Visual Studio into ReSharper.
-
42:49 - 42:54There are function calls in Visual Studio that their way into ReSharper.
-
42:54 - 43:01But there is no source code dependency that moves from Visual Studio into ReSharper.
-
43:01 - 43:03Because they've been inverted the dependencies.
-
43:04 - 43:10You can create DLLs that your application will call.
-
43:10 - 43:12But your application doesn't know it exist.
-
43:13 - 43:16And you do that by inverting dependencies.
-
43:16 - 43:17Turn them around.
-
43:17 - 43:19So this is one nice way to do that.
-
43:20 - 43:29Now the control panel is a plug-in to the alarm system.
-
43:29 - 43:32The alarm system doesn't know the control panel exists.
-
43:32 - 43:36The control panel is a plug-in.
-
43:36 - 43:39And the alarm system would accept any kind of plug-in.
-
43:39 - 43:43A lot of different things to do implement this display function here.
-
43:43 - 43:45So we could have a lot of different things that we alarmed.
-
43:53 - 43:55What would rather depend upon?
-
44:02 - 44:05A component that was stable?
-
44:07 - 44:09Or a component that was unstable?
-
44:11 - 44:12Trick questions.
-
44:12 - 44:18Right? Everybody knows that you want to depend on something that's stable.
-
44:23 - 44:25But now let me define stability.
-
44:29 - 44:31Is my laser stable?
-
44:34 - 44:36It's not changing.
-
44:39 - 44:41But is it stable?
-
44:41 - 44:44Stability is not a Boolean.
-
44:44 - 44:46Stability is a continuous variable.
-
44:46 - 44:51And it is defined as the amount of work required to make a change.
-
44:51 - 44:53If it takes a lot of work to make a change, it's stable.
-
44:53 - 44:56If it takes very little work to make a change, it's unstable.
-
44:56 - 45:00That is unstable.
-
45:00 - 45:04Cause it doesn't take much work to make a change to its state.
-
45:04 - 45:09This. Well I won't say that it's stable.
-
45:09 - 45:12Cause it would take much work to upset it.
-
45:12 - 45:15And this whole stage doesn't feel very stable to me.
-
45:16 - 45:19So I may have to be careful about the way I move.
-
45:19 - 45:22So let me ask the question again.
-
45:22 - 45:25What would you rather depend upon?
-
45:25 - 45:27Something easy to change?
-
45:27 - 45:29Or something hard to change?
-
45:29 - 45:33Modify the source code.
-
45:34 - 45:35What would you rather depend upon?
-
45:35 - 45:40A module whose source code was hard to change or a module whose source code was easy to change?
-
45:42 - 45:43Same answer.
-
45:43 - 45:46You wanna depend upon thing that hard to change.
-
45:46 - 45:49And the reason behind that is very simple.
-
45:49 - 45:52Do you mind depending on string?
-
45:52 - 45:53No.
-
45:53 - 45:55Why don't you mind depending on string?
-
45:55 - 45:58Cause if those guys ever change string, they'll be held to pay.
-
46:00 - 46:01They would suffer more than you.
-
46:02 - 46:04That's the equation that we're talking about here.
-
46:04 - 46:06You are happy to do depend upon something,
-
46:07 - 46:12if it will hurt the authors of that thing more to change it than hurts you.
-
46:12 - 46:14That's the equation.
-
46:14 - 46:16You are happy to depend upon things
-
46:16 - 46:19as long as you're not likely to change or at least the bastards gonna pay if they change.
-
46:19 - 46:25So alright, we don't want to depend on things that are easy to change.
-
46:27 - 46:29Think about that very carefully.
-
46:29 - 46:33I don't want to depend on something easy to change.
-
46:35 - 46:40Do we design parts of our system so that they will be easy to change?
-
46:43 - 46:44Yes.
-
46:44 - 46:50What parts of our system do we most want to be easy to change?
-
46:53 - 46:54The GUI.
-
46:57 - 46:58GUIs are volatile.
-
46:58 - 47:02They change for no good reason at all.
-
47:02 - 47:05People will change GUI just because they feel like it.
-
47:05 - 47:08There will be some committee (??) to say,
-
47:08 - 47:10"You know, our system look so old."
-
47:10 - 47:12What the hell does that mean?
-
47:12 - 47:15"Our system look so old, we need to give it a face lift."
-
47:15 - 47:19"Marketing people have decided, we’ve gotta have whole new look and feel."
-
47:19 - 47:21"Not gonna change any behavior."
-
47:21 - 47:23"Just look and feel of the GUI."
-
47:23 - 47:25GUI has to be easy to change.
-
47:25 - 47:29The modules that hold that source code have to be easy to change
-
47:29 - 47:33And that means that none of you modules should depend on the GUI.
-
47:34 - 47:37No source code dependency should land on the GUI.
-
47:38 - 47:42Your components should not have dependencies that land on the GUI.
-
47:42 - 47:45GUI components have to depend upon the application.
-
47:45 - 47:49Application component cannot depend upon the GUI.
-
47:49 - 47:53Otherwise you wind up with the systems that wear the GUIs hard to change.
-
47:53 - 47:57How many of you test your systems?
-
47:57 - 47:58Automated test.
-
47:59 - 48:00Through the GUI.
-
48:03 - 48:04Got a couple of people.
-
48:05 - 48:07You write test code through the GUI.
-
48:07 - 48:11You are depending upon something that supposed to be easy to change.
-
48:11 - 48:13You'll make it hard to change.
-
48:13 - 48:16If you test your system through the GUI.
-
48:16 - 48:19I have a client who have 15,000 tests all go through the GUI.
-
48:19 - 48:21Same client, by the way.
-
48:21 - 48:22Same one went out of the business.
-
48:22 - 48:2615,000 tests through the GUI.
-
48:26 - 48:29He had so many tests he didn't know what they were anymore.
-
48:29 - 48:31He just knew they all had to pass.
-
48:31 - 48:33If somebody touch the GUI
-
48:33 - 48:35a thousand of those test would break.
-
48:35 - 48:37He couldn't find the time to fix them.
-
48:37 - 48:39So he came up with real simple rule.
-
48:39 - 48:41What do you think that rule was?
-
48:41 - 48:44No body touches the GUI.
-
48:44 - 48:47They made the GUI hard to change.
-
48:48 - 48:52The other thing of course could happened there is that you could lose your tests.
-
48:53 - 48:58You spend a man year putting together nice automated test suite that go through the GUI.
-
48:58 - 49:02And then somebody decides, "We need a face lift on our site."
-
49:02 - 49:04"Pull all out the old GUI and put a brand new GUI"
-
49:04 - 49:06And all those tests are gone.
-
49:06 - 49:10And you get to rewrite them again, but you've got other systems you gotta test.
-
49:10 - 49:12Don't test through the GUI.
-
49:12 - 49:14Don't do anything through the GUI.
-
49:14 - 49:19All dependencies point away from the GUI.
-
49:19 - 49:23What other things do we want to be easy to change?
-
49:23 - 49:26The database.
-
49:26 - 49:28We want the database to be easy to change.
-
49:28 - 49:32We want to be able to make changes to database without rippling through the whole applications.
-
49:34 - 49:38All dependencies you should point away from the database.
-
49:38 - 49:41Put the database in a component with all the dependencies pointing outwards.
-
49:41 - 49:44Put the GUI into a component with all the dependencies pointing outwards.
-
49:46 - 49:54I don't want to depend on anything that is unstable.
-
49:55 - 49:58How can we measure instability?
-
50:02 - 50:04See this guy up here?
-
50:05 - 50:06That component up there?
-
50:07 - 50:09Is he Stable? Or Unstable?
-
50:09 - 50:13He's got lots of incoming dependencies.
-
50:13 - 50:16No outgoing dependencies.
-
50:16 - 50:17He's hard to change.
-
50:17 - 50:20If I make a change to him, it impacts all those guys.
-
50:20 - 50:25So this component here is responsible to those guys.
-
50:25 - 50:29Oh and this component here is independent.
-
50:29 - 50:31It doesn't depend on anybody.
-
50:31 - 50:33It's responsible and independent.
-
50:33 - 50:34I's an adult.
-
50:37 - 50:39Stable. Adult.
-
50:40 - 50:41This guy.
-
50:42 - 50:44He depends on lots of other components.
-
50:45 - 50:47No body depends upon him.
-
50:47 - 50:48Is he responsible?
-
50:48 - 50:50And dependent?
-
50:50 - 50:51He's teenager.
-
50:52 - 50:54And he's unstable.
-
50:54 - 50:58These are the two extreme kinds of components.
-
50:58 - 51:00At the two sides of component spectrum.
-
51:00 - 51:03You've got the adults that highly stable.
-
51:03 - 51:07And you’ve got the teenager who are highly unstable.
-
51:07 - 51:09The unstable ones are easy to change.
-
51:09 - 51:12That's what we wanna put all of our little code.
-
51:12 - 51:15The stable ones are hard to change.
-
51:16 - 51:23We can measure that stability by creating a metric.
-
51:23 - 51:26That metric is a metric that I call "I"
-
51:27 - 51:34'I' is equal to the fan-out. Number of outgoing dependencies.
-
51:34 - 51:37Divided by the fan-in plus the fan-out.
-
51:37 - 51:40And if you think about that for very long.
-
51:40 - 51:44You'll realize that 'I' is a metric that goes from 0 to 1.
-
51:44 - 51:470 being stable. 1 being unstable.
-
51:47 - 51:500 being an adult. 1 being a teenager.
-
51:50 - 51:53It’s all about the dependencies.
-
51:53 - 51:59And now we can re-phrase the principle to say this.
-
52:06 - 52:14Every dependency in a component graph should point at something more stable than it is.
-
52:14 - 52:22Or, if use the metric, these arrow should point in the direction of decreasing 'I'.
-
52:22 - 52:25Decreasing instability. Increasing stability.
-
52:25 - 52:31And you can do the math on just the fan-ins and fan-outs and verify that's correct.
-
52:32 - 52:37Why was the cycle bad idea?
-
52:38 - 52:41Something stable depended on something unstable.
-
52:45 - 52:48But that leaves us with a problem.
-
52:48 - 52:50And the problem is this.
-
52:55 - 52:56What's that guy?
-
52:58 - 52:59Stable? Or unstable?
-
53:01 - 53:03He's really stable.
-
53:03 - 53:05He's sitting down here the bottom of the graph.
-
53:05 - 53:08Everything over here depends on him.
-
53:09 - 53:10He's very hard to change.
-
53:11 - 53:15If I touch that component, all these other components will be affected by.
-
53:15 - 53:18For no other reason than the release number changes.
-
53:24 - 53:29That means the stuffs down here at the bottom of graph is very difficult to work with.
-
53:31 - 53:33But there's an escape to that.
-
53:34 - 53:35Back to polymorphism.
-
53:37 - 53:43How can you make something easy to extend?
-
53:44 - 53:46Even though it's hard to modify.
-
53:49 - 53:50You make it abstract.
-
53:51 - 53:54Abstract classes can be extended trivially.
-
53:55 - 53:57Without having it modified.
-
53:57 - 54:00You can add new features to a system
-
54:00 - 54:06if those new features live inside the derivatives of base classes.
-
54:06 - 54:09So the final principle is this.
-
54:10 - 54:16We would like abstractness to increase as we go down the zeros. (??)
-
54:16 - 54:18Stuff up here concrete.
-
54:19 - 54:20Unstable and concrete.
-
54:20 - 54:23Stuff down here abstract and stable.
-
54:23 - 54:30Abstractness becomes more and more prevalent as we go down this tree.
-
54:32 - 54:39In fact, we could say that abstractness is a number
-
54:39 - 54:46which is the number of abstract classes divided by the total number of classes in a component.
-
54:47 - 54:50And if you did that, you get this number 'A' which goes 0 to 1.
-
54:50 - 54:520 being concrete.
-
54:52 - 54:551 being entirely abstract. Composed of nothing but interfaces.
-
54:55 - 54:59And then we can do this very interesting thing.
-
54:59 - 55:09We can say that for any particular component 'A' plus 'I' should equal 1.
-
55:09 - 55:13Either it's abstract where 'A' is 1.
-
55:13 - 55:16And stable where 'I' is 0.
-
55:16 - 55:20Or it is instable where 'I' is 1.
-
55:20 - 55:21And concrete where 'A' is 0.
-
55:21 - 55:23'A' plus 'I' equals 1.
-
55:23 - 55:27The magic formula of components. 'A' plus 'I' equals 1.
-
55:27 - 55:31Now you've got the adults up here which are abstract
-
55:31 - 55:33And everybody depends upon them. So they are stable.
-
55:33 - 55:36You've got the teenagers down here.
-
55:37 - 55:42Everybody that's got no incoming dependencies but they're very concrete.
-
55:42 - 55:44What do you got here?
-
55:44 - 55:47This is the line 'A' plus 'I' equals 1.
-
55:48 - 55:53This is where we would like our components to sit if they can sit. One of those two end points.
-
55:53 - 55:54Why?
-
55:56 - 55:59Well, what's up here?
-
56:01 - 56:04Highly abstract. Nobody depends upon on it.
-
56:05 - 56:08An interface that nobody implements. Useless.
-
56:09 - 56:11This is the zone of uselessness.
-
56:11 - 56:14We don't want our components going that way.
-
56:14 - 56:16What's down here?
-
56:17 - 56:20Very concrete. Everybody depends upon on it.
-
56:20 - 56:22Database schemas.
-
56:23 - 56:25Concrete. Everybody depends upon them.
-
56:25 - 56:27Fun to change.
-
56:27 - 56:30Right? We don't want things down here.
-
56:30 - 56:31This is the zone of pain.
-
56:32 - 56:36We would like our components to be as far from those 2 points as possible.
-
56:36 - 56:39Ideally if we could get them here and here that would be best.
-
56:39 - 56:42But it turns out the components are persnickety that way.
-
56:42 - 56:45So at least we'd like them to be sitting along this line.
-
56:46 - 56:48Or close to the line.
-
56:49 - 56:51Which leaves us the one last metric.
-
56:53 - 56:54'D'
-
56:54 - 56:57How far away is a component from the line?
-
56:58 - 57:02Well, 'D' could be the absolute value of 'A' plus 'I' minus 1.
-
57:02 - 57:05You can do the math on this. It's not very difficult.
-
57:05 - 57:07'D' is the metric that goes from 0 to 1.
-
57:07 - 57:100 means that right on the line.
-
57:10 - 57:121 means that one of the two bad end points.
-
57:12 - 57:15If you wanna know which end point you can take the absolute value signs off.
-
57:15 - 57:16But I don't care.
-
57:16 - 57:22You can measure 'D' by looking at the fan-in and the fan-out of the component.
-
57:22 - 57:24Measuring its abstractness.
-
57:24 - 57:28Doing the math is not very difficult math to do.
-
57:28 - 57:34And find out whether your component sits nicely on that line.
-
57:34 - 57:40If it does then it is abstract as it is depended upon.
-
57:41 - 57:47If it doesn't that means either it's very abstract and not depended on
-
57:47 - 57:49or very concrete and heavily depended upon.
-
57:49 - 57:50Both of which are very bad ideas.
-
57:51 - 57:55There are lots of tools that automatically calculate these metrics for you.
-
57:55 - 57:59If you ever used NDepend. That will calculate the metrics for you.
-
57:59 - 58:03If you ever used any of the other static analysis tools,
-
58:03 - 58:06they can generate all these metrics. I. D. All of them for you.
-
58:06 - 58:10So that you can look at your components and see if they fit.
-
58:10 - 58:14And then think about what should be easy to change.
-
58:15 - 58:18Things that are easy to change should be in teenagers.
-
58:19 - 58:24Things that are hard to change should be in adults that are abstract.
-
58:24 - 58:28Concrete teenagers hold the stuff that's easy to change.
-
58:28 - 58:32Abstract adults hold the stuff that's hard to change.
-
58:33 - 58:34Any questions?
-
58:36 - 58:40We started with PDP-8 assembly code and got here.
-
58:43 - 58:45Any questions? No?
-
58:45 - 58:46Good.
-
58:47 - 58:48Oh, damn.
-
58:50 - 58:51It's alright. It's okay.
-
58:51 - 58:57(Someone is questioning.)
-
58:57 - 58:57Yep.
-
58:57 - 59:03(Someone is questioning)
-
59:03 - 59:052 versions.
-
59:05 - 59:07(Someone is questioning)
-
59:07 - 59:10Yeah, 2 versions. Same component. You kill the programmers.
-
59:11 - 59:11Yeah.
-
59:12 - 59:15Don't have multiple versions of same component in you system please.
-
59:15 - 59:17That's DLL Hell.
-
59:18 - 59:20Anybody else? Yeah.
-
59:21 - 59:24Where do you place...? Very very good question.
-
59:24 - 59:26String class sits right there.
-
59:27 - 59:32It's in the worst possible place but nobody ever changes it. So we don't care.
-
59:32 - 59:36This is all about the stuff we are actively developing.
-
59:36 - 59:38The stuff that is being changed.
-
59:38 - 59:43So we pay very close attention to the stuff that's in our libraries that are changing.
-
59:43 - 59:46The stuff that we get from other libraries that's not changing.
-
59:46 - 59:49Or the stuff that's in our old libraries that's not changing.
-
59:49 - 59:50We not gonna pay attention to that here.
-
59:51 - 59:52A lot of that stuff may live here.
-
59:52 - 59:53And that's okay.
-
59:53 - 59:55None of it's gonna live here.
-
59:56 - 59:58Well, some of it might.
-
59:58 - 60:00Anybody pull out any dead code?
-
60:00 - 60:02Abstract classes that nobody implements?
-
60:02 - 60:05Yeah, okay. So maybe you see some stuffs there.
-
60:05 - 60:12But String, Vector, a lot of libraries live down here we don't care because they're not volatile.
-
60:12 - 60:16Think of another axis is coming out from this graph, right, towards you.
-
60:16 - 60:18That's the axis of volatility.
-
60:18 - 60:22This is a slice where volatility is close to 1.
-
60:22 - 60:25The stuff where volatility is 0, we don't care about it.
-
60:26 - 60:27Anybody else?
-
60:28 - 60:29Yo! In the back.
- Title:
- Robert C. Martin: Principles of Component Design.
- Description:
-
How do you manage the structure of large agile and object oriented systems? What is the best way to break that structure into components? What should the components contain, and how should they be interrelated? How can we effectively partition a system into independently deployable components? This course teaches the 6 principles of object oriented component design. The first three are principles of component cohesion, which discuss the rules for how classes should be allocated to components. The second three are the principle of component coupling, which discuss how components should be related to one another. Principles include “The Common Closure Principle, the Stable Dependencies Principle, and the Acyclic Dependencies Principle, among others.
- Video Language:
- English
YongWook Kim edited English subtitles for Robert C. Martin: Principles of Component Design. | ||
YongWook Kim edited English subtitles for Robert C. Martin: Principles of Component Design. | ||
YongWook Kim edited English subtitles for Robert C. Martin: Principles of Component Design. | ||
YongWook Kim edited English subtitles for Robert C. Martin: Principles of Component Design. | ||
YongWook Kim edited English subtitles for Robert C. Martin: Principles of Component Design. | ||
YongWook Kim edited English subtitles for Robert C. Martin: Principles of Component Design. | ||
YongWook Kim edited English subtitles for Robert C. Martin: Principles of Component Design. | ||
YongWook Kim edited English subtitles for Robert C. Martin: Principles of Component Design. |