Code Quality

Hello! It has been a while since I wrote the last post. During winter break I relaxed and spent time with my family. During today’s post, we will take a look at clean code and code smells. I think that I will specifically look at this from the perspective of Python, my favorite and most practiced language.

Writing clean code in Python is potentially easier than other languages. Python was written to be easily readable, so through this we can organize the code in a way that is very clean. There are also several libraries that we can use in order to clean up our code, including linting and other methods.

For clean code, I took a look at an article written by other developers. More or less, much of the article went over the basics of writing clean code, which we were taught many times over during school. These basics include proper variable naming, descriptive naming, commenting code, and more. I don’t find this to be particularly revolutionary, but Python on it’s own is a fairly clean language, being high level, so it is pretty clean out of the box. Developers can put in extra effort to have their code even cleaner!

Another aspect that we will look at will be code smells. This is something that a developer will become familiar with later on in their journey, once they start learning multiple ways they can complete a particular task; there’s always a more efficient and safer way to do something. Code smells are essentially when a code has something wrong with it, even if it technically works.

I took a look at this article about code smells in Python. The beginning of this article confirmed my current beliefs about what a code smell is. It covered basics of code smells, including some very common ones which beginners might do. Some of these include duplicate code, using numbers instead of defining constants, dead code, and forgetting to remove print statements for debugging.

All in all, I think that these topics are not something you can sit down and learn, but something that you practice over time. Nobody is perfect at writing clean code and eliminating code smells, so there’s always room for improvement!

Happy coding.

–Mitch

Print Friendly, PDF & Email

Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *