190R6 Writing Readable Code

Making code readable is fundamental for development

  • it is key to maintainability
    • by yourself
    • by others
  • working together with a team

PEAR Coding Standard

The PEAR (PHP Extension & Application Repository) Coding Standard is just one standard method of encouraging different programmers, of PHP in this case, to work to a common standard so their code can be easily shared. There is a list of their standards here

WikiText

Even for comparatively simple documentation, Wikipedia has its own published standards and procedures

Good Practice

  1. Commenting & Documentation
    1. Avoid Obvious Comments
  2. Consistent Indentation
  3. Code Grouping
    1. Separation of Code and Data
  4. Consistent Naming Scheme
    1. using Case & camelCase naming schemes
    2. Capitalize SQL and Special Words
    3. Consistent Temporary Names
    4. Use Meaningful Names for Variables and Functions
  5. DRY Principle
  6. Avoid Deep Nesting
  7. Limit Line Length
  8. File and Folder Organisation
  9. Object-Oriented vs. Procedural (organisation)
  10. Avoid Using Magic Numbers (constants)
  11. Code Refactoring
  12. Using IDEs with colour coding
Ex 1
  1. Find 3 examples of different styles of writing comments
  2. Create names for 6 variables you could use when programming an ecommerce store
  3. What is the difference between Python and other languages in terms of indentation