Hello and welcome to this lecture.
And from this section onwards, we are actually going to learn some of the best practices which we need
to follow while we write any kind of python code.
Uh, so a lot of courses do not include this section on how to write effective Python code or how to
write clean code, which is understandable by others.
And according to me, this is one of the most important parts where you need to learn not only how to
write syntactically correct code, but also if you wish to work in an organization someday As a python
developer, you obviously need to know how to write clean python code.
So this is going to be an introductory lecture wherein we will learn why we need to write clean Python
code or effective Python code.
And from the next lecture onwards we are going to learn about the best practices about writing Python
code.
So I will be adding more and more lectures to this particular section as we move ahead for.
But for now we are going to cover some of the basic things which we need to remember while writing Python
code.
Okay, so let's get started with this particular lecture.
So I have laid out three reasons over here for writing clean Python code.
So the very first reason is that your code must actually be readable.
And what I mean by readable is that let's say if you are working in an organization as a python developer
and let's say you are working on a project where you need to design a certain functionality.
So for designing that particular functionality, you have to write a bunch of code which will include
a bunch of functions.
So let's say you have built one particular function which does a particular job.
So what happens is that when you collaborate with other programmers in your organization and when the
other programmer actually takes a look at your code, he must be able to identify what the particular
block of code does.
So if your code is not readable, that is, if your coworker is not able to understand what your code
actually does, then he might feel confused.
Then such kind of code is actually called as unreadable code.
So let's take an example of what a readable code and unreadable code looks like.
So let's take a simple example of adding two numbers.
So let's say you have to create a function for that.
So you type dev add.
Numbers.
And after that, let's go ahead and add two numbers up by passing them over here.
So that's going to be, let's say, A comma B, and let's say you add these two numbers and save it
into C, So as you could see by looking at this particular function, you could easily make out that
this thing actually performs the addition of two numbers.
But this is actually a simple example of function.
But in real life scenario, you actually need to go ahead and write a lot of complex functions.
And that's actually not going to be easy to identify what those functions actually do.
So in order to make your code readable, what you could do is that you could name your functions in
a proper way.
So what you could do is that you could define a function name such that the function name itself suggests
what the function actually does.
So, for example, as you could make out from the function name, that this function actually adds up
two numbers.
Now what if you actually name a function, something like, let's say function two.
So syntactically this function name is actually correct, but if your code actually contains some complex
things, then it absolutely becomes impossible for other person to determine what your function actually
does.
So instead of giving functions random names, you should always give suggestive names which suggest
what the function actually does.
So the proper name for this thing should be add numbers.
So this is one of the examples of why you should write a readable code.
So I hope you guys were able to understand this point over here.
Now let's go ahead and learn about collaboration.
So as I've earlier mentioned, if you are working in an organization, you do need to collaborate in
teams to write a particular software.
So each of your members will be working with a different piece of software or different piece of functionality
for a particular software wherein you have to write different lines of codes.
So when you work with people rather than working individually, only your code should not only be understandable
or readable by you, but also the other people who are working with you should also be able to read
your code.
So that is the main reason for writing readable code.
That is, other people understand it.
Obviously, as you have written your code, no matter how bad you wrote it, you will be able to understand
it because it is written by you.
But when some other person has a look at your code, he should be able to figure out what the code actually
does.
And that thing plays a crucial role when you collaborate in teams.
Now, the third most important point here for writing clean Python code is that the correct syntax is
not enough.
So even if you write some code which is syntactically correct, it doesn't necessarily mean that your
code is clean because as I earlier mentioned, you could name this function as anything and still it's
going to work.
But that does not mean that your code is clean.
So this was a basic introductory lecture on how to write clean Python code and why you should actually
write clean Python code.
And in the next lecture onwards, we are actually going to go into much more depth in this particular
concept because in order to become a professional python programmer or any programmer for that matter,
you do need to learn the art of writing clean and efficient code.
So thank you very much for watching and I'll see you guys next time.
Thank you.