Good Practice
in PHP
2
About Me
● Lorna Mitchell
● Twitter: @lornajane
● PHP consultant, trainer, and writer
● I live in Leeds
● Website: http:...
3
Today's Outline
● Software Development Lifecycle
● Databases
● Source Control
● Documentation
● Open Source
4
Software Lifecycles
5
Waterfall
6
Waterfall
7
Agile
● Many different interpretations
● Some or all of:
● iterative
● customer involvement
● product is always working
...
8
Extreme Programming
● Wildly fashionable a few years ago
● Useful ideas
● Pair programming
● Code for today (and refacto...
9
Databases
10
Databases
● Not a dumping ground
● Often your application bottleneck
● Worth understanding
11
Tools
● phpMyAdmin
● http://phpmyadmin.net
● Command Line
● powerful
● well-documented
12
Normalised Forms
● Guidelines for good table design
●
1st
Normal Form
● no repeating groups (e.g. comma separated lists...
13
Indices
● MySQL uses indexes to quickly find things
● Foreign key contstraints
● Columns used in where clauses
14
EXPLAIN
● MySQL command
● Which indexes are used
● What kind of indexes
● Number of rows scanned
● Great for diagnosing...
15
Source Control
16
Using Source Control
● Create a repository, add project
● Check out project
● Make changes
● Update to get other change...
17
svn log
­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
r3 | lornajane | 2010­04­25 10:32:09 +...
18
svn diff
Index: README.txt
===================================================================
--- README.txt (revision...
19
Source Control Tools
● Subversion (svn)
● http://subversion.apache.org/
● Git (git)
● http://git-scm.com/
● Bazaar (bzr...
20
Accessing Source Control
● IDE Plugins
● Trac (http://trac.edgewall.org/)
● TortoiseSVN
● TortoiseGit
● TortoiseBzr
● T...
21
Centralised Source Control
user
repo
user
user
user
22
Centralised Source Control
● Single repo (repository)
● Always commit to central
● Can branch centrally
23
Distributed Source Control
repo
repo
repo
repo
repo
24
Distributed Source Control
● Many repos
● Commit to local repo
● Share changes between anywhere
● No central point
25
What If I Don't Have Source
Control?
● Get some :)
● Install subversion
● Use a hosted solution
26
Documentation
27
API Docs
● Documentation generated from source code
itself
● Follows code structure
● classes
● inheritance
● methods
●...
28
PHPDocumentor
29
PHPDocumentor
● PHPDocumentor
● http://www.phpdoc.org/
● Uses reflection
● Comments for additional information
● Add de...
30
PHPDocumentor Comments
1 <?php
2
3 class AttendeeList {
4 private $attendees;
5 private $observers;
6
7 /**
8 * Add an ...
31
Beyond API Docs
● Tutorials
● Installation instructions
● Examples
● FAQs
● Forums
● User-contributed
32
Today's Outline
● Software Development Lifecycle
● Databases
● Source Control
● Documentation
● Open Source
33
Other Topics
● System administration
● Maintenance and bugs
● Design patterns
34
Open Source
35
Open Source
● Free software
● Free as in beer
● Free as in freedom
● Licensing
● BSD
● GPL
● Avoid reinventing the wheel
36
Open Source
● You get what you give
● Participate!
37
The Local PHP Scene
● LeedsPHP http://leedsphp.org
● PHPNW http://phpnw.org.uk
● GeekUp http://geekup.org
38
Questions?
39
Good Luck
for your Future!
Upcoming SlideShare
Loading in …5
×

Goodpractice

2,292
-1

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
2,292
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
10
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Goodpractice

  1. 1. Good Practice in PHP
  2. 2. 2 About Me ● Lorna Mitchell ● Twitter: @lornajane ● PHP consultant, trainer, and writer ● I live in Leeds ● Website: http://lornajane.net
  3. 3. 3 Today's Outline ● Software Development Lifecycle ● Databases ● Source Control ● Documentation ● Open Source
  4. 4. 4 Software Lifecycles
  5. 5. 5 Waterfall
  6. 6. 6 Waterfall
  7. 7. 7 Agile ● Many different interpretations ● Some or all of: ● iterative ● customer involvement ● product is always working ● done in bursts called "sprints" ● spec can change (in a controlled way)
  8. 8. 8 Extreme Programming ● Wildly fashionable a few years ago ● Useful ideas ● Pair programming ● Code for today (and refactor) ● TDD (Test Driven Development) ● Planning poker ● Acceptance tests
  9. 9. 9 Databases
  10. 10. 10 Databases ● Not a dumping ground ● Often your application bottleneck ● Worth understanding
  11. 11. 11 Tools ● phpMyAdmin ● http://phpmyadmin.net ● Command Line ● powerful ● well-documented
  12. 12. 12 Normalised Forms ● Guidelines for good table design ● 1st Normal Form ● no repeating groups (e.g. comma separated lists) ● 2nd Normal Form ● decouples entities and links them by relationship (e.g. customer data separate from order) ● 3rd Normal Form <- good enough! ● removes redundancy and dependent information
  13. 13. 13 Indices ● MySQL uses indexes to quickly find things ● Foreign key contstraints ● Columns used in where clauses
  14. 14. 14 EXPLAIN ● MySQL command ● Which indexes are used ● What kind of indexes ● Number of rows scanned ● Great for diagnosing slow queries
  15. 15. 15 Source Control
  16. 16. 16 Using Source Control ● Create a repository, add project ● Check out project ● Make changes ● Update to get other changes ● Commit changes to repo
  17. 17. 17 svn log ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ r3 | lornajane | 2010­04­25 10:32:09 +0100 (Sun, 25 Apr 2010) | 1 line adding documentation notes ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ r2 | lornajane | 2010­04­22 09:07:56 +0100 (Thu, 22 Apr 2010) | 1 line outlining source control and design patterns sections ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ r1 | weierophinney | 2010­03­30 17:37:27 +0100 (Tue, 30 Mar 2010) | 1 lin Added readme with outline ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
  18. 18. 18 svn diff Index: README.txt =================================================================== --- README.txt (revision 3) +++ README.txt (revision 4) @@ -31,12 +35,20 @@ to share ideas to raise profile to be told you're doing it wrong! + (pulling up examples off our own blogs, if connection allows) Testing (Matthew) QA tools and CI including code analysis, mess detection, etc (Lorna - QA tools; Matthew - CI) + Static analysis + code sniffer + demo examples, find a suitable small codebase (joindin?) + mess detector + demo examples + what else? + Deployment
  19. 19. 19 Source Control Tools ● Subversion (svn) ● http://subversion.apache.org/ ● Git (git) ● http://git-scm.com/ ● Bazaar (bzr) ● http://bazaar.canonical.com/ ● Mercurial (hg) ● http://mercurial.selenic.com/
  20. 20. 20 Accessing Source Control ● IDE Plugins ● Trac (http://trac.edgewall.org/) ● TortoiseSVN ● TortoiseGit ● TortoiseBzr ● TortoiseHg
  21. 21. 21 Centralised Source Control user repo user user user
  22. 22. 22 Centralised Source Control ● Single repo (repository) ● Always commit to central ● Can branch centrally
  23. 23. 23 Distributed Source Control repo repo repo repo repo
  24. 24. 24 Distributed Source Control ● Many repos ● Commit to local repo ● Share changes between anywhere ● No central point
  25. 25. 25 What If I Don't Have Source Control? ● Get some :) ● Install subversion ● Use a hosted solution
  26. 26. 26 Documentation
  27. 27. 27 API Docs ● Documentation generated from source code itself ● Follows code structure ● classes ● inheritance ● methods ● parameters
  28. 28. 28 PHPDocumentor
  29. 29. 29 PHPDocumentor ● PHPDocumentor ● http://www.phpdoc.org/ ● Uses reflection ● Comments for additional information ● Add descriptions to the documentation
  30. 30. 30 PHPDocumentor Comments 1 <?php 2 3 class AttendeeList { 4 private $attendees; 5 private $observers; 6 7 /** 8 * Add an attendee to the list 9 * 10 * @param integer $id Attendee identifier/array index 11 * @param string $name Full name of the attendee 12 * @access public 13 * @return boolean If attendee was successfully added 14 */ 15 public function addAttendee($id, $name) { 16 $this->attendees[$id] = $name; 17 $this->notify(); 18 } 19 20 }
  31. 31. 31 Beyond API Docs ● Tutorials ● Installation instructions ● Examples ● FAQs ● Forums ● User-contributed
  32. 32. 32 Today's Outline ● Software Development Lifecycle ● Databases ● Source Control ● Documentation ● Open Source
  33. 33. 33 Other Topics ● System administration ● Maintenance and bugs ● Design patterns
  34. 34. 34 Open Source
  35. 35. 35 Open Source ● Free software ● Free as in beer ● Free as in freedom ● Licensing ● BSD ● GPL ● Avoid reinventing the wheel
  36. 36. 36 Open Source ● You get what you give ● Participate!
  37. 37. 37 The Local PHP Scene ● LeedsPHP http://leedsphp.org ● PHPNW http://phpnw.org.uk ● GeekUp http://geekup.org
  38. 38. 38 Questions?
  39. 39. 39 Good Luck for your Future!
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×