Skip to content

Instantly share code, notes, and snippets.

@sblomberg
Last active May 23, 2016 16:57
Show Gist options
  • Save sblomberg/bac0b4969191e290e3c52e5406bc2149 to your computer and use it in GitHub Desktop.
Save sblomberg/bac0b4969191e290e3c52e5406bc2149 to your computer and use it in GitHub Desktop.

Wordcamp Minneapolis 2016 - Key takeaways

Scaling

Scaling truths, according to Automattic Wordpress VIP dev Matt Perry:

  1. Wordpress is built to scale
  2. Truth #1 doesn't matter if your theme or plugin is not built to scale
  3. Sometimes even fast code is not enough, but it's a good place to start

Start by optimizing your code, since you (developers) have the most control of that. These are the some things the Wordpress VIP team looks for in themes/plugins before rejecting or approving them for Wordpress VIP sites:

1. Query problems

Too many queries or a few very expensive queries. Use debug-bar to identify number of queries and query time. Get rid of unnecessary queries or use the WP Object Cache to reduce query time.

2. External calls

External calls are expensive and disruptive. Be very careful with wp_remote_get because all execution is halted while waiting for external response. Cache external calls if required, or load via async

3. Frontend AJAX requests (this one I'm guilty of)

Every AJAX call to your site bootstraps all of Wordpress, so your site has to load Wordpress (n+1) times where n is the number of frontend AJAX calls. Frontend AJAX responses need to be heavily cached.

Q: How do I improve debugging/developing with multiple levels of caching?

Be able to invalidate the cache whenever you need to. Take the dev time to make this painless.

Q: Are custom tables better than using the Wordpress-default posts/meta tables for performance?

The Wordpress VIP team only uses and recommends using the Wordpress-default tables. Performance between both approaches are very similar, but you risk losing performance optimizations if you roll your own tables. Direct SQL queries lose all caching/performance optimization - always use $wpdb when making calls for best performance


Object Oriented Programming in Wordpress

Bad OOP in Wordpress is just as bad (or worse) than bad functional programming in Wordpress. It can be even harder to read/maintain if not done properly. Why?

  • OOP is hard to do well because Wordpress core is mainly procedural/functional
  • It often adds mutable state, which increases complexity
  • Constructors/factory methods can add noise to otherwise simple operations

Don't default to OOP if it doesn't make sense to do so. Understand the advantages and disadvantages of OOP versus functional/procedural programming before choosing one across all scenarios.


Code reviews

The intention of code reviews is to make code better.

What are code reviews?

  • Humans evaluate other humans' code
  • Bugs are caught in the least costly of development times
  • Knowledge is shared among team
  • Opportunity to learn, mentor and teach
  • Builds a foundation of trust among team

What should you be reviewing?

  • Code you didn't work on
  • 200-400 lines of code
  • Timebox review session to 1 hour
  • Create an algorithm and/or checklist of things to review

How should they happen?

  • Either online or in-person, possibly a combination of both
  • Avoid general feedback. Be specific with both positive and negative criticism.
  • After a review, it's up to the person being reviewed to implement optional feedback. Errors and incorrect formatting or styling should always be fixed.

Javascript + WordPress

Use Javascript design patterns! (ebook here)

React is currently the best way to do SPAs, or single-page apps. Why?

  • JSX is awesome
  • Syntax is simple
  • React fails at compile time rather than runtime
  • Dev tools are amazing
  • Speed (10x faster than Angular, 18x faster than knockout, 3x faster than DOM manip with jQuery)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment