• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
5 Ways to Awesome-ize Your (PHP) Code
 

5 Ways to Awesome-ize Your (PHP) Code

on

  • 1,501 views

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

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

Statistics

Views

Total Views
1,501
Views on SlideShare
1,470
Embed Views
31

Actions

Likes
1
Downloads
7
Comments
0

1 Embed 31

https://twitter.com 31

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

CC Attribution-ShareAlike LicenseCC Attribution-ShareAlike License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

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

    • 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, 13
    • Use Version Control ‣ If you aren’t using version control, use git Install git cd /path/to/project git init Thursday, November 7, 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
    • 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
    • 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
    • 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, November 7, 13
    • 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
    • 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
    • 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
    • Error Reporting: Dev display_errors = On display_startup_errors = On error_reporting = -1 log_errors = On Thursday, November 7, 13
    • Error Reporting: Prod display_errors = Off display_startup_errors = Off error_reporting = E_ALL log_errors = On Thursday, November 7, 13
    • 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 all yourself . . . Thursday, November 7, 13
    • 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, 13
    • Ditch NIH ‣ Install Composer (http://getcomposer.org) ‣ Search Packagist (http://packagist.org) ‣ Offload work to the open source community Thursday, November 7, 13
    • 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
    • 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
    • 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
    • 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, November 7, 13
    • 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
    • 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
    • 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
    • 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
    • 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
    • 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
    • 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
    • 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
    • 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! Thursday, November 7, 13
    • 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
    • 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
    • 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
    • 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
    • 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.phptherightway.com/ Thursday, November 7, 13
    • 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
    • Thanks! jeremy@jeremykendall.net http://about.me/jeremykendall @jeremykendall http://365.jeremykendall.net Thursday, November 7, 13