0
5 Ways to Awesome-ize
Your (PHP) Code

Jeremy Kendall

Thursday, November 7, 13
Thursday, November 7, 13
I love to code

Thursday, November 7, 13
I love to code
I’m terribly forgetful

Thursday, November 7, 13
I love to code
I’m terribly forgetful
I take pictures

Thursday, November 7, 13
I love to code
I’m terribly forgetful
I take pictures
I work at OpenSky

Thursday, November 7, 13
What Are These 5 Ways of
Which You Speak?

Thursday, November 7, 13
Use Version Control

Thursday, November 7, 13
Use Version Control
‣

Thursday, November 7, 13

If you aren’t using version control, use git
Use Version Control
‣

If you aren’t using version control, use git
Install git

Thursday, November 7, 13
Use Version Control
‣

If you aren’t using version control, use git
Install git
cd /path/to/project

Thursday, November 7,...
Use Version Control
‣

If you aren’t using version control, use git
Install git
cd /path/to/project
git init

Thursday, No...
Use Version Control
‣

If you aren’t using version control, use git
Install git
cd /path/to/project
git init
git add .

Th...
Use Version Control
‣

If you aren’t using version control, use git
Install git
cd /path/to/project
git init
git add .
git...
Use Version Control
‣

If you aren’t using version control, use git
Install git
cd /path/to/project
git init
git add .
git...
or Else . . .

Thursday, November 7, 13
Error Reporting: Turn it Up!

Thursday, November 7, 13
Error Reporting: Turn it Up!
‣

Thursday, November 7, 13

Turn error reporting all the way up in dev
Error Reporting: Turn it Up!
‣
Helps find existing problems
‣

Turn error reporting all the way up in dev

Thursday, Novemb...
Error Reporting: Turn it Up!
‣
Helps find existing problems
‣
Helps head off future pain
‣

Turn error reporting all the wa...
Error Reporting: Turn it Up!
‣
Helps find existing problems
‣
Helps head off future pain
‣
Don’t say it’s just an E_NOTICE ...
Error Reporting: Turn it Up!
‣
Helps find existing problems
‣
Helps head off future pain
‣
Don’t say it’s just an E_NOTICE ...
Error Reporting: Dev
display_errors = On
display_startup_errors = On
error_reporting = -1
log_errors = On

Thursday, Novem...
Error Reporting: Prod
display_errors = Off
display_startup_errors = Off
error_reporting = E_ALL
log_errors = On

Thursday,...
Ditch NIH

Thursday, November 7, 13
Ditch NIH
‣

Thursday, November 7, 13

If you write it all yourself . . .
Ditch NIH
‣
. . . you maintain it all yourself
‣
If you write it all yourself . . .

Thursday, November 7, 13
Ditch NIH
‣
. . . you maintain it all yourself
‣
Eventually you have very little time for either . . .
‣
If you write it a...
Real, Actual Work

Thursday, November 7, 13
Real, Actual Work

Thursday, November 7, 13
A Life

Thursday, November 7, 13
Ditch NIH

Thursday, November 7, 13
Ditch NIH
‣

Thursday, November 7, 13

Offload work to the open source community
Ditch NIH
‣
Install Composer (http://getcomposer.org)
‣

Offload work to the open source community

Thursday, November 7, 1...
Ditch NIH
‣
Install Composer (http://getcomposer.org)
‣
Search Packagist (http://packagist.org)
‣

Offload work to the open...
Ditch NIH
‣
Install Composer (http://getcomposer.org)
‣
Search Packagist (http://packagist.org)
‣
Add dependency to compos...
Ditch NIH
‣
Install Composer (http://getcomposer.org)
‣
Search Packagist (http://packagist.org)
‣
Add dependency to compos...
Ditch NIH
‣
Install Composer (http://getcomposer.org)
‣
Search Packagist (http://packagist.org)
‣
Add dependency to compos...
DRY Up Your DB

Thursday, November 7, 13
DRY Up Your DB
‣

Thursday, November 7, 13

If you’re not using PDO, switch now.
DRY Up Your DB
‣
If you’re not using prepared statements, switch now.
‣
If you’re not using PDO, switch now.

Thursday, No...
DRY Up Your DB
‣
If you’re not using prepared statements, switch now.
‣
Replace connections and queries one at a time
‣
If...
DRY Up Your DB
‣
If you’re not using prepared statements, switch now.
‣
Replace connections and queries one at a time
‣
(o...
DRY Up Your DB
‣
If you’re not using prepared statements, switch now.
‣
Replace connections and queries one at a time
‣
(o...
DRY Up Your DB
class UserDao
{
protected $db;
public function __construct(PDO $db)
{
$this->db = $db;
}
public function fi...
DRY Up Your DB
class UserDao
{
protected $db;
public function __construct(PDO $db)
{
$this->db = $db;
}
public function fi...
DRY Up Your DB
class UserDao
{
protected $db;
public function __construct(PDO $db)
{
$this->db = $db;
}
public function fi...
DRY Up Your DB
class UserDao
{
protected $db;
public function __construct(PDO $db)
{
$this->db = $db;
}
public function fi...
DRY Up Your DB
class UserDao
{
protected $db;
public function __construct(PDO $db)
{
$this->db = $db;
}
public function fi...
Or Just Pick Something
from Packagist

Thursday, November 7, 13
Start Writing Beautiful Code

Thursday, November 7, 13
Start Writing Beautiful Code
‣

Thursday, November 7, 13

It’s time for a coding standard!
Start Writing Beautiful Code
‣
Makes life so much easier
‣

It’s time for a coding standard!

Thursday, November 7, 13
Start Writing Beautiful Code
‣
Makes life so much easier
‣
Pick someone else’s
‣

It’s time for a coding standard!

Thursd...
Start Writing Beautiful Code
‣
Makes life so much easier
‣
Pick someone else’s
‣
Use automated tools to enforce
‣
It’s tim...
Start Writing Beautiful Code
‣
Makes life so much easier
‣
Pick someone else’s
‣
Use automated tools to enforce
‣
php-cs-fi...
Start Writing Beautiful Code
‣
Makes life so much easier
‣
Pick someone else’s
‣
Use automated tools to enforce
‣
php-cs-fi...
Start Writing Beautiful Code
‣
Makes life so much easier
‣
Pick someone else’s
‣
Use automated tools to enforce
‣
php-cs-fi...
Bonus!

Thursday, November 7, 13
PHP: The Right Way

Thursday, November 7, 13
PHP: The Right Way
‣

Thursday, November 7, 13

Go to http://www.phptherightway.com/
PHP: The Right Way
‣
Start reading
‣

Go to http://www.phptherightway.com/

Thursday, November 7, 13
PHP: The Right Way
‣
Start reading
‣
Don’t stop reading
‣

Go to http://www.phptherightway.com/

Thursday, November 7, 13
PHP: The Right Way
‣
Start reading
‣
Don’t stop reading
‣
Do it “The Right Way” for 6 months
‣

Go to http://www.phptherig...
PHP: The Right Way
‣
Start reading
‣
Don’t stop reading
‣
Do it “The Right Way” for 6 months
‣
Then pick and choose
‣

Go ...
Thanks!
jeremy@jeremykendall.net
http://about.me/jeremykendall
@jeremykendall
http://365.jeremykendall.net

Thursday, Nove...
Upcoming SlideShare
Loading in...5
×

5 Ways to Awesome-ize Your (PHP) Code

2,606

Published on

5 principles you can apply *right now* to make your code better. The principles apply to most languages, the implementation is PHP specific.

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,606
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
13
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Transcript of "5 Ways to Awesome-ize Your (PHP) Code"

  1. 1. 5 Ways to Awesome-ize Your (PHP) Code Jeremy Kendall Thursday, November 7, 13
  2. 2. Thursday, November 7, 13
  3. 3. I love to code Thursday, November 7, 13
  4. 4. I love to code I’m terribly forgetful Thursday, November 7, 13
  5. 5. I love to code I’m terribly forgetful I take pictures Thursday, November 7, 13
  6. 6. I love to code I’m terribly forgetful I take pictures I work at OpenSky Thursday, November 7, 13
  7. 7. What Are These 5 Ways of Which You Speak? Thursday, November 7, 13
  8. 8. Use Version Control Thursday, November 7, 13
  9. 9. Use Version Control ‣ Thursday, November 7, 13 If you aren’t using version control, use git
  10. 10. Use Version Control ‣ If you aren’t using version control, use git Install git Thursday, November 7, 13
  11. 11. Use Version Control ‣ If you aren’t using version control, use git Install git cd /path/to/project Thursday, November 7, 13
  12. 12. Use Version Control ‣ If you aren’t using version control, use git Install git cd /path/to/project git init Thursday, November 7, 13
  13. 13. Use Version Control ‣ If you aren’t using version control, use git Install git cd /path/to/project git init git add . Thursday, November 7, 13
  14. 14. Use Version Control ‣ If you aren’t using version control, use git Install git cd /path/to/project git init git add . git commit -m “Just saved the company” Thursday, November 7, 13
  15. 15. Use Version Control ‣ If you aren’t using version control, use git Install git cd /path/to/project git init git add . git commit -m “Just saved the company” ‣ Thursday, November 7, 13 Interactive tutorial at http://try.github.io
  16. 16. or Else . . . Thursday, November 7, 13
  17. 17. Error Reporting: Turn it Up! Thursday, November 7, 13
  18. 18. Error Reporting: Turn it Up! ‣ Thursday, November 7, 13 Turn error reporting all the way up in dev
  19. 19. Error Reporting: Turn it Up! ‣ Helps find existing problems ‣ Turn error reporting all the way up in dev Thursday, November 7, 13
  20. 20. Error Reporting: Turn it Up! ‣ Helps find existing problems ‣ Helps head off future pain ‣ Turn error reporting all the way up in dev Thursday, November 7, 13
  21. 21. Error Reporting: Turn it Up! ‣ Helps find existing problems ‣ Helps head off future pain ‣ Don’t say it’s just an E_NOTICE . . . ‣ Turn error reporting all the way up in dev Thursday, November 7, 13
  22. 22. Error Reporting: Turn it Up! ‣ Helps find existing problems ‣ Helps head off future pain ‣ Don’t say it’s just an E_NOTICE . . . ‣ Turn error reporting all the way up in dev Thursday, November 7, 13
  23. 23. Error Reporting: Dev display_errors = On display_startup_errors = On error_reporting = -1 log_errors = On Thursday, November 7, 13
  24. 24. Error Reporting: Prod display_errors = Off display_startup_errors = Off error_reporting = E_ALL log_errors = On Thursday, November 7, 13
  25. 25. Ditch NIH Thursday, November 7, 13
  26. 26. Ditch NIH ‣ Thursday, November 7, 13 If you write it all yourself . . .
  27. 27. Ditch NIH ‣ . . . you maintain it all yourself ‣ If you write it all yourself . . . Thursday, November 7, 13
  28. 28. Ditch NIH ‣ . . . you maintain it all yourself ‣ Eventually you have very little time for either . . . ‣ If you write it all yourself . . . Thursday, November 7, 13
  29. 29. Real, Actual Work Thursday, November 7, 13
  30. 30. Real, Actual Work Thursday, November 7, 13
  31. 31. A Life Thursday, November 7, 13
  32. 32. Ditch NIH Thursday, November 7, 13
  33. 33. Ditch NIH ‣ Thursday, November 7, 13 Offload work to the open source community
  34. 34. Ditch NIH ‣ Install Composer (http://getcomposer.org) ‣ Offload work to the open source community Thursday, November 7, 13
  35. 35. Ditch NIH ‣ Install Composer (http://getcomposer.org) ‣ Search Packagist (http://packagist.org) ‣ Offload work to the open source community Thursday, November 7, 13
  36. 36. Ditch NIH ‣ Install Composer (http://getcomposer.org) ‣ Search Packagist (http://packagist.org) ‣ Add dependency to composer.json ‣ Offload work to the open source community Thursday, November 7, 13
  37. 37. Ditch NIH ‣ Install Composer (http://getcomposer.org) ‣ Search Packagist (http://packagist.org) ‣ Add dependency to composer.json ‣ Run composer install or composer update ‣ Offload work to the open source community Thursday, November 7, 13
  38. 38. Ditch NIH ‣ Install Composer (http://getcomposer.org) ‣ Search Packagist (http://packagist.org) ‣ Add dependency to composer.json ‣ Run composer install or composer update ‣ Everyone needs logging. Go install monolog. ‣ Offload work to the open source community Thursday, November 7, 13
  39. 39. DRY Up Your DB Thursday, November 7, 13
  40. 40. DRY Up Your DB ‣ Thursday, November 7, 13 If you’re not using PDO, switch now.
  41. 41. DRY Up Your DB ‣ If you’re not using prepared statements, switch now. ‣ If you’re not using PDO, switch now. Thursday, November 7, 13
  42. 42. DRY Up Your DB ‣ If you’re not using prepared statements, switch now. ‣ Replace connections and queries one at a time ‣ If you’re not using PDO, switch now. Thursday, November 7, 13
  43. 43. DRY Up Your DB ‣ If you’re not using prepared statements, switch now. ‣ Replace connections and queries one at a time ‣ (or one group at a time) ‣ If you’re not using PDO, switch now. Thursday, November 7, 13
  44. 44. DRY Up Your DB ‣ If you’re not using prepared statements, switch now. ‣ Replace connections and queries one at a time ‣ (or one group at a time) ‣ Combine with simple data access objects ‣ If you’re not using PDO, switch now. Thursday, November 7, 13
  45. 45. DRY Up Your DB class UserDao { protected $db; public function __construct(PDO $db) { $this->db = $db; } public function find($id) { $sql = 'SELECT * FROM users WHERE id = :id'; $stmt = $this->db->prepare($sql); $stmt->bindValue(':id', $id); $stmt->execute(); return $stmt->fetch(); } } Thursday, November 7, 13
  46. 46. DRY Up Your DB class UserDao { protected $db; public function __construct(PDO $db) { $this->db = $db; } public function find($id) { $sql = 'SELECT * FROM users WHERE id = :id'; $stmt = $this->db->prepare($sql); $stmt->bindValue(':id', $id); $stmt->execute(); return $stmt->fetch(); } } Thursday, November 7, 13
  47. 47. DRY Up Your DB class UserDao { protected $db; public function __construct(PDO $db) { $this->db = $db; } public function find($id) { $sql = 'SELECT * FROM users WHERE id = :id'; $stmt = $this->db->prepare($sql); $stmt->bindValue(':id', $id); $stmt->execute(); return $stmt->fetch(); } } Thursday, November 7, 13
  48. 48. DRY Up Your DB class UserDao { protected $db; public function __construct(PDO $db) { $this->db = $db; } public function find($id) { $sql = 'SELECT * FROM users WHERE id = :id'; $stmt = $this->db->prepare($sql); $stmt->bindValue(':id', $id); $stmt->execute(); return $stmt->fetch(); } } Thursday, November 7, 13
  49. 49. DRY Up Your DB class UserDao { protected $db; public function __construct(PDO $db) { $this->db = $db; } public function find($id) { $sql = 'SELECT * FROM users WHERE id = :id'; $stmt = $this->db->prepare($sql); $stmt->bindValue(':id', $id); $stmt->execute(); return $stmt->fetch(); } } Thursday, November 7, 13
  50. 50. Or Just Pick Something from Packagist Thursday, November 7, 13
  51. 51. Start Writing Beautiful Code Thursday, November 7, 13
  52. 52. Start Writing Beautiful Code ‣ Thursday, November 7, 13 It’s time for a coding standard!
  53. 53. Start Writing Beautiful Code ‣ Makes life so much easier ‣ It’s time for a coding standard! Thursday, November 7, 13
  54. 54. Start Writing Beautiful Code ‣ Makes life so much easier ‣ Pick someone else’s ‣ It’s time for a coding standard! Thursday, November 7, 13
  55. 55. Start Writing Beautiful Code ‣ Makes life so much easier ‣ Pick someone else’s ‣ Use automated tools to enforce ‣ It’s time for a coding standard! Thursday, November 7, 13
  56. 56. Start Writing Beautiful Code ‣ Makes life so much easier ‣ Pick someone else’s ‣ Use automated tools to enforce ‣ php-cs-fixer ‣ It’s time for a coding standard! Thursday, November 7, 13
  57. 57. Start Writing Beautiful Code ‣ Makes life so much easier ‣ Pick someone else’s ‣ Use automated tools to enforce ‣ php-cs-fixer ‣ PHP_CodeSniffer ‣ It’s time for a coding standard! Thursday, November 7, 13
  58. 58. Start Writing Beautiful Code ‣ Makes life so much easier ‣ Pick someone else’s ‣ Use automated tools to enforce ‣ php-cs-fixer ‣ PHP_CodeSniffer ‣ Refactor bit-by-bit ‣ It’s time for a coding standard! Thursday, November 7, 13
  59. 59. Bonus! Thursday, November 7, 13
  60. 60. PHP: The Right Way Thursday, November 7, 13
  61. 61. PHP: The Right Way ‣ Thursday, November 7, 13 Go to http://www.phptherightway.com/
  62. 62. PHP: The Right Way ‣ Start reading ‣ Go to http://www.phptherightway.com/ Thursday, November 7, 13
  63. 63. PHP: The Right Way ‣ Start reading ‣ Don’t stop reading ‣ Go to http://www.phptherightway.com/ Thursday, November 7, 13
  64. 64. PHP: The Right Way ‣ Start reading ‣ Don’t stop reading ‣ Do it “The Right Way” for 6 months ‣ Go to http://www.phptherightway.com/ Thursday, November 7, 13
  65. 65. PHP: The Right Way ‣ Start reading ‣ Don’t stop reading ‣ Do it “The Right Way” for 6 months ‣ Then pick and choose ‣ Go to http://www.phptherightway.com/ Thursday, November 7, 13
  66. 66. Thanks! jeremy@jeremykendall.net http://about.me/jeremykendall @jeremykendall http://365.jeremykendall.net Thursday, November 7, 13
  1. A particular slide catching your eye?

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

×