It's happening.
Our next developer of 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 lets say the Python community endorses.
Are we following the best practices and Python has this great feature of auto 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 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 gonna be able to understand it if you work in teams or for companies and other co-workers common
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 I'll be really hard for somebody to read my code.
Maybe these people would 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 a 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 would 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 here everywhere is the heart.
Why 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 wanted 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 truth value that we'll just evaluate to true.
So that just kind of cleaned up 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 say film 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 in the next one.