Get startedGet started for free

Software engineering principles

1. Software engineering principles

Now that you've built the foundations of the calculator, it's time to refresh some important principles your coding needs to follow.

2. Roadmap

Let's especially focus on the modularity and the "Don't Repeat Yourself" principle.

3. Modularity

One of the core principles in software engineering is modularity - breaking a system down into distinct, independent modules. Each module is designed to handle a specific functionality and connects with other modules through well-defined interfaces. This modular structure makes development and testing more manageable and organized. You'll apply modularity to structure your project, keeping your code neat, simplifying development, and making testing more efficient.

4. The DRY principle

Another key principle is DRY, or "Don't Repeat Yourself." It's all about minimizing repetition by creating reusable components for common functionalities. Think of it like writing a recipe once and sharing it instead of rewriting it every time. DRY keeps your code clean, maintainable, and less prone to errors. In this project, you'll use object-oriented programming (OOP) to ensure your code follows the DRY principle.

5. Packaging

Packages are another crucial concept in software engineering. They help you group related modules into a single, organized folder structure. By reusing packages, you naturally apply the DRY principle, reducing redundancy in your code. It also helps your code to be modular. A package is defined by an `__init__.py` file, which distinguishes it from a regular folder. In this project, you'll take your mortgage calculator and turn it into a Python package!

6. Building a package

A minimal Python package includes a folder and a Python file. By convention, name the package folder using short, lowercase words separated by underscores. The folder must also contain an `__init__.py` file, signaling to Python that it's a package. You'll follow these conventions to organize your code.

7. Absolute and relative imports

Python offers two types of imports: absolute and relative. Imagine your file structure: at the project level, there is `main.py` and a package containing `module1.py` and `module2.py`. With absolute imports, you use the full path from the root directory. For example, to import `module1.py` into `main.py`, you'd write `from package import module1`. Similarly, you can just import a single function. Relative imports are based on the location of the current file. A single dot refers to the current package, while two dots refer to the parent package. For instance, to import `module1.py` into `main.py`, you’d write `from . import module1`. Relative imports are particularly useful within modules of the same package. Absolute imports are clear and straightforward but might reduce portability. Relative imports are more flexible, however they depend on the context of the file. You'll use these import strategies to keep your file structure organized.

8. Let's practice!

Let's apply these principles to your work at PyBank!