Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Software Engineering In PHP
1. Software Engineering
In PHP
V1.0 - Prepared for Austin PHP
http://php.meetup.com/42/
Ralph Schindler - Zend
http://ralphschindler.com | http://zend.com
Josh Butts - Vertive
http://joshbutts.com | http://vertive.com
Wednesday, May 13, 2009 1
2. General Purpose
• These slides are for:
• Software “developers” with an interest in
becoming software “engineers”
• Engineers in other disciplines (Java, .NET, C#)
that want to draw parallels to PHP
• These slides are:
• An overview only, a means to pique interest
• More information can be found in the linked
provided with each slide
Wednesday, May 13, 2009 2
3. Contents
• Programming Languages
• Design Patterns
• Software Development & Best Practices
• PHP Ecosystem
Wednesday, May 13, 2009 3
5. Programming Languages
Paradigms
• Imperative vs. Declarative
• Object Oriented
• Class / Inheritance
• Prototype based
• Procedural
http://en.wikipedia.org/wiki/Programming_paradigms
http://en.wikipedia.org/wiki/Imperative_programming
http://en.wikipedia.org/wiki/Declarative_programming
http://en.wikipedia.org/wiki/Object-oriented_programming
http://en.wikipedia.org/wiki/Class-based_programming
http://en.wikipedia.org/wiki/Prototype-based_programming
http://en.wikipedia.org/wiki/Procedural_programming
Wednesday, May 13, 2009 5
6. Programming Languages
Typing
• Static vs. Dynamic
• Strong vs. Weak
• Duck Typing
http://en.wikipedia.org/wiki/Type_system
Wednesday, May 13, 2009 6
7. Programming Languages
Compiled vs. Scripting
• Compiled (machine code)
• c, c++
• Compiled (byte-code)
• Java, C# (.net)
• Scripting
• PHP, Ruby, Python, ECMAScript (Java /
Action)
http://en.wikipedia.org/wiki/Scripting_language
http://en.wikipedia.org/wiki/Compiled_language
http://en.wikipedia.org/wiki/Virtual_machine
http://en.wikipedia.org/wiki/Just-in-time_compilation
Wednesday, May 13, 2009 7
8. Programming Languages
PHP
• Scripting Language
• Virtual Machine: Zend Engine
• Written in C
• Multi-paradigm
• Imperative (procedural)
• Object-oriented (inheritance)
• Weak dynamic typing
http://en.wikipedia.org/wiki/Zend_Engine
http://en.wikipedia.org/wiki/PHP
Wednesday, May 13, 2009 8
9. Design Patterns
Building Blocks for Software
Wednesday, May 13, 2009 9
10. Design Patterns
Overview
• Applications
• Model 1
• Model 2
• Programming Patterns
• Architectural Patterns
http://en.wikipedia.org/wiki/Model_1
http://en.wikipedia.org/wiki/Model_2
http://en.wikipedia.org/wiki/Design_pattern_(computer_science)
http://en.wikipedia.org/wiki/Architectural_pattern_(computer_science)
Wednesday, May 13, 2009 10
11. Design Patterns
Model 1 vs. Model 2
• Coined in the Java world
• Model 1 apps are procedural applications
• TypicallyJSP pagesa series of scripts,
built as
original
• Model 2 apps arehave separation of and/or
tiered applications
applications that
concerns
http://en.wikipedia.org/wiki/Model_1
http://en.wikipedia.org/wiki/Model_2
http://en.wikipedia.org/wiki/Separation_of_concern
http://en.wikipedia.org/wiki/Separation_of_presentation_and_content
Wednesday, May 13, 2009 11
12. Design Patterns
Programming Patterns
• Most notable source: Gang
of Four
• Object oriented design
patterns
http://en.wikipedia.org/wiki/Design_Patterns_(book)
http://www.amazon.com/Design-Patterns-Object-Oriented-Addison-Wesley-Professional/dp/0201633612/
http://en.wikipedia.org/wiki/Design_pattern_(computer_science)
Wednesday, May 13, 2009 12
30. Software Development
Process
Best Practices for Building Software
Wednesday, May 13, 2009 30
31. Development Process
Overview
• Unit Testing
• Source Control
• Coding Standards
• Continuous Integration
• Documentation
http://en.wikipedia.org/wiki/Programming_style
http://martinfowler.com/articles/continuousIntegration.html
http://en.wikipedia.org/wiki/Unit_testing
http://en.wikipedia.org/wiki/Revision_control
Wednesday, May 13, 2009 31
32. Development Process
Unit Testing
• Why write unit tests?
• prevent regressions
• ensure software meets requirements
• tests help document what the software
does
• XUnit pattern
http://en.wikipedia.org/wiki/XUnit
Wednesday, May 13, 2009 32
33. Development Process
Source Control
• Why use source control?
• Keep track of changes you made
• Light-weight backup
• Great for collaboration, even if there is only
one of you now
• Common SCM (Source Code Management)
tools
http://subversion.tigris.org/
http://git-scm.com/
http://www.github.com
http://en.wikipedia.org/wiki/Distributed_revision_control
Wednesday, May 13, 2009 33
34. Development Process
Coding Standards
• Why have coding standards?
• readability for yourself and colleagues
• prevents mistakes, syntax errors
• Pear Coding Standards
• don't write your own standards, its not
worth your time
http://pear.php.net/pepr/pepr-proposal-show.php?id=426
http://pear.php.net/manual/en/standards.php
http://framework.zend.com/manual/en/coding-standard.html
Wednesday, May 13, 2009 34
35. Development Process
Build & Deploy
• Create a testable and repeatable deployment
process
• Run some functional tests
• document your application
• Code comments
• API Docs
http://cruisecontrol.sourceforge.net/
http://code.google.com/p/xinc/
http://www.atlassian.com/software/bamboo/
Wednesday, May 13, 2009 35
37. PHP Ecosystem
Application
Frameworks
• Application Framework
• Zend Framework
• toolkit / glue style: use what you want or use it all
• CakePHP & CodeIgnitor
• lightweight MVC frameworks with data models
• Symfony
• MVC, more admin and configuration features
http://framework.zend.com/
http://codeigniter.com/
http://cakephp.org/
http://www.symfony-project.org/
http://en.wikipedia.org/wiki/Web_application_framework
Wednesday, May 13, 2009 37
38. PHP Ecosystem
Unit Testing
Frameworks
• PHPUnit
• Most popular, derived from NUnit pattern
• Simpletest
• phpt
http://www.simpletest.org/
http://phpt.info/
http://en.wikipedia.org/wiki/Unit_testing
http://www.phpunit.de/
Wednesday, May 13, 2009 38
39. PHP Ecosystem
IDEs & Editors
• Editors
• pattern matched syntax highlighting & code folding
• typically multi-language
• especially good at text & code manipulation
• IDEs
• Language introspection (code completion)
• Errors / Warnings / Syntax Check
• Debugging capabilities (breakpoints, watches, profiling)
http://en.wikipedia.org/wiki/Comparison_of_text_editors
http://en.wikipedia.org/wiki/Integrated_development_environment
http://www.xdebug.org/
Wednesday, May 13, 2009 39
40. PHP Ecosystem
IDEs & Editors
• Eclipse-based IDEs
• Zend Studio (paid) / PDT (open source)
• great PHP editing and debugging
• Aptana
• javascript & css editing & code completion is excellent
• debugging with xdebug
• Text Editors
• Ultraedit on Windows
• Textmate on Mac
• “E” is Textmate on Windows
http://www.zend.com/en/products/studio/
http://www.eclipse.org/pdt/
http://www.ultraedit.com/
http://www.aptana.com
http://www.macromates.com
Wednesday, May 13, 2009 40