Instructor: So that's it for this section.
It was a long section
with a lot of code, which we changed.
Now, we have this final result
though I will already say one piece is missing.
And that would be polymorphism,
which also can help us with solving that problem
of having duplicate if checks.
We solved it for now
by having this map full of functions, which works.
But there is another approach using classes
and polymorphism, which I will also come back to
in the next section, however,
because the next section will be about classes,
objects and everything we need to know about them
when it comes to writing clean code.
So therefore, for the moment,
this is the final state.
And of course, you might argue
that this is quite a long file
with quite a lot of scrolling required to move around.
Now, of course, keep a couple of things in mind.
For one, we've got a bunch of dummy data here,
which already occupies 30-ish lines of code.
And then we get all these dummy methods down there
at the bottom, which we, of course,
also would have in reality
with real code in there
but they would probably not all be in the same file.
And in general, this long file could be split up.
I have an example folder structure here
in the final-demo folder,
which you also find attached.
There, I have a very lean app.js file
where we just have the main function,
processTransactions and processTransaction
and then all the other functions,
which are being called in here
are in the end imported from other files,
which you find in subfolders.
For example, the util folder has the error-handling function
and my validator functions.
The data folder simply holds these transactions
and the processing folder
has these functions that deal with the direct processing
of the transactions.
So the validation, and then also for processing
with a processor, and picking a processor.
And of course, in reality,
you would split up code like this
or in a similar way
because that then makes the individual files easier to read
and therefore, also helps with achieving clean code
throughout your entire project.
You don't just want to have one endless file.
Of course, for the purpose of this section
and for showing everything
without switching files all the time,
I did do it all in one file
and even if you go through this file, therefore,
it should still be rather clean.
It reads top to bottom.
We have these functions with good names,
which we can call
and we used all these functions
and all these various concepts covered
through this course
to ensure that we still have a couple of if statements
and a loop but we have less of them
and we do combine them
in a more structured way
to ensure that we have way more readable code
even though it takes up more lines of code
than we had the beginning
because this was definitely harder to read
and understand and maintain and it had a lot
of duplication inside of it.
So now throughout this section,
we learned how splitting this up into functions,
something we already learned in the last section
and how a couple of tweaks related
to if statements
and how to name our conditions and so on
can help us with turning this into a way more readable
and therefore cleaner code base.