Ryan Markel - WordCamp StL 2016 - Code Review

55
CODE REVIEW WORDCAMP ST. LOUIS 2016

Transcript of Ryan Markel - WordCamp StL 2016 - Code Review

Page 1: Ryan Markel - WordCamp StL 2016 - Code Review

CODE REVIEWWORDCAMP ST. LOUIS 2016

Page 2: Ryan Markel - WordCamp StL 2016 - Code Review

RYAN MARKELHELLO, WORLD!

Page 3: Ryan Markel - WordCamp StL 2016 - Code Review

CODE REVIEW

ABOUT ME

▸ I’m a (really) long-time WordPress user.

▸ I work at Automattic.

▸ On the WordPress.com VIP team.

▸ I can (kind of) code.

▸ With some help.

▸ On a good day.

Page 4: Ryan Markel - WordCamp StL 2016 - Code Review

OK; SO WHY DO YOU CARE SO MUCH ABOUT CODE REVIEW? AND WHY SHOULD I?

All of you, just now

CODE REVIEW

Page 5: Ryan Markel - WordCamp StL 2016 - Code Review
Page 6: Ryan Markel - WordCamp StL 2016 - Code Review

CODE REVIEW IS A WAY OF LIFE

Page 7: Ryan Markel - WordCamp StL 2016 - Code Review

WHAT IS WORDPRESS.COM VIP?

DIGRESSION:

Page 8: Ryan Markel - WordCamp StL 2016 - Code Review
Page 9: Ryan Markel - WordCamp StL 2016 - Code Review

CODE REVIEW

WORDPRESS.COM

▸ Largest single WordPress installation in the world

▸ Serving:

▸ 21.5 billion page views per month

▸ 55.8 million new posts per month

▸ Many millions of sites/blogs

Page 10: Ryan Markel - WordCamp StL 2016 - Code Review

CODE REVIEW

WORDPRESS.COM VIP

▸ Enterprise-level WordPress hosting

▸ On the WordPress.com infrastructure

▸ 2.5 billion page views per month

▸ 99.9976% uptime

▸ 349ms average response time

Page 11: Ryan Markel - WordCamp StL 2016 - Code Review
Page 12: Ryan Markel - WordCamp StL 2016 - Code Review

CODE REVIEW

WORDPRESS.COM VIP

▸ Sites run on WordPress.com sites, just like yours and mine

▸ Clients have a custom svn repository for their theme

▸ They commit changes to their theme directly to their directory on WordPress.com

▸ A problem with a WordPress.com VIP site can affect:

▸ Other VIP sites

▸ More of the WordPress.com network

Page 13: Ryan Markel - WordCamp StL 2016 - Code Review

WE REVIEW ALL CODE BEFORE DEPLOYING IT

Page 14: Ryan Markel - WordCamp StL 2016 - Code Review

WHY CODE REVIEW?1.

Page 15: Ryan Markel - WordCamp StL 2016 - Code Review

CODE REVIEW

WHY CODE REVIEW?

▸ Safe code

▸ Finding XSS, unescaped and unsanitized code

▸ Scalable code

▸ Smart queries, cached functions, DRY code

▸ Readable code

▸ Coding standards (whitespace, formatting, etc.)

▸ Learning!

Page 16: Ryan Markel - WordCamp StL 2016 - Code Review

WE DON’T […] REVIEW TO ADD MORE TIME TO OR DELAY YOUR LAUNCH SCHEDULES.

WordPress.com VIP

CODE REVIEW

Page 17: Ryan Markel - WordCamp StL 2016 - Code Review

WE DO […] CODE REVIEWS TO HELP YOU LAUNCH SUCCESSFULLY.

WordPress.com VIP

CODE REVIEW

Page 18: Ryan Markel - WordCamp StL 2016 - Code Review

WHAT DO YOU LOOK FOR WHEN YOU REVIEW CODE?

2.

Page 19: Ryan Markel - WordCamp StL 2016 - Code Review

CODE REVIEW

WHAT DO YOU LOOK FOR WHEN YOU REVIEW CODE?

▸ Validation, sanitizing, and escaping

▸ XSS in Javascript

▸ Uncached WordPress functions

▸ Smart fetching of remote data

▸ Terrifying queries that set databases on fire

▸ Best practices and WordPress coding standards

▸ Typos

Page 20: Ryan Markel - WordCamp StL 2016 - Code Review

HOW DO YOU DO CODE REVIEW?

3.

Page 21: Ryan Markel - WordCamp StL 2016 - Code Review

AUTOMATIC CODE REVIEW

Page 22: Ryan Markel - WordCamp StL 2016 - Code Review

CODE REVIEW

AUTOMATIC CODE REVIEW

▸ PHP CodeSniffer

▸ WordPress Coding Standards rules

▸ VIP Quickstart and/or VIP Scanner

▸ Continuous integration testing

▸ e.g., Travis

▸ WP Enforcer

Page 23: Ryan Markel - WordCamp StL 2016 - Code Review

MANUAL CODE REVIEW

Page 24: Ryan Markel - WordCamp StL 2016 - Code Review

THE WORDPRESS.COM VIP CODE REVIEW PROCESS

DIGRESSION:

Page 25: Ryan Markel - WordCamp StL 2016 - Code Review
Page 26: Ryan Markel - WordCamp StL 2016 - Code Review

THE “DEPLOY QUEUE”

Page 27: Ryan Markel - WordCamp StL 2016 - Code Review

(REDACTED)

Page 28: Ryan Markel - WordCamp StL 2016 - Code Review

CODE REVIEW

WORDPRESS.COM VIP CODE REVIEW PROCESS

▸ Client commits changes to repository

▸ Changeset displayed in a special view that contains:

▸ Commit itself (diff, revision #, repository data, etc.)

▸ Changelog entry for each revision

▸ Reviewer can either:

▸ Open a ticket to discuss the change and leave notes

▸ Deploy or revert as needed

Page 29: Ryan Markel - WordCamp StL 2016 - Code Review

CODE REVIEW

WORDPRESS.COM VIP CODE REVIEW PROCESS

▸ 9.5 million lines of code reviewed to date

▸ Over 144 thousand individual deploys

▸ Average time from commit to deploy (this includes review!) is around two hours

Page 30: Ryan Markel - WordCamp StL 2016 - Code Review

THAT’S COOL, BUT WHAT TOOLS CAN I USE TO ACCOMPLISH THE SAME?

You, just now again

CODE REVIEW

Page 31: Ryan Markel - WordCamp StL 2016 - Code Review

DO YOU USE GITHUB?

Page 32: Ryan Markel - WordCamp StL 2016 - Code Review
Page 33: Ryan Markel - WordCamp StL 2016 - Code Review
Page 34: Ryan Markel - WordCamp StL 2016 - Code Review

PULL REQUESTS ARE LIKE BUILT-IN CODE REVIEW OPPORTUNITIES

Page 35: Ryan Markel - WordCamp StL 2016 - Code Review

CALYPSODIGRESSION:

Page 36: Ryan Markel - WordCamp StL 2016 - Code Review
Page 37: Ryan Markel - WordCamp StL 2016 - Code Review

[CODE REVIEWS] HELP TO KEEP CODE QUALITY CONSISTENT,

Calypso Project Documentation

CODE REVIEW

Page 38: Ryan Markel - WordCamp StL 2016 - Code Review

THEY SPREAD OWNERSHIP OF THE CODE,

Calypso Project Documentation

CODE REVIEW

Page 39: Ryan Markel - WordCamp StL 2016 - Code Review

AND THEY HELP EVERY PERSON WORKING ON CALYPSO IMPROVE OVER TIME.

Calypso Project Documentation

CODE REVIEW

Page 40: Ryan Markel - WordCamp StL 2016 - Code Review

CODE REVIEW

CALYPSO

▸ Pull requests are peer reviews waiting to happen

▸ Stay positive - comment on the code, not the person

▸ Have a list of things to look for in code review

▸ Checklists are your friends

▸ When you are creating a pull request

▸ When you are reviewing and (hopefully) merging it

Page 41: Ryan Markel - WordCamp StL 2016 - Code Review

YOU NEED DOCUMENTATION

Page 42: Ryan Markel - WordCamp StL 2016 - Code Review

CODE REVIEW […] GREATLY INCREASED THE QUALITY OF OUR CODEBASE…

Andy Peatling, WordPress.com Developer Blog

CODE REVIEW

Page 43: Ryan Markel - WordCamp StL 2016 - Code Review

…AND HELPED EVERYONE LEVEL UP THEIR JAVASCRIPT SKILLS.

Andy Peatling, WordPress.com Developer Blog

CODE REVIEW

Page 44: Ryan Markel - WordCamp StL 2016 - Code Review

WAYS TO DO MANUAL CODE REVIEW

Page 45: Ryan Markel - WordCamp StL 2016 - Code Review

CODE REVIEW

MANUAL CODE REVIEW

▸ Github pull requests

▸ No one merges their own PR

▸ Use the comments! They are a great tool!

▸ Line number comments are fantastic

▸ If you don’t use Github or a similar tool

▸ Diff reviews (use a good text editor) - WordPress core!

Page 46: Ryan Markel - WordCamp StL 2016 - Code Review

MAKE IT PART OF YOUR TEAM CULTURE

Page 47: Ryan Markel - WordCamp StL 2016 - Code Review

WHAT IF I’M A SOLO DEVELOPER? WHAT DO I DO?

A few of you, maybe for the last few minutes

CODE REVIEW

Page 48: Ryan Markel - WordCamp StL 2016 - Code Review

SLEEP ON YOUR CODE

Page 49: Ryan Markel - WordCamp StL 2016 - Code Review

CODE REVIEW

SELF CODE-REVIEW

▸ Create pull requests or diffs of your own code and queue them up for review

▸ Don’t merge to master/production/head the same day if you can help it

▸ Clear your mental context between writing your code and reviewing your own code

▸ Use automatic code review tools to get you part of the way there

Page 50: Ryan Markel - WordCamp StL 2016 - Code Review

EVERYONE CAN DO CODE REVIEW

Page 51: Ryan Markel - WordCamp StL 2016 - Code Review

WHEN NOT TO DO CODE REVIEW

4.

Page 52: Ryan Markel - WordCamp StL 2016 - Code Review

NEVER

Page 53: Ryan Markel - WordCamp StL 2016 - Code Review

REVIEWED CODE IS BETTER CODE

Page 54: Ryan Markel - WordCamp StL 2016 - Code Review

THANK YOUWORDCAMP ST. LOUIS 2016

Page 55: Ryan Markel - WordCamp StL 2016 - Code Review

NO, REALLY; THANK YOU

RYANMARKEL.COM/WCSTL2016

▸ Download of these slides and my notes

▸ Links to the resources listed and quoted in this presentation

▸ Contact form so you can reach me if you have any questions

▸ Lots of blog posts that have nothing to do with code review, this talk, or really WordPress at all