Table des matières
- Partie 1
Write Clear Code Using PEP 8 Guidelines
- Partie 2
Solve Common Programming Problems With Design Patterns in Python
- 1
Build Complex Systems With the Help of Design Patterns
- 2
Avoid Confusion With the Constant Design Pattern
- 3
Create Flexible Functions With the Decorator Design Pattern
- 4
Structure an Application With the MVC Design Pattern
- 5
Implement the Model for Your Application
- 6
Implement the Controller and View for Your Application
Quiz : Solve Common Programming Problems With Design Patterns in Python
- Partie 3
Apply the SOLID Principles to Python Code
- 1
Discover Good Programming Practices With the SOLID Principles
- 2
"S" for the Single Responsibility Principle
- 3
"O" for the Open/Closed Principle
- 4
"L" for the Liskov Substitution Principle
- 5
"I" for the Interface Segregation Principle
- 6
"D" for the Dependency Inversion Principle
- 7
Avoid STUPID Practices in Programming
Quiz : Apply the SOLID Design Principles to Python Code
- Partie 4
Congratulations!
Use Linters to Keep Your Code Tidy
If I make a typo or a grammar mistake while writing this paragraph, the text editor highlights it so I can correct it. It doesn’t find all my mistakes. I could write nonsense about how snakes invented the Python language, and it wouldn’t notice! 🐍 But at least it ensures that I’m using correct English.
Wouldn’t it be useful if something like that existed for the Python language?
There is! It’s called a linter and finds places in your code where you aren’t conforming to PEP 8. Then it’s up to you to fix those issues (or in some instances, you might be breaking PEP 8 intentionally, in which case you would ignore some of the linter’s output).
It doesn’t check whether your Python code will run correctly or as expected. It’s a spell checker that doesn’t verify your facts. But it will prevent you from running into the problems we’ve been looking at in the previous three chapters.
Using a Linter
Some editors have linters built in. There are also free online ones.
They’re super easy to use, so let’s take a look!
Try It Yourself!
Download this file - it’s the same one that you saw in the video - and run it through a linter. There will be lots of errors! The Python code is correct, but it doesn’t respect PEP 8 yet.
Fix all the errors you can find, and then keep running it through the linter until it no longer finds any errors.
If you get stuck, you can compare it to the solution.
Let’s Recap!
A linter is an automated tool that warns you when your code is not PEP 8-compliant.
Linters don’t find all your programming mistakes but only the main style recommendations of PEP 8.
Test your understanding of PEP 8 with the following quiz! In the next part of the course, you’ll learn how using design patterns to structure your programs can keep them maintainable.
- Formations jusqu’à 100 % financées
- Date de début flexible
- Projets professionnalisants
- Mentorat individuel