Readable code 🔍
Watch the result of this project >> here
🎯 Objectives
- To be able to make decisions about when and how to refactor less readable code.
- To be able to adhere to known PHP code standards like PSR12.
- To be able to think critically about code principles and not follow them blindly.
✔️ Specifications
🌱 Must-haves
- Have a look at this code and try to understand what it does.
- Read the following article Jason McCreary on writing clean code
- Have the code follow a consistent writing standard. For now, we'll roll with the widely used PSR12.
- Rewrite the file in a way that would improve readability for you.
- Don't install PHP codesniffer (yet).
- When you are done, discuss your solution in groups of two.
💡 Tips
- Don't aim for perfect all the time, aim for good enough / continuous improvement.
- When refactoring, focus on one section (or one thing) first (e.g. a specific function or clear naming).
- Work in small steps. Write these as separate to-do's if you like. Test after every step and use small commits when you're sure everything still works.
- When in doubt what approach is better, think "what would help me to understand this quickly if I see it again a year from now".
- Be critical: if you think a certain tip isn't beneficial to your code, ignore or tweak it.
- When getting used to a standard, don't jump to auto-rewrites immediately. Get used to write code following the standard yourself first.
📖 Further reading
- Base Code field guide (paid, but first chapters are free)
- PHP code sniffer + (your IDE: PHPStorm, VScode, ...)
- Code style guide of your company