So let's make it bigger and see how we can make this code cleaner.
OK, let's start by this that we can see two lines like this that has been repeated a lot in Boston,
the one to take a look what we have here, bottom dots.
So now I want to create a block of code that will just be reused in the side this blocks instead of
repeating all this lines again and again.
So for this, let's see where it is finished right here.
So after this, I'm going to say function and call this function, for example, number collect, because
it is going to do something with clear thinking the number and inside, let's just get one of these
two lines cut and paste it right here.
And I am going to call this number clicked.
In the site here, and as we know, we need the opening and closing races here and you can see that
it says that we have no parameters.
OK, so this will be worked for No one.
But what if I click on number two?
I wanted to change to number two.
We can possibly be doing and think about that.
But if you have paused it now, I'm going to tell you the solution.
The solution is that you can't pass a parameter to this click number and call it, for example, just
number, which is off type.
We can say integer and then convert it to string here.
So here instead of one, I will say no, no.
Which number?
All they will be shadowed because they have two numbers.
So let's call it number cliqued.
Copy and paste it here.
OK, so this will be no, and that is the argument or the parameter, and we can see that it will be
concatenated to this.
But I will say is strange.
OK, so one shrink will be concatenated to this string, which this could be one to three or anything
else that you want.
And we have something here said that make it private because this function is going to use just inside
this glass.
But we'll talk about this later in the inheritance part where we are going to talk about the object
oriented.
But for now, I am going to use reuse you.
I'm really sorry.
I am really tired, actually.
No cliqued.
Let's go up here.
We have a problem because we haven't passed our parameter to see what's the parameter we can say like
this.
You can.
It says that in turn the number clicked parameter so it will be well now let's do the same for all of
this number clicked this time to let's do it till.
Let's copy and paste them all.
Go ahead and do that.
I'm going ahead and doing that on my own.
So you can see that I have already used that block of code, which is called a function in all of these
branches, so this is much more nicer because they are summarized in just two lines and that two lines
has been reused.
So we have decreased the number of lines of code that we have, and that is something clever that we
have thought.
So let's see if we can do it for others.
We can't do it for DOT because I can't pass that as a parameter to number clicked because no cliqued
expects an integer as a parameter.
So number of button dot is OK, but unclear.
Clear is just one line is OK then what else we have.
We have button class can do the same for these operations tool because as Uncle Bob says, oh sorry,
we prefer to have just one line inside our branches, invent expression inside these blocks or for example
inside if else or if or else if or else statements.
This is something that is a preferred to be done.
So I'm going to create a function, call it plus collect.
I have copy that and I will say private function.
Pelosse collect and put it inside this block like this, we don't need any parmeter, so let's just
reuse it here.
So we have a just one line for this branch.
Let's do the same for minus to.
And you can see that I am defining my functions right before the upper function, the function that
is calling these plus or minus cliqued, this is another point that you should know how to define a
function, how to call it minus click.
You can see that I have defined the minus cliqued function here just after where I want to call them.
So what else?
We have the divide function.
I will call it private function.
Divide cliqued.
And inside of have this and I'm going to reuse it.
Here, so let's again take a look at them.
This is much more nicer to we can't even create a function for these two lines, but that will be your
challenge.
And this is one line.
You can see that we prefer to have just one line inside each branch.
And for this, we have a gray line just below our.
Let's see what Andrew is going to suggest us.
Suggest us.
And that is replace.
If it's when, let's replace it.
OK.
You can see that how it has converted our UV Alice and Alice Eve statements to Ben because I understood
your prefer to have one instead of it.
That's OK.
We did a lot of job for that.
Thanks tenders today for changing it, but I like it too.
So for this we can start by extracting this one expression because we want to have just one line here.
Inside this block side will say private function.
This time Ekwall is correct.
And inside of Veliko, this lodge, let's call this Ekwall is cliqued here.
OK, this is OK, but if we go down again, we have an expression which inside each branch we have four
lines and even I want to go ahead and.
You know what I want to do, I want to extract functions from this, too, you can see that I am trying
to break the code as much as I can to functions, to block off codes.
And that is because that make a code clear, a code that can be read with any volume, you know, then
most of the time, this is not just you that's working on a project.
This will be a team that's working on the project.
So when your team or your co-worker, then your team mate see that you have write code like D, that
he or she can understand it.
He first off first of all, you have helped him or her and sing.
A second of all, you will have a better perspective because you are being charged by that person.
So I want you to be that person that has been judged.
But just devel.
They know you as a professional programmer if you do these things that I am telling you in episodes
like this.
So let's extract this call.
It's private function.
Just plus an inside will go this and I'm going to call plus function like this.
Let's do the same for minus and divide.
Private function divide.
And divide, it should be called here and at last, oh, sorry, this was let's change it to.
It was it was minus.
So now let's extract this, which this time this is divide, private function, divide, and in the
sides will have this.
I'm going to call divide right here.
So now inside plus minus and divide.
We can not make more functions as much as we have done here.
So this is the code.
That's I myself really like is I know that you like it to it because everything is where they should
be and everything is really arranged.
Well, we can even do this as let's do this.
This is not a good line because I want just one line in each branch.
This work, if you have a hundred lines in a branch.
But as I said, as Uncle Bob says, this will be better to have one branch in each one expression branch
or if a statement branch.
So what is this let's call it that is collect.
And I'm going to define it just below this number clicked because they have the same concept actually
that is clicked.
Inside will call this.
OK, so, you know, this is a really, really nice class of lines of code that I won't be tired of
looking at it.
And the scroll is up and down for an hour because this is really in my scope.
So that says it's about a calculator app.
We learned a lot in this section.
I know maybe you need to go over all these episodes again to see what's going on.
If you have any problem.
We have the Q and A, we have the Internet, we have the stack overflow.
We can go there, search.
And as a developer, you should have a great ability of search and debugging.
And you know, what I want to tell you is that I was tired because in this time of at the time you are
listening to this episode, we are in the era of coronavirus thing.
So I am working remotely all alone at home.
And you guys, my students, my potential students are the ones that I can talk to.
I hope that my voice will be heard soon by you because I want my course to be up on the themI soon.
So that was it.
And I have talked a little bit about myself, but don't lose hope even in this coronavirus.
Think that maybe a lot of people have lost their job, but somebody's always have lines of code to do.
So let's go to the next section and see what will be the next app that we want to create.
See you soon.