Improving Code Quality
Contents
Improving Code Quality#
Goal#
The goal of this project is to enhance the code quality of the scripts written for the core exercises. Specifically, the aim is to ensure that the code is readable, maintainable, and thoroughly tested.
Principle#
Code quality refers to the overall level of excellence and maintainability of a software project. High-quality code is easy to read, understand, and modify, which makes it easy to maintain and improve over time. In contrast, poor quality code is difficult to work with and can be a source of unexpected bugs and frustration for developers.
There are several factors that contribute to code quality, including:
Readability: Code should be easy to read and understand, even for developers who are not familiar with the project. This can be achieved through the use of descriptive names, clear formatting, and well-written comments.
Maintainability: Code should be easy to maintain and modify, which means it should be organized in a logical manner and should not have too many dependencies.
Test coverage: Code should be thoroughly tested to ensure that it is reliable and free of bugs. This can be achieved through the use of automated tests.
Performance: Code should be efficient and should not consume too many resources.
Improving code quality is an ongoing process that requires continuous attention and effort. In this project, we will focus specifically on documentation and automated testing. You will learn to use various tools and techniques to help improve the overall quality of your future projects.
Implementation details#
For this project, you will be using the following tools:
Doctest: Include inline examples in the form of doctest in the docstrings of the functions.
Pytest: Write unit tests for the functions using the pytest framework.
Mock: Write functional tests for the functions using the mock library to simulate external dependencies.
You will implement your modifications directly in the scripts written for the core exercises. In addition to modifying the existing code, you will also need to create dedicated test scripts for each exercise or library, named according to the associated library or exercise, such as test_lib_*.py
or test_ex*.py
.
Finally, you will generate a Code Coverage report using the pytest-cov
plugin, to show the percentage of the code that is covered by the tests.
A step-by-step guide, explaining in detail how to test your code, is available here.
Expected Result#
The expected outcome of this project is a set of scripts written for the core exercises that are well-documented, modular, and thoroughly tested. Thereby, the code should be more readable, maintainable, and less prone to bugs. Additionally, the use of code coverage reports will ensure that the code is being tested effectively.