Docsity

Best Practices di Sviluppo PHP: Codice, Documentazione e Collaborazione, Appunti di Programmazione Avanzata

Anteprima parziale del testo

Scarica Best Practices di Sviluppo PHP: Codice, Documentazione e Collaborazione e più Appunti in PDF di Programmazione Avanzata solo su Docsity!

Mike Naberezny Principal Maintainable Software

Best Practices of

PHP Development

Matthew Weier O’Phinney PHP Developer Zend Technologies

About Us

 PHP Developer, Zend Technologies

  • Production site maintenance and deployment
  • Internal web services
  • Zend Framework contributor

 Open Source Contributor

• PEAR
  • Cgiapp
  • Solar Matthew Weier O’Phinney

About You

 Can you read your own code?^ Can others?
 Is your software documented?
 More importantly, is your software tested?
 Are you using source control?
 Does your team work efficiently?
 Do you push buggy software into production?

Agenda

 Programming
  • Coding Standards
  • Documentation
  • Testing
 Tools and Processes
  • Collaboration
  • Source Control
  • Deployment

 Q&A

Programming

Coding Standards

Coding Standards

Focus on code, not formattingConsistencyReadabilityCollaboration

Coding Standards

 Popular Library

 Issues have already been debated

 Well known and accepted (more than any other)

 Basis for many open source PHP projects

  • Horde*
  • Solar
  • Zend Framework

PEAR Coding Standard

  • The PEAR coding standard was largely adopted from Horde.
  • Chuck Hagenbuch, Founder of the Horde project

Coding Standards

 Class names are CamelCased, with an initial cap,

using underscores to separate logical package and code boundaries:

  • Spreadsheet_Excel_Writer
  • Services_Google_AdWords

Naming Conventions

Coding Standards

 Variable names are camelCased, with the initial

character lowercased

 Constant names are ALL_CAPS with underscores

for word separators

 Private methods and properties are prefixed with

an _underscore

Naming Conventions

Coding Standards

 One True Brace

  • Functions and Classes have the opening brace on the line following the declaration, at the same indent level
  • Control structures keep the opening brace on the same line as the declaration

 Indentation

  • Spaces only; no tabs
  • Four (4) spaces per level of indentation
  • Purpose is consistency of viewing

Design Patterns

 Reusable ideas, not code

 Proven solutions to common design problems

 Better communication through shared vocabulary

Programming

Documentation

Source Documentation

 phpDocumentor tags are the most used standard for

generating documentation from PHP source code.

 Uses annotation tags in source comments very similar to

those used by Javadoc.

 Other documentation generators, such as Doxygen, support

these same tags. Don’t invent your own tags.

 Supported by a number of different IDEs.^ Zend Studio is

perhaps the most prevalent.

phpDocumentor http://phpdoc.org

Source Documentation

Completely Undocumented (is your’s like this?)