Software Engineering In PHP

40
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 1 Wednesday, May 13, 2009
  • date post

    17-Oct-2014
  • Category

    Technology

  • view

    12.676
  • download

    4

description

Software Engineering In PHP

Transcript of Software Engineering In PHP

Page 1: Software Engineering In PHP

Software EngineeringIn PHP

V1.0 - Prepared for Austin PHPhttp://php.meetup.com/42/

Ralph Schindler - Zendhttp://ralphschindler.com | http://zend.com

Josh Butts - Vertivehttp://joshbutts.com | http://vertive.com

1Wednesday, May 13, 2009

Page 2: Software Engineering In PHP

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

2Wednesday, May 13, 2009

Page 3: Software Engineering In PHP

Contents

• Programming Languages

• Design Patterns

• Software Development & Best Practices

• PHP Ecosystem

3Wednesday, May 13, 2009

Page 4: Software Engineering In PHP

Programming Languages Language Features & Paradigms

4Wednesday, May 13, 2009

Page 5: Software Engineering In PHP

Paradigms

• Imperative vs. Declarative

• Object Oriented

• Class / Inheritance

• Prototype based

• Procedural

Programming Languages

http://en.wikipedia.org/wiki/Programming_paradigmshttp://en.wikipedia.org/wiki/Imperative_programminghttp://en.wikipedia.org/wiki/Declarative_programming

http://en.wikipedia.org/wiki/Object-oriented_programminghttp://en.wikipedia.org/wiki/Class-based_programming

http://en.wikipedia.org/wiki/Prototype-based_programminghttp://en.wikipedia.org/wiki/Procedural_programming

5Wednesday, May 13, 2009

Page 6: Software Engineering In PHP

Typing

• Static vs. Dynamic

• Strong vs. Weak

• Duck Typing

Programming Languages

http://en.wikipedia.org/wiki/Type_system

6Wednesday, May 13, 2009

Page 7: Software Engineering In PHP

Compiled vs. Scripting• Compiled (machine code)

• c, c++

• Compiled (byte-code)

• Java, C# (.net)

• Scripting

• PHP, Ruby, Python, ECMAScript (Java / Action)

Programming Languages

http://en.wikipedia.org/wiki/Scripting_languagehttp://en.wikipedia.org/wiki/Compiled_language

http://en.wikipedia.org/wiki/Virtual_machinehttp://en.wikipedia.org/wiki/Just-in-time_compilation

7Wednesday, May 13, 2009

Page 8: Software Engineering In PHP

PHP• Scripting Language

• Virtual Machine: Zend Engine

• Written in C

• Multi-paradigm

• Imperative (procedural)

• Object-oriented (inheritance)

• Weak dynamic typing

Programming Languages

http://en.wikipedia.org/wiki/Zend_Enginehttp://en.wikipedia.org/wiki/PHP

8Wednesday, May 13, 2009

Page 9: Software Engineering In PHP

Design PatternsBuilding Blocks for Software

9Wednesday, May 13, 2009

Page 10: Software Engineering In PHP

Overview

• Applications

• Model 1

• Model 2

• Programming Patterns

• Architectural Patterns

Design Patterns

http://en.wikipedia.org/wiki/Model_1http://en.wikipedia.org/wiki/Model_2

http://en.wikipedia.org/wiki/Design_pattern_(computer_science)http://en.wikipedia.org/wiki/Architectural_pattern_(computer_science)

10Wednesday, May 13, 2009

Page 11: Software Engineering In PHP

Model 1 vs. Model 2• Coined in the Java world

• Model 1 apps are procedural applications

• Typically built as a series of scripts, original JSP pages

• Model 2 apps are tiered applications and/or applications that have separation of concerns

Design Patterns

http://en.wikipedia.org/wiki/Model_1http://en.wikipedia.org/wiki/Model_2

http://en.wikipedia.org/wiki/Separation_of_concernhttp://en.wikipedia.org/wiki/Separation_of_presentation_and_content

11Wednesday, May 13, 2009

Page 12: Software Engineering In PHP

Programming Patterns

• Most notable source: Gang of Four

• Object oriented design patterns

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)

12Wednesday, May 13, 2009

Page 13: Software Engineering In PHP

Example: FactoryDesign Patterns / Software Patterns

http://en.wikipedia.org/wiki/Factory_method_patternhttp://en.wikipedia.org/wiki/Creational_pattern

13Wednesday, May 13, 2009

Page 14: Software Engineering In PHP

Example: Lazy LoadingDesign Patterns / Software Patterns

http://en.wikipedia.org/wiki/Lazy_initialization_pattern

14Wednesday, May 13, 2009

Page 15: Software Engineering In PHP

Example: SingletonDesign Patterns / Software Patterns

http://en.wikipedia.org/wiki/Singleton_pattern

15Wednesday, May 13, 2009

Page 16: Software Engineering In PHP

Example: CompositeDesign Patterns / Software Patterns

http://en.wikipedia.org/wiki/Composite_patternhttp://devzone.zend.com/node/view/id/7

16Wednesday, May 13, 2009

Page 17: Software Engineering In PHP

Example: AdapterDesign Patterns / Software Patterns

http://en.wikipedia.org/wiki/Adapter_pattern

17Wednesday, May 13, 2009

Page 18: Software Engineering In PHP

Example: ObserverDesign Patterns / Software Patterns

http://en.wikipedia.org/wiki/Observer_patternhttp://www.php.net/~helly/php/ext/spl/

18Wednesday, May 13, 2009

Page 19: Software Engineering In PHP

Programming Patterns

• Most notable source: Martin Fowler

• PoEAA: Patterns of Enterprise Application Architecture

Design Patterns

http://en.wikipedia.org/wiki/Architectural_pattern_(computer_science)http://martinfowler.com/eaaCatalog/

http://www.amazon.com/Enterprise-Application-Architecture-Addison-Wesley-Signature/dp/0321127420/

19Wednesday, May 13, 2009

Page 20: Software Engineering In PHP

Non-PoEAA

• Presentation-abstraction-control

• Service-oriented architecture (distributed)

• Mulit/Three-Tier

• Peer-to-Peer (distributed)

Design Patterns / Architectural Patterns

http://en.wikipedia.org/wiki/Presentation-abstraction-controlhttp://en.wikipedia.org/wiki/Service-oriented_architecture

http://en.wikipedia.org/wiki/Three-tier_(computing)http://en.wikipedia.org/wiki/Peer-to-peer

20Wednesday, May 13, 2009

Page 21: Software Engineering In PHP

PoEAA• Logical: Domain Model & Table Module

• Data: Table Row & Row Data Gateway, ActiveRecord, Data Mapper

• Other:

• Repository, Registry, Plugin

• Model-View-Controller, Front Controller, Two-step View

Design Patterns / Architectural Patterns

http://martinfowler.com/eaaCatalog/http://en.wikipedia.org/wiki/Active_record_pattern

21Wednesday, May 13, 2009

Page 22: Software Engineering In PHP

Example: Domain Model

http://en.wikipedia.org/wiki/Domain_Model

http://martinfowler.com/eaaCatalog/domainModel.html

Design Patterns / Architectural Patterns

22Wednesday, May 13, 2009

Page 23: Software Engineering In PHP

Example: Table Module

http://martinfowler.com/eaaCatalog/tableModule.html

Design Patterns / Architectural Patterns

23Wednesday, May 13, 2009

Page 24: Software Engineering In PHP

Example: Table GatewayDesign Patterns / Architectural Patterns

http://martinfowler.com/eaaCatalog/tableDataGateway.html

24Wednesday, May 13, 2009

Page 25: Software Engineering In PHP

Example: Row GatewayDesign Patterns / Architectural Patterns

http://martinfowler.com/eaaCatalog/rowDataGateway.html

25Wednesday, May 13, 2009

Page 26: Software Engineering In PHP

Example: Active RecordDesign Patterns / Architectural Patterns

http://martinfowler.com/eaaCatalog/activeRecord.html

http://en.wikipedia.org/wiki/Active_record_pattern

26Wednesday, May 13, 2009

Page 27: Software Engineering In PHP

Example: Active RecordDesign Patterns / Architectural Patterns

http://martinfowler.com/eaaCatalog/activeRecord.html

http://en.wikipedia.org/wiki/Active_record_pattern

27Wednesday, May 13, 2009

Page 28: Software Engineering In PHP

Example: MVCDesign Patterns / Architectural Patterns

http://en.wikipedia.org/wiki/Model-view-controller

http://martinfowler.com/eaaCatalog/modelViewController.html

28Wednesday, May 13, 2009

Page 29: Software Engineering In PHP

Example: RegistryDesign Patterns / Architectural Patterns

http://martinfowler.com/eaaCatalog/registry.html

29Wednesday, May 13, 2009

Page 30: Software Engineering In PHP

Software Development Process

Best Practices for Building Software

30Wednesday, May 13, 2009

Page 31: Software Engineering In PHP

Development Process

http://en.wikipedia.org/wiki/Programming_stylehttp://martinfowler.com/articles/continuousIntegration.html

http://en.wikipedia.org/wiki/Unit_testinghttp://en.wikipedia.org/wiki/Revision_control

Overview

• Unit Testing

• Source Control

• Coding Standards

• Continuous Integration

• Documentation

31Wednesday, May 13, 2009

Page 32: Software Engineering In PHP

Development Process

http://en.wikipedia.org/wiki/XUnit

Unit Testing

• Why write unit tests?

• prevent regressions

• ensure software meets requirements

• tests help document what the software does

• XUnit pattern

32Wednesday, May 13, 2009

Page 33: Software Engineering In PHP

Development Process

http://subversion.tigris.org/http://git-scm.com/

http://www.github.comhttp://en.wikipedia.org/wiki/Distributed_revision_control

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

33Wednesday, May 13, 2009

Page 34: Software Engineering In PHP

Development Process

http://pear.php.net/pepr/pepr-proposal-show.php?id=426http://pear.php.net/manual/en/standards.php

http://framework.zend.com/manual/en/coding-standard.html

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

34Wednesday, May 13, 2009

Page 35: Software Engineering In PHP

Development Process

http://cruisecontrol.sourceforge.net/http://code.google.com/p/xinc/

http://www.atlassian.com/software/bamboo/

Build & Deploy

• Create a testable and repeatable deployment process

• Run some functional tests

• document your application

• Code comments

• API Docs

35Wednesday, May 13, 2009

Page 36: Software Engineering In PHP

PHP EcosystemSoftware & Tools

36Wednesday, May 13, 2009

Page 37: Software Engineering In PHP

PHP Ecosystem

http://framework.zend.com/http://codeigniter.com/

http://cakephp.org/http://www.symfony-project.org/

http://en.wikipedia.org/wiki/Web_application_framework

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

37Wednesday, May 13, 2009

Page 38: Software Engineering In PHP

PHP Ecosystem

http://www.simpletest.org/http://phpt.info/

http://en.wikipedia.org/wiki/Unit_testinghttp://www.phpunit.de/

Unit Testing Frameworks

• PHPUnit

• Most popular, derived from NUnit pattern

• Simpletest

• phpt

38Wednesday, May 13, 2009

Page 39: Software Engineering In PHP

PHP Ecosystem

http://en.wikipedia.org/wiki/Comparison_of_text_editorshttp://en.wikipedia.org/wiki/Integrated_development_environment

http://www.xdebug.org/

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)

39Wednesday, May 13, 2009

Page 40: Software Engineering In PHP

PHP Ecosystem

http://www.zend.com/en/products/studio/http://www.eclipse.org/pdt/http://www.ultraedit.com/http://www.aptana.com

http://www.macromates.com

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

40Wednesday, May 13, 2009