One of the things that I try to do on a regular basis is to go through my code regularly as I'm working
on a project and just do a code review.
And in the best of all possible worlds, code reviews are done by somebody else.
I'll write code.
Somebody else will review it and we'll make changes as necessary.
But when I'm working by myself, which I do a great deal of the time, I wind up doing the code review
on my own.
And I typically set aside Wednesday afternoons to go through the previous weeks work and just find things
that need to be cleaned up.
And if you look at our code base right now, there are a few things that need to be cleaned up.
For example, I have this reservation model which we were using early on, but I also have this reservations
model, plural, and they duplicate each other.
I don't need this one anymore, so I'm going to get rid of it, which means that a few things will break.
For example, in the main package, I no longer can put a reservation model in there because it doesn't
exist anymore.
I'm going to leave that alone for a minute because there's another thing that I noticed.
I've named every one of these types using a plural word, even though in code, when I draw a particular
user out of the database, I'm looking at one user.
When I want to have more than one users, I'll draw a slice of users out of the database.
So I'm going to rename this model to User and I'll rename the comment and I'll do that for all of my
models because they all should be singular.
It just makes your code read better when you have the S on the end making user, for example, plural
users.
Your code really isn't as readable because it implies there might be more than one in that when in fact
there is not.
So let's fix all of these.
And let's fix these two.
So that should take care of it here.
Now, back in our main, did that fix this problem?
Yes, it did.
What else might I store in the session?
I may as well as I'll put in my user and I may as well put in a room, and I may as well put in a what
else do we have in here?
Room restriction.
Sure.
Let's put in a restriction, too.
We may not use it, but it's not going to hurt anything at all to register these in the session.
So there's there's a couple of things clean up right away.
Now let's check our handlers and make sure they didn't break.
No, no errors, they're good so far, so good, and let's make sure it runs.
Everything piles, that's good, and let's try our tests.
And we have a break, so main test go assignment mismatch one variable, but one returns to values a
aha.
Let's go fix that.
So that's in main test.
Go and run now.
Actually takes two variables.
So the first one we'll just ignore and for this one, not enough arguments to call in call to new repo.
Right.
Because here we actually need to pass a database connection.
Cool to it.
I'm going to leave that alone right now because what we're going to do is use our repository repository
model to create a test database repository.
And we're not going to do that right now.
We'll do that in a future lecture.
So I'll leave that one alone for right now.
Now, is there anything else that makes no sense?
Or I noticed one other thing when I went through my code, and you may have noticed it, too.
I'm down here at the end of the run function in May not go.
I'm calling Handler's new handler.
That's fine.
And I'm calling render new templates.
But new templates is actually a package call in a package called Render.
So I'm going to rename that that method.
So instead of calling it new templates, I'll call it New Renderer Earth and then I'll fix the comment.
And down here in this package, I have the function named render template.
Instead, let's just call it template because it's convention not to name a function in a given package
with the name of the package as the first part of the word.
It just makes it more readable.
So we'll have to fix things in our main function here.
This will be new renderer and then we'll have to fix things renderer and then we'll have to fix things
that our handlers, because those are broken now.
Everywhere I called render template is, should you say, render dot template, which actually reads
much better.
So what I'll do is copy this and say edit find and replace.
So I'll find Renderer, render template and replace it with Renderer, render dot template, and that
should fix it.
And it appears to let's make sure things run out, clear the screen.
That's much cleaner.
OK, so that was just a minor cleanup and we do have to remember that we're going to have to fix our
set up tax test here so we can fix this one right now, render new renderer.
We'll have to fix this part and we'll do that when we get to when we actually have a couple of database
functions to test.
Will set up a new repo repository database repository specifically for testing.
And we'll use that in this this test, but will be a couple of lectures before we get there.
In the meantime, we have cleaned up our our code a little bit.
We've made it more readable.
And I think that we are ready to move on to actually work with the database.
So let's do that in the next lecture.