My wife would be I'm very unhappy if I left it somewhere. Okay. All right. We've just made we've just made nine has two factors pass What happens if we do ten? but Can we get another failing test? Does anybody think we can get another failing test? No, I think the algorithm is done Okay, now if I didn't think it was done. I would write more tests Until I was comfortable with and this one's kind of tricky. So I might jump ahead and do a hundred I Might do some more just to make myself feel a little better Okay, but I'm pretty confident that there's the algorithm Can we do anything to that algorithm? Okay, there's the algorithm and there's duplication in here This is the second half of the course is Learning how to spot duplication. So what's our problem? We could do that if we're if performance is our problem This is what we have Just move to the same Yeah, well never gonna be greater than one. It can never be greater than one All right, it can never be so if I leave this code in It just makes that algorithm harder to read This is the kind of stuff that you want to get rid of this is the part that people say, you know You're saying okay, but it's done dead simple This is the part where you think This is where your brain has to work so we're gonna get rid of that line and Go away line and if I run the tests. All right, so make that change quickly Get rid of that line and then we're done We have just done Bob Martin's caught a prime factors caught it I was at Agile 2004 I think it was and I was sitting next to Ken our and Richard Gabriel who knows Richard Gabriel and And not the singer Nobody oh Peter Gabriel Richard Gabriel Richard Gabriel was one of the open-source guys anyway. He became a poet.  It's a little poem that was the poem that got him his PhD in In poetry and he had to write it a thousand times over and over and over and over again So he said Everybody in the room who has programmed something? Twice the same thing twice raise their hand. Let's do that Okay, I was sitting next to Ken our and I got my hand up.  Just keep your hands up for a second. Everybody's who programmed the same thing three times Who that looks good four times? Five times Wow six times seven times eight times nine times And my hand went down about then Ten times this what? Yeah, I actually But I was sitting next to Ken our and about ten everybody else's arm was down in the room including mine and Ken ours was still up and About 2017 Ken ours came hand came down. I went home on the airplane. I wrote hello world a bunch more times Just go so I could leave it up longer the point is We need to practice What we do and if we practice on greatly huge hard problems if we rewrite the same thing We need to practice on a little thing and Bob Martin has put one of these together. It's on the web Just look up Uncle Bob Uncle Bob prime factors. All right and run through this one. He's got another one the bowling the bowling game Highly recommended fun, and it's got a little bit more. It's a little harder than this one All right, that's homework all right, so What happened to my computer I Got the point That's all right. I think yeah, yeah, it's not Your pointing device has to be a direct a line of sight All right, I want to skip I'm gonna skip the exercise what we're doing skip this particular exercise. We'll come back to it. I hope but I want to do is Can't see that far Okay, so the question I get all the time is was John I can't do this and I say why can't you do this? So somebody tell me what we can't test just name something we can't test this just say it We can't test nuclear weapon detonation Okay, that's a good one. What'd you say? Okay, okay, but yeah, but you don't get to talk All right, nobody thinks there's not there's something we can't test Real-time systems, okay, so so the people say John. I can't test it. It's legacy code It looks like that Not possible And that's good legacy code Yeah, so that's what I want to hear those things The one the one I really hear the people that really grumble are they say well legacy code is one of them Because it's too ugly the next one they say is I can't test gooey's I can't test nuclear Nuclear launch launching, okay, it turns out we can you're gonna be up in a sec it turns out we can and Richard is about to show us how the thing is that what's important to be able to test legacy systems because I don't know Who gets to work on clean code or beginning code? From scratch when's the last project you did? Greenfield thank you greenfield All right. Are you working on it now? Were you working on it last year greenfield? Yeah, see that all the hands go down So we don't get to work on greenfield very often when we do we like yes, yes But it guess how long it takes to turn greenfield Untested greenfield code into legacy code So Richard is a little short One month Jim shore says three months Okay, and I'd rather side with Richard on this one, but Jim shore says three months So if you've been on your greenfield Development and haven't been writing tests for three months You've got legacy code Okay, that's that's just the way it is Okay, that's that's the fact legacy code defined by James grinning is any code that's untested and By the time three months goes by there's gonna be enough bricks and rocks falling down in little odd places That you probably you probably wanted yours testing if you go longer than that it's gonna cost you a lot to get those tests in Alright, so what do we do to help our legacy code out? the One of my favorite things is don't be afraid that you want to get inside just get inside Go inside take small steps Okay, and there is a light luckily in the middle of this pyramid. There is a light at the end of that the other thing we want to do is Make sure we get lots of shoring and make sure we get Scaffolding up Okay, lots of it. All right, that's what we do how we deal with legacy code All right, Richard has got And you guys see that good Okay, so what we're looking at here is just a really dumb little application that is an address book I can add an address and This is existing code legacy code This what we're gonna do is we're gonna write a test for the behavior that's on this ad address dialogue You notice that this okay button is disabled Until I type some text in the first name field That's the behavior That we're going to unit test We're gonna write a test that says the okay button should be disabled when the field is empty And it should be enabled when the field has some text in it Because that's the existing behavior that I have on this dialogue I want to write a test to cover the existing behavior Because then we're going to add some new behavior and I want to make sure the new behavior I add does not break the old behavior So that's the application. It's really quite stupid Let's go over here and take a look at the existing code on the form And you see in here there's a handler for the text changed event on that first name text box And he just says yeah got to have non empty text For that okay button to be enabled whenever the text has changed. I'm gonna keep setting that so what we're gonna do is We're gonna move this behavior to another class and the reason we want to do that is because This class is a form And it has controls on it and they all get created whenever this form gets created it by initialized component and Creating the controls involved looking up all these resources and setting all these attributes on the individual controls That means instantiating this class is expensive And we want our unit tests to run fast because we're gonna end up with hundreds and thousands of thousands and thousands of unit tests After we work on this thing for five years, right? We're gonna have all kinds of unit tests. We want them to run fast So that every time we make a change. It's quick to get an answer to that question of did I break something? So we're gonna make a new class What I'm gonna follow is something called the mediator pattern a mediator class It's just a class that coordinates the interaction of other objects So I'm gonna add a class called add address form mediator Okay, got that class That's fine. I'm gonna add a test project to my solution oops add new project It's going to be a C-sharp class library and I'm gonna call it test add Test address book So all I'm doing so far is just getting like my test this this is legacy code It doesn't have any tests on it, right? So I'm just getting my test framework set up That makes a time made a Project to hold my tests. You always want to keep your test code separate from your production code So that your production code doesn't ever accidentally become dependent on your tests because you're not gonna ship your tests You're gonna ship your production code only So on my test project here I'm gonna add a reference to the end unit framework so I can use it to write my tests and The first time add reference runs always takes a while isn't DC-sharp guys, I'm sure you know you can't see it but my hard drive lights on solid here. We go and unit framework Okay, I don't need this data and XML link stuff We're not gonna be doing any of that. I'm gonna call this class test add address form mediator You name your class your test classes and your test files anything you want. I like to Make it obvious what I'm trying to test Just from the name so this thing is going to be a test fixture because it's going to be a class that holds tests These little pop-up boxes you're seeing are coming from a sharper which is helping me fill in stuff and The first test I like to write for a new class I like to call it construct and it basically is my one-stop shop for finding out how to make an instance of this class So I'm gonna say add address form mediator and do oops This class needs to be public so I can see it from my test and I need to reference Added my I needed to add a reference to my production code. So I added that made my test code refer to my production code and Imported its name space and I'm just going to say Assert that is not null mediator And this little message I'm writing is just for me now you notice. I didn't say new class name. I said That get instance The reason I do that is I like to do what's called encapsulating construction on the classes that I write hide the constructor You might say why do you why do you bother to do that? Well, I do that so that if suppose at some later date This guy needs to be a singleton and everybody needs to use the same exact instance or Suppose I need to do some kind of special thing every time one of these objects is created But the callers that are getting these instances don't need to know about that So by decoupling myself from the direct use of the constructor I'm able to localize any of those decisions right here inside this Something I encounter often is sometimes you do what you call to phase initialization Where there's certain things that don't work right if you do it try to do it from the constructor But it will work if you do it on any other method. So I'll do the constructor and then do the The second phase initialization inside here. So again, I encapsulated that inside this method all the guys that are using this class Don't need to know about that So let's go back to look at our test. I've got a test here that says how to make an instance I Can build this code Build succeeded and go over here to end unit. I'll load up My test framework my test assembly so that's a test bin debug. Here's my test assembly loads that up I've got one test here. I run that test My test is green now. I kind of cheated because I went off and I implemented the Implemented this get instance right as I was writing it because I knew I'm kind of doing that I know exactly what I want some kind of stiffness skipping a step. I didn't quite strictly speaking have a red test So now I've got this mediator What I want to do is I want to start moving this behavior from this form Off on to the mediator. So I know I know that the form is gonna need a mediator because that's where all the work Is gonna happen and this is the behavior that I want to move so instead of doing that I'm gonna say mediator first name text changed now This is the thing that I want to have You know Implement the behavior on you know, that's gonna interact with my form. So I'm gonna have to stub that out And I'm gonna say not implemented exception because what I want to do keep that around What I want to do is write a test That says what that first name change should do so the test is Okay enabled when first Name not empty. So I say mediator dot I have to make a mediator mediator dot first Name text change. That's the production code that I want to call and now I need to assert something here. I need to say You know it is true that on a on the form that the okay Enabled property was set And I want to say that not only was it set But the last value it was set to was true now. I don't have a form yet. So how am I gonna? How am I gonna do that? Let's have the mediator talk to the form through an interface So I'm just gonna make an interface. I Don't know how I'm gonna get one yet. I don't even know what this interface is, but I know it's gonna be Something that our real form will have to implement So I know this Kind of getting what let's let's do this I'm going to The mediator is gonna have to talk to the form. So let's get that Adjusted here. So we know that this mediator is gonna have to collaborate with the form Which is where all the controls live because he is gonna orchestrate the interaction between the controls so what we're gonna do is have an interface that Handles all those interactions for the mediator now in my test I've got I'm I've got it written here that you know I've got this interface and then I've got some things down here that I want to know for my test But these are not things that I want to expose in my production code So really what I want in my test is I want some kind of stand-in for the real form because remember the whole Reason we're moving this to another class in the first place is I don't want to instantiate that real form Because it's a heavyweight. So I'm gonna make a fake form For this fake form. It's gonna have to be a class It's gonna have to implement the interface that the production form uses which we don't know what that interface is yet We're gonna do this encapsulation stuff on it just like we did before These are the things we want to know about how the mediator interacted with the form So we know that these have to be properties on our fake. They're things that are fake is gonna tell us We don't know what they're gonna. We don't know what they're gonna do yet But these are the things that we want to know In our test. Okay, so at this point Resharper is telling me hey, you didn't give me a form up here. Okay fine. I'll do the simplest thing to get that test to compile and Over here, I'm gonna do the simplest thing just to get him to compile oops Okay, so our build succeeded. We've got a failing test Okay, we've got a failing test because our stand-in form doesn't really do anything except Throw not implemented exceptions yet So let's see if we can Do a little something on here we know that What we really wanted to have happen over here If we go back and look at our production code that we're trying to get covered by tests. This was the old This was the old behavior right here is that he was Setting the enabled property of the okay button and he was reading the text property of the first name text box control So those are good candidates for what we need to have on this interface for our fake and our production form so Let's go over here to Our mediator, let's take this interface and we're gonna say Public bool Okay enabled and he's gonna have a setter Because that's all we need Oh, it's an interface. It's only public and he's going to access The first name text at with a getter So I so based on our existing production code These are the kinds of interactions that the mediator needs to have with the form so Let's take this. I'll just move that off to its own File, okay, so we have the form interface. We have the mediator and We know that the production form has to Implement that interface and we know that This mediator needs to talk back to the real form. So when we construct the mediator, we're going to use the Production implementation of this interface I'll stub out the implementation of the interface right now I'm just going to leave these With not implemented and we'll come back to them in a minute because we're going to we're focusing on the mediator first But I want this all this code to compile so I'm going to come back over here to the mediator and This was The production code that we had and then his first name text changed We're just going to steal that Implementation by pasting it in and then saying well instead of accessing the enabled property on that control directly Now I'm accessing that same thing through the form and ditto for the first name text So now I've moved that production code from the dialogue where it was sitting directly in the event handler I've moved it over here to the mediator The mediator is interacting with those controls through an interface and the reason we want To do that extra level of indirection is so that when we write our tests we can write a fake That stands in for the real form and he's going to say oh, yeah My first name text is empty and my okay button is not been set yet And he's going to he's going to record the interaction of the mediator with the controls in the test scenario So if we come back here and look at our test We should now have We have our fake form. He doesn't yet Oh, he's not implementing the members of the interface yet So now we'll put the implementation on the fake. What does the fake want to do? The fake wants to do two things. He wants to remember all the things that were done to him So that you can in your test you can write assertions and say when I talked to them I told the mediator to do something did he interact with the fake form in the right way did he do the things to the fake form that he was supposed to do and and Did so that's the one thing you want to remember what you do to the fake form so in this case we want to remember that we called the Setter on the okay enabled property you want to remember the last value that was set on it so I'm going to make some backing store for these and then my Accessors that I had written had stubbed out are going to now return those values We also want to remember The same thing for the first name text Except in this case. It's a getter.  I'm just going to return To make my first test pass. I'm just going to return a string a fixed string and I'm going to put a getter on that property to follow any conventions So up here we learned that based on the remember we're writing a covering test here We're not writing a test for new functionality. We're writing a test to try to cover the behavior of existing functionality And so it's okay to cheat When writing the test and look at this and say this is the production behavior I want to call or I want to cover there's two things that happened here. It did a set property on one Part of the form and it did a get property on the other part of the form So I want to make sure that those things Are validated in my test Because we so we did a Assertion on the part that did the right now. Let's do an assertion on the part that did the read So we asserted that we did the read What we Have configured this fake form to do is that whenever it's asked for the first name. It's always going to return this fixed string So now we should have a Passing test that covers one test case One test scenario for this existing production code there's Another the other test case that's in here. Can anybody tell me what that is? See if you're asleep. Come on. It's easy. There's only two things that can happen, right? The button is either enabled or disabled So what's the other test case is when we're going to say? Okay disabled when first name empty so we can it's very similar to this case so we can start out with this So let's see we know that The okay enabled set should have happened just like before except this time the last value should have been false Instead of true and we know that we should have gotten the value at the first name text So let's go ahead and compile this The build succeeded we'll go ahead and run the tests Okay, that one fails Now it fails because on my fake form it always returns Richard whenever I ask for the first name So what I need to do is enhance my fake a little bit so that I can say don't just return the same thing every time but I want you to On this test So this is the okay enabled when the first name not empty So I want to say form your first name text fake result Get fake result is Richard Yeah, I don't have that on my fake yet. So we'll go off and put that over there and the setter is going to say First name text get fake result value Go ahead and make a backing store for that And come back down here instead of returning this fixed string We will return first name text get fake result Now I've added that configuration here Does anybody think this second test that I've written is going to pass now? He says my code's not going to compile, but I don't need a getter on that Okay, now do you think my test is going to pass he says yes. He says no My test does not pass because that backing field was not initialized And I'm take trying to access the length property of an empty or of not an empty string, but of a null Value so we'll go back over here to our test and we say yeah, you know now I'm being really explicit about the state of this form before I try to exercise Production code that interacts with the form now. I'm saying You know in this case I said hey the name has to be empty for this test Well, that's what I said right here as I said the first name text get fake result is an empty string So now when I compile this go back over here now rerun my tests and What did I do wrong? Ah? I did not change my assertion because I copy pasted the What did I do here? It should have been set to all you have set to okay enable set call You mean in the implementation of this yeah, you're right look see kind of bug in my face Sometimes Automatic completion is a blessing and sometimes it's a curse Okay, now our tests are great. So we've covered The two Simplistic, but we've covered all the two different possible behaviors of that dialogue So are there Any questions on this before we go and add some new behavior to this dialogue by putting wiring it up through the mediator? Earlier versions of this presentation. I had a lot more behavior on the dialogue And we just found it was just too much work to get through in the in the time available So let's say let's go back and look at our Design view of this address form here, and we're saying hey, you know It's it's nice that this okay button is disabled when the required first name text is missing But it's an extremely subtle hint to the user So what we'd really like to do also is we'd like to enhance this dialogue so that the fields that require input are labeled with Red text and not just ordinary text So that's what we're going to go and try and implement test-driven style So we've covered all the existing behavior of this production dialogue with our existing tests and We're going to add some new behavior here Does anybody see some? Duplication here that we might be able to get rid of between these two tests. Okay, so Looks like we do this thing And we do this thing Every time in both these tests so while we're green we can take advantage of this time We also do it up here, although we pass in a null for this for the form So we've got some duplication between all three of these tests we can while we're green we can refactor that out into a Setup method Or what I'm going to do is I'm going to say yeah split that Declaration so I can take the declaration and put it up here and make it a member And let's do the same for this one And take that out put it up here and make it a member and then We're know we're going to need one of these forms let's move that to the common setup We know we're going to need One of these mediators put that in the common setup The mediators taking a form So I've moved that out of one of my tests I'm just leaving the other tests alone for now My build succeeded run my tests again. We're all still green. So that's good I didn't break any of my tests by this change now what I can do is I can say I Don't need to create this mediator here because It's going to make one in the common test setup and from my third test case I can say yeah, I don't need to make a form and I don't need to make a mediator Those are happening in my common test setup my build succeeded go back here run my tests again My tests are all green now if I was using a source code control system That would be a great time to commit changes and lock in positive games, right? So now we eliminated some duplication by just doing a little refactoring phase on our test code Let's go write the test for our new situation. We want to say Now when I first make When I first construct this form The first name field is empty. So as soon as I make the mediator Which is created at the same time as the form is created he should immediately say What's the first name text? Oh, it's empty your label should be read so I Was thinking I might need a new test case But it turns out because it happens as soon as the mediator is constructed because it's tied to the lifetime of the form I Could just add more assertions that say when you construct one of these This is something that should happen every time it's constructed because it's Lifetime and the form's lifetime are intimately tied together. So I can say on here It is true that on my fake form you should have Set the color of the first name label It's also true that The color it's set it to should have been read. I'm gonna need to add system dot drawing so I can talk about colors First name label color set last value Okay, I don't my fake doesn't know anything about these yet Let's go ahead and stub those out on my fake.  I don't need to do that in encapsulation behind a property I'll just make the field directly on the fake We could do we'll just do one that way Yes, it's a system dot drawing color. So in that case, I just made it a public field on my fake I like to do the encapsulation with resharper. It's not significantly longer, but you can do it either way So, hey, that's fine. That's what our test says, right? Should these things should have happened Code built. Okay. Let's see what happens now Well now our construct test is failing because we haven't done anything on the production side to make this actually happen yet now What I've done is I've said, yeah, I need to know these things about my fake form But I haven't defined anything yet on the interface for the form that the mediator is going to use and then when we try to Go and make this Pass by adding an implementation over here. That's when we're going to find out Yeah, um, hey on the form the If the first name text length is greater than zero Then I don't need to do anything if it's Equal to zero. I want to say form that first name label color is color dot red And I want to use system drawing that color now he's saying yeah, but I'm only talking to the form through the interface The interface doesn't have anything that lets me set the color yet. So go ahead and put that over on the interface Because I've changed the interface The fake form and the production form now need to be updated to implement the new member So if I go over here to the fake form first I'd say implement the member Yeah, we strictly speaking we can go back here. We don't need to get on this. We can just do a set So then he says You're trying to set my color Let me remember that Last value Remember that too. Okay, so that's my fake and Remember we have two objects implementing the same interface and we just added a new member on the interface So we have to go back to all the objects that implement that interface and on the form We have to implement that now Over here. We haven't really implemented anything yet. I'm just going to leave that as Not implemented exception for right now Because you just want to test the behavior on our mediator first Okay, now everything's red So what happened? what happened was that on our fake form if I think this is what happened take a look at our test our test said We should have set the first name label color and That it should have been set to red So look at the mediator. He says We should have gotten the first name text and that we should have Set the label color if the text length was empty so Down here I have object not set to an Instance since I managed to confuse myself. Let's just go back here But it happened on all three tests So it must be this part that's causing the problem. That's the last change.  Our construct test is still red So my form must be No For my first name text must be no on my form Which it is on my fake So We changed the behavior Let's go back every look at our test. We changed the behavior of what happens when we construct a mediator, but Right here the mediator gets constructed the form was created But the fake form didn't have his first name text fake results set up to anything So what happened was that was null and then the constructor immediately tried to access that That caused our test to fail So now we'll go back here and look at this Okay, now our test is passing Okay, now we've made we've put the behavior over on the mediator We've made new behavior on the mediator But the last thing that we were missing was this Production implementation of our interface Now due to the way that we Put things on the interface. We said, oh, it's the okay enabled property. So I'm pretty sure that means okay button got enabled That's the production implementation of the interface Over here on this getter That's the implementation of that and This is first I have to go briefly over here to my designer and implement or generate a member for this label so we can talk to it through code So I had generate members at the false I change that to true So now I can say first name label that for color is Value Okay, now we don't have tests Directly covering this class this production code, right? We put all the behavior on another class and that's what we're unit testing so Making sure that you've got this stuff wired up properly Still requires manual testing But When we look at the code We just look at that and we say yeah, that's just correct by inspection. There's no branching There's no looping. There's no checking. There's no nothing. It's just yeah Take that thing and shove it on there or take this thing from here and give it back So when we look at this implementation of the production interface We say yeah, I can look at that and I don't feel that that's where the bug is as long as there's no Not implemented crap right as long as we implemented the whole interface Because these properties were really simple. They're just bully in the string. I just look at that and I think yeah That that's good. So now I Have my unit tests on my that covered my new behavior that I wanted to add now Let's just go and make sure that it's really on the form. Okay, so here's our main window And when I click out over here the labels red. It's red Because I didn't type anything Now it's red when it's it's set to red in the constructor. We covered one case But we still have more behavior that we would want to cover because we want to say yeah It shouldn't be red anymore as soon as I satisfy the constraint, right? So if we have time I Can go ready to test to that? We have time Well, it should take a few minutes Let's try it. Let's see how long it's going to take us to do that so back over here Go back down to our test and we want to say Well, we can enhance our existing test. That's just right any test We could have enhanced an existing test we can say The first name label not red when not empty I'm not really saying what color it should be. I'm just saying it's not red So I'm gonna say form That first name that fake result So it's not empty And say that you know that should have trigged whenever the the text has changed It should fire the first name text changed event and then we're gonna say assert that is true that on the form First name label color set was called and it shouldn't have been red. Okay, that's my test build Run my tests. My test is red.  Let's just say we'll add a getter on the interface Add a member to remember this original color, whatever it was. We're not saying what the color should be We're just saying whatever it is originally and now I have to go back over here to my production form and implement the new getter So down here. I didn't have a getter before now. I need one. I'm not gonna take that.  That was pretty cool. I didn't think I could get it done in three minutes, but Yeah, I did a similar Version of this presentation to dotnet user group meeting and I was going to submit the More elaborate behavior plus test version to their site. So John we can put a link to that on the wiki when I have it uploaded on their site Or we can upload another copy on your site, too. Yeah, the link would be perfect Well, it'll be no there'll be no the application Yeah, it might take them a while to get it up on their site, but we'll see Which ever is faster, we'll get it to you Sorry, what what are those sites? The dotnet user group meeting has a user group has a site. You just Google for that I don't know what use is on your head on your handout We'll get you and You'll have to copy your all because I did not make enough copies I was just wondering what is their point where it's where you wouldn't want to use unit tests in place of someone like Using UI a user interface automation They're so not the framework or it takes advantage of the accessibility interface and and you pretty much much fast Which is your going to detect states of the buttons and the text box It doesn't suffer colors. It's lose there But the hidden subtext under your question is does Microsoft really understand unit testing and I have to come to conclusion not really well, but the reason I say that is because the I Believe the framework you're talking about works through like event recording and event playback and You can make tests that way the problem is as soon as you go and change your UI all the tests break And they break for stupid reasons like you moved to control from the left to the right and now the mouse click at that XY position I don't think it deals with the XY location of the button as much as just the physical button It's also if the name of the button changes it breaks, but not so much location change Okay, but that's that's another good example of a fragile test, right? Why should I look at you would change but if I but see if I rename Using a renaming tool. It's gonna rename all the names in my in my tests, too I mean I could go right in here with resharp or do rename on one of those things members of the interface and a Rename it in my production code and in all my tests, and it would just recompile and still work Whereas if I I mean if I In this code if I go into the forms designer, and I change the name of a control as Long as the name of the control the rename gets reflected in that event handler and in the implementation of the interface Nothing else needs to care that my control name changed I mean, I'm not familiar with that framework, but I might as day that's Codeplex it has a whole testing suite kind of built around it But you can build the test suite right in right in as a separate projects You might be able to take take advantage of those renames as well.   You can unit test gooey okay, so As far as that specific framework goes I'd have to look more closely into it But I would not recommend trying to do unit testing gooey By doing event recording an event playback unless the gooey is stable like it's you know We're just trying to get regression tests on this code, and we're not going to change this gooey And it's been the same for five years Then it's okay Because you're not changing it, but as soon as you change it all the event playback stuff breaks any other any other questions Okay, so we've had a chance We've had a chance to code on at each one of your table You know the person who was getting done fast So that is your driver So look at your table look at the guy that was getting done fastest at your table make him the driver All right, and then I don't care who the other roles are you've got make sure you pick up those roles All right, the learning is going to come from the conversation that you have between Hot Rod Hindley and the arm okay the old man and young that's where your learning is going to come We're about to do a little project, and I want it to go fast That's why I want the fastest coder at your table to take it So pick him who's your fastest coder point to him that table's only got two There's gonna somebody needs to go help that somebody needs to go be help that table Oh, they did with a pearl guy over there left So we need at least four there's there's two four We can send one more person back there to make to commentate with them, and that'll be good So fastest program right this table Who do we pick okay perfect who's doing this one here? Okay excellent, and then we're gonna have Doug if you want to be if you want to be the the baby That'd be perfect All right, so the exercise that we're gonna do Again a very simple one. We want a password validator now what a password validator in my goofy world means We accept a string and return return the input string if it is a valid password otherwise return null Okay, all right, so what I want to hear is I Want to hear I want to see the typing I want to see the pair And then I want to see somebody standing behind them talking to each other they get up behind him and talk Yeah, and talk and don't forget we're doing this test first so the comedy there just starts got to start talking who's the commentator Okay, so that makes you to the question tater. Yeah, so just talk talk talk and listen to those questions Yeah, play by play answer their questions try to maybe poke them Maybe they can be the color commentating occasionally You don't have a hot rod does it ignores boomer pretty much Okay, that's all the time you got We're shipping hands hands off the computer. We're shipping what we've got Yeah, this is arbitrary standard so So yeah would QA we don't have one of those We just laid them off if we don't get this release out right now We are companies going out of business and you guys should be working for free All right, so what are we shipping table table number one? What are we shipping? Do we isn't even working right now? Okay, so what do you got? All right, perfect. That's good. I like that table of you guys The first one so we're gonna ship Okay, how about you guys does it does it comply so it doesn't compile at all So it throws an exception is it gonna crash when they try to when they try to do the username and password or not We won't crash. That's good. That at least we won't get that Okay, everybody. Okay, so we can actually ship that Eight characters we got eight characters.  Thank you All right, so all right, so I've got I know All right, so that was our first that was our first release Now that you've got it out to customers. We are gonna do the next one A password recommender so what a password recommender is gonna be am I going the right way? Okay, so if the password is invalid return a suggestion and you got and You've got five minutes go So yeah, if you send a bad data Fail, but but it's trapped so the Let me let me answer that a little bit later because I want to stop this right now. Okay time That's it your time's up All right Hands off the keyboard over in that corner Okay, so We didn't quite get the exercise the refactoring exercise that I wanted to get to but we got the What I wanted to show you there is how many times did we have working code broken code working code? Is your code working right now? No, it's not if you hit controls the like three times would it be working? Yeah, see that that how about you guys is it working right now? Okay, how about that Okay, tell me what it so it compiles. Okay last time we had it last time I didn't let anybody through Okay, all right. How about this this team It compiles. Okay, and your team the what? It'll work. Okay. All right, so We had two tables We had two tables that actually were within three control Z to working back to working Okay, we could have actually shipped that we had a couple of tables that really we're going out of business Actually, we had three tables that were going out of business with and two that we actually stay in business with all right This is part of why I do test-giving development My code works within three or four undoes Okay, something can ship and something going to ship without bugs But you don't need a long extended QA cycle if you attended a case session she told my story and A year we ended up spent we locked the code down for two weeks and in that two weeks we did What are we doing that two weeks? Testing and performance testing and performance in the two weeks before we released The bugs just were fixed as we went we could have released three months earlier I mean the reason we landed on the date we said we would because we could have gone three months earlier just cut features We delivered features We delivered working features and we were within three control heat and if we're using source control We just pull the stack off the top and could hand it to them and that's going to work It's not going to bug in it. It might not have all the features It might have a half implemented feature, but it's not going to have bugs So two teams two teams survived out of and then three teams Who are the companies got out of business all right finally?  Yeah, everybody that guy's Ward Cunningham. He invented the wiki Fitness he invented pair programming he invented all right. I tell you I have to tell you I have to tell you about that guy because he does not publish enough for himself He's not busy out promoting himself He's the guy that you sit down and talk to if you ever get a chance and he's brilliant You know who this guy is Somebody tell me that's Kent Beck He's the one that coined test-driven development. He's the one that wrote it up him and Ward Cunningham paired together All right, the reason I put this guy up there. That's Michael feathers He wrote legacy code You really he really can if you read the legacy code book some of the stuff Richard showed you How to do if you've got legacy code get his book learn those patterns Because if you want to do test-driven development you need to turn your legacy code into tested code And he tells you how to working effectively with legacy code the name of the book All right You guys know who that is That is Bob Martin Martin, Uncle Bob Martin He's the one that we did the first caught it. He did that caught of the prime factors and Solid clean code. He's got the book clean code. He's got the solid principles. He's worth reading All right, I've got one more thing so the name of this thing was try test-driven development and You in this class in a really short amount of time you've gone through multiple cycles of this All right, my goal for you is when you leave here you try test-driven development again and again And you can do it You've seen it I've shown you I've shown you I mean rich what Richard what Richard showed you Is some of the tough stuff What You know what when we went through the rhythm it's some of it's easy and some of it's harder There are some things you need to learn. That's on the sheet of paper if we got those out There's not enough copies There is not enough copies for everybody So you're gonna have to fight over them and at the bottom I'm giving one for cable at the bottom of At the bottom of the is a URL and that's been updated since I printed this copy out So for C sharp it's more current. So you need to go to the URL anyway, so I would write it down I am yeah, so I got more copies Okay, the one got another one the the thing you want is the really the URL on the bottom You've been absolutely fantastic class It's And I've got one more It was really fun. I've never I have not given Richard that three minutes So I really appreciate Richard doing that thing and we and as much pressure as we put on Jeff During his code that was really cool and then your experience. I mean it was it was amazing I did this for the C sharp music group and It just like was it took an hour to get through that at first exercise We managed to cut this one way down so you guys were awesome All right. Good luck


This program is brought to you by Cable Franchise V's and generous donations from viewers like you Hello, and welcome to the Amherst Weekly Report Amherst Media's weekly news roundup I'm Faith Gregory and these are the biggest news stories out of Amherst, Massachusetts This past week we saw three nearby colleges reverse their previous reopening plans for the fall 2020 semester The University of Massachusetts Amherst Smith College and Mount Holyoke College have all significantly reduced the number of students They will allow back on campus Smith College announced on Wednesday August 6th that it would have no in-person classes The University of Massachusetts Amherst announced its revised plan on Thursday August 7th through a letter Chancellor Sipaswamy released to the campus community In the letter he said that this decision was made in response to the worsening conditions of the COVID-19 Pandemic nationally and that while the prior instructional plan will remain the same The University will no longer offer on-campus housing for students whose coursework is entirely remote UMass stated in its reasoning that as of July 30th six UMass students who lived on campus tested positive for the novel coronavirus Mount Holyoke announced its decision to not bring back students in the fall shortly after UMass and Said that students currently living at Mount Holyoke who can't return home or students who cannot perform academically at home are welcome to stay on campus Universities aren't the only schools moving their facilities online this week The Northampton School Committee decided Thursday August 6th that the Northampton Public Schools will take place remotely this fall until at least November 4th The Amherst-Pellum and Amherst Regional School Committees decided on the same night that the Amherst-Pellum Regional Schools will also go remote until Mid-November in a phasing method called Model 4 where select groups of students will be educated in person and everyone else will learn remotely Here's what they had to say about the Model 4 method from my perspective in our perspective out of the four that are there phasing Model 4 would be The preference for a lot of the reasons that you heard from me and from Mr. Siddique earlier just Seems like it makes sense Logistically it makes sense. I know it holds out secondary kids a little longer than some people Might want but I think I think just it If we focus on a small group at the beginning and particularly the groups that have the Least access to distance learning. I think that's in our best interest And I think you know, I know some people think it's too aggressive some people do it's conservative But you know for our perspective, I think that's where if we land there That seems like the best approach from my personal perspective Springfield Public Schools will go the same route following a Springfield School Committee decision on the same day to move schools to virtual facilities Many of the universities and school committee cited a rise of COVID-19 cases across the state This is a trend that has been visible in Amherst and nearby towns According to the weekly COVID-19 health report for Massachusetts for August 12th Northampton and Amherst reported a combined number of 30 positive cases in two weeks prior Charlie Baker held a briefing on Tuesday August 11th regarding the COVID-19 uptick in Massachusetts Baker released a colored coded map of Massachusetts showing the severity of COVID cases in each individual town The map will be updated regularly as COVID risks fluctuate in different communities Here's what Baker had to say regarding the new mapping process for COVID cases in Massachusetts Rad obviously indicates Municipalities that have more than eight cases of COVID per hundred thousand people And this is based on a national and global public health standard. That's extremely high risk for COVID infection yellow indicates municipalities between four and eight cases per hundred thousand people or a moderate level of risk and Depending on the community there could be areas where trends are moving in the wrong direction Although in about half of these communities. We've seen downward trends for the past two or four weeks green indicates municipalities with less than four cases per hundred thousand and White indicates less than five total cases of COVID-19 reported in the most recent 14 day period The lowest number of cases here in the Commonwealth Regarding reopening Baker said quote we can continue to reopen Massachusetts get back to something like the new normal But only if everyone continues to bring their fight to this virus Next the University of Massachusetts Amherst has opted to cancel the 2020 mass football season as of Tuesday august 11th The announcement came in the form of a press release Athletic director Brian Bamford said the continuing challenges surrounding the COVID-19 pandemic posed too great a risk And that attempting to play a season would not have placed the members of their program in the safest situation possible In other news an informal house session of the Massachusetts house of representatives took place on Monday august 10th And referred a petition establishing a moratorium on the mcast test to the committee on joint rules reported and rule suspended And to the committee on education This petition is presented by james hawkins a democrat and representative from adalboro, Massachusetts More locally the Amherst town council also met on monday august 10th in a special meeting The town council revisited the issue of polling locations for the september 1st state primary election and november 3rd federal election At a previous meeting the town council approved a plan to consolidate the seven polling stations into one located at the Amherst regional high school gym Monday they passed a motion to reconsider their decision to relocate in-person voting for all town precincts at Amherst pelham regional high school After moving to reconsider the vote they brought up a motion to move three polling stations precincts 2 4 and 10 To Amherst pelham regional high school leaving all other precincts in their previous voting locations In state politics the Amherst democratic town committee is hosting a virtual candidates night with ed markey Jim McGovern and joe kennedy the 3rd on sunday august 16th at 7 p.m The candidates night is advertised on the Amherst democratic town committee's facebook and will be held over zoom Finally a new petition has appeared on the website care two petitions demanding for reparations for Amherst, massachusetts The petition which is sponsored by michelle miller of district one and corine andrews and matthew andrews of district two Formally request the town of amherst partnership to end structural racism and achieve racial equity and to establish a funding source devoted to local reparations The petition calls out the 80 000 set aside from the town budget for investment to identify and dismantle institutional racism As well as the formation of a human rights commission and the adoption of a human rights policy Saying that while they are confident these measures are making an impact. There is more work to be done The petition specifies what we're asking for is the town's sincere partnership in confronting the legacy and current manifestations of structural racism here in amherst That's all the news for this week. Thank you for tuning in to the amherst weekly report I'm faith greggery and we hope to see you again at the same time next week


Do you ever feel like you're just going through the motions, losing sight of what really matters in life? It's a common experience, but one that can leave you feeling unfulfilled and disconnected from yourself and others. That's why it's important to take a step back and remind yourself of what truly matters. It might be the people you love, your passions and hobbies, or the simple pleasures that bring you joy. When you focus on what truly matters, you can cultivate a greater sense of purpose and fulfillment in your life. You can prioritize the things that bring you the most happiness and meaning and let go of the things that don't. So take a moment to reflect on what truly matters to you. What brings you joy and fulfillment? What values do you hold dear? By keeping these things at the forefront of your mind, you can live more intentionally and with greater satisfaction. And now I'd like to ask you, what is one thing that truly matters to you?


If you've clicked on this video, there's most likely a friend or two in your life that you're wondering about. Maybe you're worried they may be toxic, but you're not 100% sure. It can be challenging to navigate the fine line between giving someone the benefit of the doubt and recognizing when it poses a genuine threat to your mental health. This is why we want to give you six warning signs of a toxic relationship. Before we begin, we want to disclose that toxic and abusive friendships are two different things. If you believe your friendship has become abusive in any way, it's time to make an exit plan as soon as possible. Urge the psychologist Afshan Mohamed Ali. Just kidding. Real friends are your forever cheerleaders. They want to build you up and make you feel good about yourself. Toxic friends, however, tease and insult you on the regular. They may tell you they're just kidding, but if they don't change their behavior when they learn it hurts your feelings, it's a friendship red flag. One at all. There's a difference between being super close to your BFF and feeling like they're trying to glue themselves to you. A toxic friend can be someone who wants all of your attention all of the time. These friends call you and text you without a break and require you to always respond immediately. If you try to pull away from a friend like this, they can even create fake crises to obtain your urgent support, explains therapist Nicole Arst. Conditions attached. According to psychologist Dr. Carlson, a friendship that is conditional, which means that it's based on you doing certain things, wearing certain things or being a certain way, can be destructive. Cue the infamous line from Mean Girls. You can't sit with us unless you wear pink. Toxic friendships have this way of making you question yourself and compromise who you are to fit in. Immediately selected. You know the movie where it's the main character's first day at their new school and the villain picks them out of the crowd and befriends them immediately, telling them everything they'll want to hear. Because they're on a mission to befriend them quickly. Because they have ulterior motives of their own. Someone who latches on to you and tries to become your BFF with urgency is a red flag. Explains counselor Suzanne Deckey's white. Tread lightly as they might think you'll be able to get them a job, connection, invitation, or entry to something they couldn't get on their own. Healthy friendships feel organic, whereas something forced could be toxic. A game to be won. Be wary of the friend who makes snarky comments when you share your accomplishments or good news. It's a psychotherapist Courtney Glashow. Ever notice that your friend is happiest when they feel on top? You can be satisfied but never as happy as them. You can get a good grade, but it has to be lower than theirs. Would you be scared to tell them if you got your dream job? Real friends are thrilled about your happiness and success. That doesn't mean they won't ever get jealous. They're only human. But even if they're jealous, they're still genuinely happy for you. To know if there's hope for your friendship, your friends should demonstrate that they're open to discussing how to make things better and genuinely change, says forensic neuropsychologist Dr. Judy Ho. But if your friend blames you for their behavior or is defensive, it may be time to start distancing yourself from them. Friendship breakups can be devastating, but sometimes necessary. Plus, chances are you've yet to meet all of your friends that you'll have in this lifetime, which can be a comforting thought. Can you relate to this video? If so, let us know below. And if it might help someone else, please share it with them.


Then we will talk about the types of monopoly. The first one is natural monopoly. It is formed when the size of the market is so small that it can accommodate only one player. Means the capacity of the market or the size of the market is so small that it can only accommodate one player. Then we have local and regional monopoly, a monopoly that exists in the limited geographic area like whether it is through regulation like if you take under the this WTO rules or similarly maybe you can take another example like that local grocery store because that serve as a local monopoly because there is no other shops available in that particular region. Similarly, this regional monopoly is generally if you look at the strips agreement or the WTO agreement that leads to the regional monopoly because there is a restriction for the other firms to enter into the market. Then we have economic monopoly and economic monopoly is created whenever the competition is eliminated due to economic efficiency of other players or due to superior efficiency of a particular player. So, it is created whenever competition is eliminated due to economic efficiency of other players or due to superior efficiency of the particular player. So, maybe the efficiency is that one firm is doing really well that leads to the economic efficiency and that stops the other firms to enter into the market. Then we have a kind of monopoly, we cannot call it exactly it is a monopoly, it is a act of monopoly that is monopolization where the attempt by the firm to dominate the market or become the monopoly. And generally we take the typical example of Microsoft where they are trying to get into the anti-virus market and by bundling their product and that is a classic example we always take that this is the act of monopolization by the Microsoft to become a monopoly leader in anti-virus market also because they are trying to do it through the bundling activity and if you remember there is also a antitrust case against the Microsoft for this monopolization act. So, it is not a kind of monopoly rather an act or rather an attempt by the firms to become a monopoly leader. Then we have a legal or regulated monopoly it is created when the government restricts the entry of other players in particular market in order to keep the total control in hand like the typical example of Indian railway and maybe the different state electricity board. This is the regulated monopoly because this generally the government keeps all the control the government takes a call with respect to price and output decision and that leads to the generally that leads to the market or that leads to the entire market firm into the monopoly market. And generally this is a kind of monopoly where the behavior is overseen by the government entity and typically the public utility sector that is generally known as the generally comes under this form of the monopoly like that example of state electricity board or it is a case of Indian railway where the behavior is overseen by the government or there is some say of the government when it comes to the price and output decision and that leads to the market as the monopoly form of market structure. Then we will talk about the demand and monopoly demand and revenue of a monopoly market. Demand curve is downward sloping it is a regular demand curve downward sloping price and quantity demanded there inversely related and if the monopolist want to sell they have to reduce the price. So, the demand curve of monopolist is highly price in an in a in elastic because of this the single product available in the market and there is no close substitute that leads to the inelasticity of the monopolist and that is why the demand curve is highly price in elastic. When a monopoly drops the price to sell one more unit the revenue is received from the previously sold unit also decreases because since there is a single product and there is no close substitute sometime if the monopoly firms want to sell more they have to at least reduce the price and in this case the revenue received from previously sold unit also decreases because the price is decreasing even if the quantity is increasing. So, when a monopoly increases the amount itself it has two effect on total revenue. So, what is our total revenue? Total revenue is price and quantity. So, output effect more output is sold and Q is higher because there is a decrease in the price that leads to the output effect because Q is higher price effect price decreases. So, price is generally lower. So, whenever the monopoly increase amount itself it has to reduce the price then only the sell will be more and that is why it leads to two kind of effect one is output effect and second one is the price effect. So, here the average revenue curve denotes the demand curve for the firm and also determine the slope of the marginal revenue curve. So, average revenue curve is also the demand curve there is a same in case of a perfect competitive market structure also because the average revenue is also equal to the demand curve, but here the difference is that here the marginal revenue curve is separate, but in case of competitive market structure the marginal revenue curve is also equal to the average revenue curve. And the average revenue curve also determines the slope of the marginal revenue curve. Since the demand curve is highly inelastic average revenue curve would be downward sloping and the marginal curve would lie below the average revenue curve. So, if the demand curve is highly inelastic average revenue curve will be downward sloping and marginal curve would lie below the average revenue curve. And the monopolist marginal revenue is always less than the price of its good. And why it is generally less than the price of its good? Because monopoly has to lower the price of all units of its product if it wants to sell the additional unit. And the addition to the total revenue resulting from selling additional unit would be less than the price of the firm would receive for this unit. It means the marginal revenue has to be less than the price. So, MR is less than price and MR curve would lie below the average revenue curve. Now, we will see for a linear demand curve the slope of the marginal revenue curve is twice that of average revenue curve. And marginal revenue curve would lie half way between the average revenue curve and the price axis. So, for a linear demand curve the slope of the MR is twice that is slope of the air. And it will lie half way between the price curve and price axis and the average revenue curve. So, let us see the how generally we graphically look at the slope of the average revenue curve and the slope of the marginal revenue curve. And we will check whether the slope of the marginal revenue curve lies below average revenue curve. And algebraically also we will see what is the slope generally for the average revenue curve and whether the slope of the marginal revenue curve which twice of the slope of the average revenue curve. So, if you take a demand curve that is P is equal to A minus BQ then what will be the revenue? Revenue is PQ and if it is PQ then it is A minus BQ multiplied by Q. And which leads to AQ minus BQ square and this is the total revenue. So, slope of average revenue will be B because this is TR by Q and slope of marginal revenue will be we need to find out the slope of marginal revenue and what is marginal revenue? Marginal revenue is DR DQ. So that comes to D AQ minus BQ square with respect to Q and that will get it then this is A and 2BQ. And what is the slope of marginal revenue curve? The slope of marginal revenue curve is minus 2B. So, slope of average revenue curve is B and slope of marginal revenue curve is 2B. So, we can conclude that the slope of marginal revenue is 2B. Twice that of slope of average revenue curve because the slope of AR is B and slope of MR is 2B. Then graphically how we generally represent this? Graphically we represent this as this is our average revenue curve and this is the marginal revenue curve. Here we take revenue and cost and here we take the quantity and if you look at the marginal revenue curve you just look at it lies in the half way between the average revenue curve and the price axis. So, monopoly demand curve if you look at monopoly demand curve is the average revenue curve and the slope of the average revenue curve in a typically demand function if it is A minus BQ then it is get B and slope of marginal revenue curve is 2BQ and 2B. So, that leads to the slope of marginal revenue curve is the twice of the slope of the average revenue curve and for a linear demand curve always the slope the MR lies below the average revenue curve because the slope is more than the slope of the average revenue curve. Then we will come to the profit maximization of the monopoly firm. So, the profit maximizing rule is again same marginal cost has to be equal to marginal revenue for the first order condition and the slope of the MC should be greater than the slope of the MR for the second order condition. So, monopoly maximizes the profit by producing the quantity at which the marginal revenue equal to marginal cost and then it uses the demand curve or the typical average revenue curve to find what price induce the consumer to buy that quantity. So, the first one they find out the output level by MR and MC that is the profit maximizing rule and then by using the demand they find out the price at that price what the consumer is ready to buy. So, what is the steps for the profit maximization? We need to set marginal revenue is equal to marginal cost to find the Q that maximizes the profit. Then we use the market demand curve to find a P that the Q brings and then we find average total cost and average variable cost to determine profit losses or shutdown. So, the first step is to equalize marginal revenue and marginal cost find out the Q that maximizes the profit. Then we use the market demand curve to find the price that the quantity brings and finally we will find out the cost associated with that level of producing Q because that will tell us whether the firm at that level of quantity whether the firm is incurring loss making profit or making super-novel profit. So, here the profit is equal to the total revenue minus total cost total revenue is that is P Q and total cost is the fixed cost plus the variable cost.  So, if you simplify this then becomes P minus average total cost multiplied by Q and this is also called as the profit margin and the monopolist will receive economic profit as long as price is greater than the average total cost. So, till the time price is greater than average total cost monopolist will receive economic profit. If the price is equal to the average cost or the average total cost that is normal profit and if the price is below the average total cost then it becomes the loss. Then we will take the case of in case of short run we will take the case of super normal profit in which case generally the firm gets super normal profit. Then we will take the case of loss like in which case the firm gets loss and in which case the firm gets the normal profit. So, to start with we will do it for the super normal profit. So, we will find out our here we will take quantity, here we will take average revenue, marginal revenue, average cost and marginal cost. So, this is our average revenue, this is our marginal revenue, then this is our average cost, marginal cost intersect the average cost at its minimum. Now, what is the what is the steps for the profit maximization? First we need to find the equality of marginal cost and marginal revenue. So, this is the point where the first order condition gets fulfilled and corresponding to this we will identify the quantity, this is the profit maximizing level of output. Next what we should do? Using the demand curve we will find out the price. So, corresponding to this we will find the price axis and this is the price. Now, this is the profit maximizing quantity, this is the profit maximizing price. This we have got through the equalization of marginal cost and marginal revenue. Now, next we need to find out at this price, at this quantity what is the situation for the firm, whether the firm is getting super normal profit, whether the firm is getting the normal profit or whether the firm is getting loss. How to find out that? That is through the average revenue or so called price and the average cost. So, corresponding to this what is the average cost corresponding to this, this is the average cost and this is the price. So, P is greater than average cost. So, if you remember till the time P is greater than average cost the firm will get economic profit or so called super normal profit. And what is the amount of the super normal profit? The difference between the average cost and the average revenue curve and this is the amount of profit super normal profit what the firm is getting. So, if the price is greater than average total cost the amount between the average total cost and the average revenue curve that gives us the super normal profit this is above the cost of production. Now next we will find out what is the second situation that is for the normal profit. Again we will follow the same process or the same steps to find out the normal profit. So, here we have revenue and cost, here we have quantity. We will draw our average revenue curve, we will draw the marginal revenue curve, then we will draw our average cost curve and we will draw the marginal cost curve. We have average revenue, we have marginal revenue, we have average cost, we have marginal cost. Marginal revenue, marginal cost is the to find out the profit maximizing level of output corresponding to that we get the level of output corresponding to that in the demand curve we get the price. Now what is the next task? If this is the profit maximizing price, this is the profit maximizing output we need to find out that what is the profit, what is the profit or what is the loss. So, in this case if you look at corresponding to this point the average cost is just equal to the average revenue. If average cost is equal to average revenue the firm is incurring no loss the firm is not incurring the super normal profit. Now this is the case of a normal profit where corresponding to the profit maximizing level of output the average cost is equal to the average revenue curve. Then we will analyze the case of loss where particularly the firm incurs loss when it is a profit maximizing condition. So, we have average revenue, quantity, revenue and cost, we have marginal revenue, we have average cost and we have marginal cost. We will find out the marginal revenue, marginal cost condition, we will find out the Q, we will find out the P. So, this is P, this is Q. Corresponding to this you will find this is the amount of the cost. So, in this case the average cost is greater than price and that leads to the loss for the market, loss for the firm as this much area because this gives the difference between the average cost and P. So, in this case at this level of output the average cost is higher than the price and that is why the firm is incurring loss. The common question comes here whether since it is a case of the monopolist whether the firm should incur loss or not because it is a monopolist they have a independent capacity to take a decision on the price and the output. There is only single firm, single producer at least there is no close substitute. So, monopoly is a market firm where there is no close substitute. Now, still when the firm is incurring loss in the short run what may be the possible reasons. There is possibility that the firm may incur loss in the also in the short run and what are the possibility or what is the reason that the firm is incurring loss in the short run. First maybe it is possible that in the early year the monopolist may not be very efficient to attend the low average cost of production. May be the cost efficiency or may be to attend the low average cost of production it is not possible at the early year of the monopoly. Then the size of the market in the early years may be small hence to sell the entire output firm has to incur the losses. So, the size of the market in the early year may be small not very large and to sell entire output may be the firm has to lower the price which leads to incur or may be evidence of loss in the short run. Then the monopoly firm deliberate look charge a low price to keep the competitor out of this market. Why they charge a low price? If you remember whenever there is a super normal profit that attracts the firm other firms to enter into the industry and if they are charging a high price that leads to super normal profit and that will attract the new firms enter into the industry and in that case may be the competition will be there and it may not be a monopoly market again. And that is the reason they take a strategy to maintain a lower price because if you are maintaining a lower price that is not profitable for the other firms to enter into the market or there will be no incentive for the other firms to enter into the market and that serve as an anti-bariour, but in the other side when they are charging a low price generally that leads to the loss for the firm because they are charging a low price and that leads to a situation where price is less than the average total cost. Then in order to curve the creation of monopoly sometimes the government may impose a tax on the monopoly product which in turn increase the cost of production. So, there is a tax so whenever there is a imposition of tax that increase the cost of production and in that case whatever the price they are charging that becomes less than the average total cost and that leads to the may be the possible cause or that leads to the sum of the loss in the monopoly. And we will come to the price and output determination in the long run. So, here if you look at the long run again it is different from the short run in term of the factors used in case of the expanding the scale of operation or may be it has a there is no fixed cost or there is no fixed input all the inputs are variables that is why all the cost are variable. So, in the long run monopoly firm would either a normal profit or super normal profit, but would not incur loss in the long run because if there if you if you remember the in case of competitive market when the firm incur loss in the short run still they continue with the hope that the long run they are going to incur loss in at least they can they are going to make the normal profit. But in case of monopoly generally in the long run they are not going to incur loss at all either they will get a normal profit or super normal profit, but as a strategy they prefer to take a normal profit because when it is their earning super normal profit that that work as a incentive for the incentive for the other players to enter into the market and that is the reason if you look at all the firms they get normal profit not the super normal profit. And they would rather try to reduce the cost of production increasing the control of raw materials and that will give some amount of profit to the firm above the normal profit because if they are reducing the cost of production still charging that much price the gap between the price and total cost is more and that brings more profit to them and how generally they reduce the cost of production when by increasing the control on the raw materials because since they are the sole producer or sole seller if the raw material the supplier is not selling the raw materials to them may be there is no there is no market for that particular raw material and in that way the exercise control on the supplier of the raw materials they get it in the reduced cost and that again leads to the reduced cost of production for the other firms. So, what happens when they are getting the super normal profit? Super normal profit leads to high price attract competition high price will allow to survive the new entrant and the it leads to again competition. So, whenever there is a super normal profit if they are getting super normal profit it is always the because of high price which attracts the competition and high price will allow to survive the new entrant and that will lead to competition. So, to retain the monopoly power generally the firm they charge a low price where they get only the normal profit and the low price also serve as a entry barrier for the new firm. Then we will just take a numerical to understand that how in the long run the price and output is decided and also the profit. So, here we take the total cost that is 50 plus 40 Q we will take the demand curve that is 100 minus 2 Q we need to maximize the profit and for that we will find out the D pi by D Q which in turn this is D R Q with respect to D Q minus D C Q with respect to D Q. Now marginal revenue is equal to marginal cost. So, if you know from here because this is marginal revenue this is marginal cost if this is equal to 0 then marginal revenue is equal to marginal cost. We will find out now the marginal revenue and we will find out now the marginal cost. What is total revenue? Total revenue is 100 minus 2 Q multiplied by Q. So, that comes to 100 Q minus 2 Q square and marginal revenue is D T R with respect to Q. So, this becomes 100 minus 4 Q this is the value of the marginal revenue. Then we will find the marginal cost and how we can find out the marginal cost that is again through the taking the derivative from the total cost function with respect to the with respect to the Q. So, we have total cost function that is 50 plus 40 Q and marginal cost is T T C with respect to Q. So, that becomes 40. So, we have now we will find out find out the quantity. So, marginal revenue is 100 minus 4 Q m c is equal to 40 and if you simplify this then this is 4 Q is equal to 60 and Q is equal to 15. Now from here we can find out the value of P. How we will find out the value of P? P is equal to 100 minus 2 Q. So, that comes to 100 minus 2 15 that is 100 minus 30 that is 70. So, P is equal to 70 Q is equal to 15. Now we will see because this is the first order condition we will see whether the second order condition gets fulfilled or not. So, second order condition is D square pi D Q square should be less than 0. So, in this case if you look at what is the second order derivative of this. If you look at this is minus 4 if you solve this is we get minus 4 which is less than 0. So, second order condition also gets fulfilled and with this value of P is 70 Q is 15 we get the value of profit which is equal to 400. So, this is how generally we solve the numerical when it comes to whether short term or long run we equalize that with the we check whether both the conditions get fulfilled or not and from the first order condition we get the value of Q and P. We put the value in the Q revenue function and cost function in order to get the profit. So, we will stop here today in the next session we will discuss about the supply curve of the monopoly firm. How the measurement of the monopoly power is done? Generally how the multi plant firms they function or how the price output determination is done in the multi plant firm and we will do a comparative assessment between the monopoly firm and the perfect competitive firm.


In this module, you will see that when our thinking is changed about gender that is deconstruction takes place and it happens through our desire. What happens after that? The social system constructs gender, then we deconstruct it through desire. What happens now? Culture interferes. Culture controls our desire. This influence of culture leads to another process that is called reconstruction. Initially gender work is done by male children. Now how it happens? How culture does it? The first stage is through male children and adults. After the first two years of life they are agents of culture. They do the gender work. They construct art, art and views about them. During this phase fathers are more active in parenting than our mothers. The style of parenting is different for boys and girls. See our treatment by our fathers. They talk with us. The stories they tell us. So in parenting, in our grooming, they are more active and especially in grooming of boys. Monitor the choice of gender specific games, language or toys. So everything is being monitored, being controlled through parenting and especially by fathers. In parenting, fathers give more attention to boys than girls. It is also observed that girls are more neutral in choices of plays etc. than the boys. Whenever they play, they talk, they remain neutral. Boys tend to be more rigid because they are interrupted by their male peers. Male peers, they enforce gender norms. They remind them of gender norms. And they disapprove feminine choices. See fathers start this process. They focus on boys. Then comes our peers, especially male peers. Male peers also take part in this monitoring of our choices. And whenever we take wrong choices, these people interrupt. Apparently activities and behaviors are neutral. There is of course something different in case of girls. The difference is called asymmetric view of gender. So this is the way culture interferes. And this is the way culture reconstructs, reset our thinking about gender. Here is a task to further elaborate the ideas I have shared with you. Talk with your father, see when he is free and comfortable. Interview him informally to support or reject the idea of asymmetry. Asymmetry means their attitude for boys and for girls is not symmetrical, not identical, not similar. So after the interview, you will see whether the view that culture creates asymmetric attitude towards boys and girls is right or wrong. Another task is compare your findings from the interview with your father with some book or any other writing on parenting styles. Such books are available especially in libraries where early childhood education is taught. So parenting style, even general bookshop and Google can provide you books, materials on parenting styles. So write your own point of view after this comparison with your father's parenting style and with the style discussed in that book. Remember you will focus on parenting in Pakistani culture.


The Dragon Ball Super Broly movie, you've seen it, you've loved it, but have you ever really thought about what Broly was really up against? This is a guy that didn't even know other humans really existed and then he had to fight Goku, Vegeta, Frieza and then Goku and Vegeta fused with a sweet puffy jacket. Oh, and halfway through his dad died. Winning this fight was next to impossible. And the fans behind the BT4 mod must agree because this challenge recreating the movie is one of the hardest in the entire game. Will I be able to beat it using Broly myself? Well, that is exactly what I intend to find out. Oh yeah, and like and subscribe. Damn, Broly has a way with words. Power of a Saiyan? Damn, Broly has the true power of a Saiyan? Okay, no shot, I'm winning this. This is already giving me flashbacks to the last parallel quest we tried. You have to be like a Budokai Tenkaiichi god to beat these things legitimately. Oh no way, he back stepped into a prominent flash. What? Oh my god, he's got beams on top of beams. What if I throw one? Damn, okay, well never mind, it kind of worked.  Oh, he can't touch what he can't see. Anime. He'll up, he'll up, he'll up, he'll up. Nope, nope. Damn! Where is he, where is he, where is he? Oh!  Damn, Broly kind of got hands himself. Let's go! And you know what? And you know what? Wait, wait, why is it not working? Transform! Transform, Broly! Wait, what? It takes three bars to go Super Saiyan? Why does it take, first of all, it shouldn't even take three. Oh, here it goes! Let's go! It did, it cost zero bars for some reason. Damn. Meteor shower! I missed everything. No! Alright, we have one bar explosive wave though, that's kind of cheap. Just try to keep our eyes on the, um, the plus side, you know? Alright, if he wants to beam clash, I will beam clash him all day. Oh! Take this!  Let's go! I didn't end up installing anything, I'm here for the long haul Vegeta! You should have known about me! Oh, he just took my stamina. I'm going to have to wait around for three bars of Ki to come back naturally. I am not going to get to move again, am I? Goku, please! Goku, mercy! Mercy! Mercy! He picked me up off the ground! I can't even move yet! Goku, mercy! Okay, so that was unfortunate. But, um, you know, we get back after it, that's fine. That was unfortunate. Alright, but here's what we're going to do. Now, since we went Super Saiyan naturally, I just get to start Super Saiyan. And surely, nobody will call that cheating. Oh, never mind. Oh! What an intro! That was sick! They updated Broly's intro? That was Kaleed! Meteor shower! Damn! I was still tracking him, but it only did that much damage. That gate took war! How did he dodge that? How did he dodge that? Oh ho!  Okay, okay, there we go. There we go, knock him up. Follow up with a big punch. Expulsive Wave, one bar. Don't let him do that, and I messed up. There we go, nice dodge! Dragon Ball! Anime! I lost! Win the clash! I'm getting pretty good at those clashes, though. Can we all admit that? Oh my God, one bar explosive wave. Never mind. Took too long. Alright, back up, get some distance. Get some distance. Expulsive Wave, nice. If he tries to rush us, just use our one bar explosive wave. It's cheap. Ominous Flash, don't let it hit! We didn't have a choice. Do we dare go with Meteor Shower? Oh, just hit him with Omega Blaster. Surely he loses this. Can't even block it. That move is cheap! Okay, so far I think, you know, we've got something with Broly that we can definitely make work. It's just going to be a matter of how often we're able to... I didn't even know he tried that. Meteor Shower's just dead. Damn, that move is strong, too. Oh my God! Do we at least get a bar of health every time? No, cool. Alright, so we're just dead. One bar explosive wave, get some distance. Oh... No! I couldn't run. I couldn't run! I tried to take on the Jets, but Goku was not having it! Goku was not letting that one slide! I like that. Get some distance. And Blue Goku... Blue Goku actually should be banned, I'm going to be honest. This character has put me through the ringer in too many parallel quests. He's trying to charge up. Get there, get there, get there! No! One bar explosive wave! Charge up, charge up, charge up! Use it, Broly, use it! Broly! No! Broly! No! My ultimate! It's okay, that's not too much damage. Alright, now that... Damn! Damn! Alright, well now that he's down there... There it is, there's Omega Blaster. I was wondering when it was going to come out. Fire it! I missed. Okay. No, don't even try that. Okay, I didn't block it. Dodge it! I didn't dodge it. Dodge it! I didn't vanish it. Vanish this! Don't hit me! Block that! I'm not losing! Oh. Alright, so we made it to Goku, who is two out of four characters we need to be with no heals. Awesome. I was just making sure that I understand the rules of this parallel quest. I like this new intro though. Look at this updated intro. That's actually sick. Gigantic roar. Oh, that could have been used. Now I dodge yours. Oh, I actually did it though. I was actually just kind of doing a bit. I didn't expect to actually be gone like. Oh, come off it Vegeta. We already did this. Damn, even when I'm good at the game, I'm bad at the game. Impossible to deal with. Meteor shower just did I know he's run up on me and... Please, Mercy! We're just gonna restart here guys. That was a bad beginning. Alright, here we are again against Vegeta. We're gonna give him the space because clearly he does not do... Don't even try it. Gigantic roar with boost and it didn't hit him. For some reason, he clashed so hard with me. I can't believe we lost that too. At least we dodged Gala Gun. There. Dragon Ball. Anime. What?  Okay, run. Nice dodge, Broly. Meteor shower, respond. 5k damage, I'll take it. Oh my god, what a response by Broly to dodge that. Nice blocks, don't let the Keyblast do too much damage. Return off, return fire. Ah, he's using a lot of Keyblast. Yell at him, yell at him, yell at him. Yes! We're in the money now, we're in the money now. 8k damage, I'm gonna have to win a clash. We're playing the... We're playing the game, explosive wave, get him off me. Damn, that bounced him back. Reflect those. They ran out before they... Ah, he started dodging. That's fine. He's gonna be up at blue, but that's fine. Just Meteor shower. Up close and personal. I know he did not block that. Meteor shower again. He dodged most of it, but he didn't dodge the end. I'm gonna win this. Yes!  Meteor shower, part 4. I knew he couldn't dodge all of it. We are in the money, Goku's coming out. We actually have blue health. Yeah, I am. Okay, wait, he's a little...  He's a little stronger. We know that, though. We know that. We know blue Goku's for real. Dragon Ball, anime. Budokai, Takaichi. Let's go! I'm playing the goddamn game right now. Come on. Ah, I couldn't win that one. Okay, my wrists are starting to give out on the clash.  While I'm blind, I can't see. Meteor shower. Has he got up close and personal? I'm not gonna let him play. I'm gonna...  Dragon Ball. I don't... Lose... These... Let's go! I told you I don't lose these. Explosive wave.  Wave! Ugh! My actually doesn't win this thing. Explosive wave. Yes, that was a great counter. If that rush move would have hit, it would have been all over. I'm making it to Gojira. They told me it was impossible. They said I would never play the game right. You wanna beam clash, Frieza? You do not wanna beam clash. I already saw you sneaking up on me. Get back! Oh! He thought he could be Broly. Not gonna happen. Wait, where's he going? Thank God. I thought he was gonna hit me there. Alright, I'm just gonna go with a nice Meteor shower here. He's getting low. I just need to chip him down this last bar. Okay, that was pretty aggressive. I'm on the ground. That should not combo. Alright, now that you're on the ground, Frieza... Ha ha ha ha! Alright, and Key Blast. Damn! It's Gojira! We actually might win! Let's go! I got...  That's fine. We blocked that. Oh! I need to... I need to vanish here badly. Gojira's... Gojira's definitely not somebody you wanna mess with. I understand, I understand, I understand. Explosive wave. Alright, come on. Play safe, play safe, play safe, play smart. Explosive wave. He's trying to teleport behind me. Okay, Gojira's smart. Oh, he's fast too! He's fast too! How am I supposed to beat him? No, I can't, I can't, I can't. That... I think that...  No! I'm still alive! One HP and a dream! I'm not going down to nobody! Why is he so fast? Let him charge up, let him charge up. Okay, don't... I gotta try to win this. Oh, no! I gotta try!   Bro was just not feeling it! Come on, Gojira is a beast! Alright, we're gonna try this one more time. I think that's as close as I'll ever get. Damn, I'd be stuttering too. Gojira kind of beat the language out of me. But listen, I'm gonna try him one more time. Whatever happens happens. Let me watch this new intro one last time. Team BT4 be working hard. You know it was a good attempt, because I'd be... I'd be Vegeta with, like, red bar. I feel like I've gotten, like, crazy good at this game, though. Like, I've gotten crazy good at Budokai, I think, Aichi. Ooh, nice finish!   How is this fair to me? We're doing it again! Aw, I lost! Bro, what do they expect from a human being? Aw, he threw a Key Blast at me. Didn't even let me block. That was smart for him. There we go! That's huge damage! Get up, get up, get up, Meteor Shower, Meteor Shower, Meteor Shower. Nice! Aw, I don't know where he is. I think he only took half of that. What the... Okay, explosive way to clutch up. Alright, I think we just Meteor Shower for gain here, honestly. There's no shot he dodged at Meteor Shower. Nobody dodged Meteor Shower. This simply does not happen. Alright, Goku. I'll give it up. Goku is pretty strong. Compared to Frieza and Vegeta, Goku is definitely the go. Okay, okay, there was no dodging that. I'm on the ground. That should not hit. If that hits, I'm quitting. Yes. There we go. Fight back. There we go. Got the vanish. Tweak the leg. Not gonna happen. Explosive way to get him off me.  Okay, hold on. Oh, aw, come on. Explosive way to that. No more damage, no more damage. Meteor Shower, if he's gonna try to rush me, don't. Don't even try that on Broly. You can't. Why is Bro- Bro was stunned for six years. No! Damn, so much damage. It's not fair, man. It's not fair, Bro. Block that. I did not win that one and I was not even close. There we go. There we go again. I was waiting for that. Aw, I missed by an inch. No shot, dude. No shot, I missed by that little. Climb me. Get off me. Let's go, let's go, let's go. I don't lose these. I don't lose these. Alright, maybe I lose these. Please tell me explosive wave still on. He should not be able to hit me. Yes! Meteor Shower! He dodged it! Oh no!  I have to win. Oh no. No, Bro. No! I was, I was aiming at him. I don't know what happened. No! No!