It's happening.
Our next developer fundamentals and that is what is good code.
I mean, what is good that seems so vague, right?
Like when somebody says I'm a good coder, I'm an excellent programmer, he's a senior programmer,
he's an expert programmer.
He's a tech lead.
He's a genius.
What what does that really mean?
Well, you can narrow it down to these simple statements.
What is clean, good code?
I kind of gave it away.
The first one is clean.
That is, we want to make sure our code is following a style that, let's say the Python community endorses.
Are we following the best practices?
And Python has this great feature of format, and Python has standard ways of using spaces to make sure
that our code is clean.
I'm not using unnecessarily ugly spaces like this, or maybe making lists really weird and funky.
Maybe no spaces in between here.
Maybe.
I have a lot of random comments over here.
We're keeping our code clean.
We make sure that every line that we have is easily readable, but also we don't have any extra stuff
that we don't need in there.
And this also relates to the idea of readability.
Now, readability means the ability to want to read your own code.
Maybe two years down the road, you're going to come back and look at the code.
Are you going to be able to understand it?
If you work in teams or for companies and other coworkers, come and look at your code.
Is it easy to understand?
And here this is obviously personal preference, but most of the time the ideas are are simple.
For example, I'm using names here that make sense.
If I had variable names that don't make sense, it'll be really hard for somebody to read my code.
Maybe people will be confused why I have this print statement here.
In that case, maybe I should comment in here being like need a new line after every row.
Or maybe they'll be confused why we need this as well.
So.
Depending on your style, you might want to add comments.
Make sure that the naming of your variables are good, and maybe making sure that it's not only you
that understands the code.
The other one is the idea of predictability.
And this is my favorite one.
That is, sometimes people try to be really clever with their code, trying to have the most compact
code or using the newest features or some really obscure tools that or functions that are not very common
just to look, well, frankly smart.
But you want to have code that makes sense, that does things just one thing really well.
Now this code is quite small, so it's quite predictable, you know, it just has one pass through and
it's easy to predict what's going to happen.
We're going to print, but as we get more and more into the course, you'll see that our code is going
to get larger and larger.
And having predictable, easy to understand code is really important.
And then finally, this is an important principle that you're hear everywhere is d r y do not repeat
yourself.
You don't want to have code that you're constantly repeating yourself over and over again.
This is a small example, but it's very easy as a programmer to say, Oh, I'm going to copy this and
then I'm going to run this again so that if I click Run.
Look at that.
I have two trees now.
This is amazing.
But maybe that's not the best idea.
You now have 28 lines of code and people might be confused why we're doing this twice.
Maybe instead, we want to programmatically have a counter here of maybe saying running this twice or
maybe using something like functions, which we'll learn later to make sure that we can repeat this
process over and over and over.
Now keep these in the back of your mind because throughout the course we're going to explore these topics.
But let's say I just came on to this code, and I want you to clean it up a bit.
Again, this is just personal preference, but these are some of the things that I would do.
One is here pixels equal to one.
Instead, this is kind of confusing.
I'm just going to say if there is a pixel here and I know that pixels are either a zero on one, then
print here because this is a true value that will just evaluate to true.
So that just kind of cleaned out my code a little bit better.
Next, another thing that I might do, maybe I want to make this more extensible, which might mean
doing something like let's say fill variable that equals to the star and then maybe empty, which equals
to an empty string and change these to fill.
And empty.
Now, this is extra line of code.
But for example, if we're doing this multiple times instead of perhaps, maybe we're running print
over and over and over, or maybe we have another line of print over here.
And another line of print over here and then maybe another line of print over here that is empty.
Instead of me having to change five locations here, I can now change just this part.
And maybe instead of Star, I want to display, I don't know, dollar sign.
And if I run this.
All right.
I get a little different image here.
But again, I was able to just change the variable and the variable was used to fill out whatever I
needed done.
Now, these are all things that you do need a bit of experience to get used to, but we'll hopefully
explore this throughout the course, and by the end of it you'll have all these best practices in mind.
I'll see you in the next one.
Bye bye.