JavaScript: Is Deep The Right Goal? | @thetorquemag
“All The Word That's Fit To Press.”
A WP Engine

JavaScript: Is Deep The Right Goal?

I’m very excited to be a part of WordCamp Miami‘s “Learning Javascript, Deeply” track. The fact that five of the seven talks are on JavaScript frameworks, however, is reflective of a troubling reaction I see to Matt Mullenweg’s call for WordPress developers to “learn JavaScript deeply.”

JavaScript frameworks like Backbone, which is what WordPress uses, are great ways to make complex JavaScript tasks easy. But it would be foolish to think that learning a JavaScript MVC framework is learning JavaScript deeply.

JavaScript: Is Deep The Right Goal?

Don’t get me wrong, I’m giving two talks on AngularJS because I think Angular is a simple JavaScript framework that produces great results. I am definitely not an advanced JavaScript developer. I am way better with PHP and AngularJS gives me a way to quickly build good client-side applications that embraces design principles that make sense to me.

I know my JavaScript fundamentals, so when I say AngularJS is simple or easy, I know that’s a little chauvinist. While I may not have a computer science education — in fact my educational background is in environmental studies —I have spent time understanding the basic patterns and principles of software development and how they apply to PHP.

If you show up to my introduction to AngularJS talk at WordCamp Miami having never learned anything about JavaScript or software design in general, you’re not going to be able to follow along.

The first time I tried to learn Angular it was a disaster. At the time, I didn’t fully understand JavaScript closures and how object oriented development differed from JavaScript to PHP. I also had never experienced the MVC pattern before.

Don’t get me wrong, I’m super excited about the JavaScript track at WordCamp Miami. I hope lots of people go to the sessions, find the framework that makes sense for them, and build awesome things with it plus the WordPress REST API.

Backbone, AngularJS, Ember, and React, for example, are all “easy” ways to get started with API-driven JavaScript client-side app development, however, I’m not convinced they lead to a deep understanding of JavaScript directly.

Easier Is Good

It was actually kind of funny to hear Matt Mullenweg talk about learning JavaScript deeply when his team used React to make the admin redesign easier (not that there is anything wrong with that).

I like easy. I’m a WordPress developer. I have a career because WordPress is an easy way to get started with PHP development. I am able to work with JavaScript because jQuery — an easy way to get started with JavaScript development — was all I needed in terms of JavaScript for years to do my job.

These relatively easy — though they were not very easy when I started — development tools got me to where I can pick up something like AngularJS very quickly when I needed it. If you leave a comment on this post you will see the comment appear on the page without a refresh. If someone else leaves a comment while you have this page open, it will appear on the screen within 15 seconds.

I like to think that’s pretty cool. Maybe I’m biased because I wrote most of the plugin, which is called Epoch and is made possible by Postmatic, that makes that possible. I wrote the client-side portion of that plugin in jQuery and plain JavaScript.

It works, but requires a lot of custom PHP to create the API for it and format the data as needed. At the time of writing this article, I am re-writing Epoch to use the WordPress REST API instead of my custom API, and I am also using AngularJS.

I’m pretty sure that the end result will be much better and faster. It will definitely be simpler and cleaner. While the JavaScript code I wrote for Epoch version 1 isn’t using a fancy JavaScript MVC framework, and over time got kind of messy with bug fixes, I still learned a ton about JavaScript from writing it.

I learned a lot of things about JavaScript fundamentals and DOM manipulation that Angular would have hidden from me behind all of its magic.

If WordPress is really entering an era of API-driven interfaces, tools like Angular and Backbone will make that even easier.

Let’s Stay Out Of The Framework Wars

Still, the focus on frameworks scares me. This is not just because I find the “my framework is better than yours” debate to be silly.

My concern is that it is reinforcing the notion that WordPress is all about JavaScript or it will be in the near future. A lot of that has to do with open-sourcing the code behind the improvments to the admin intrerface they have implimented over the last two years. But, as WordPress developers, we should be able to understand  that news about Automattic isn’t about WordPress the software.

The focus on improving the visual interface is important for modernizing WordPress — and JavaScript MVC frameworks are an important part of that. But WordPress is a server-side PHP application. Yes, you could make something like WordPress is node.Js, but that’s not what WordPress is doing and it is not what Automattic did with Calypso.

Learn PHP Deeply

If you are a WordPress developer, given that we are in the era of the API-driven JavaScript interface, then you should understand that your PHP skills are more important than ever. JavaScript interface needs a solid server-side application, most of the time I choose WordPress, some plugins collection and other components — all written in PHP.

Right now a lot of WordPress core, and popular WordPress plugins were not written in a way that is easily adaptable to being wrapped up in the REST API endpoints. It’s going to take a lot of work to change that. Work that will be written in PHP.

Moving forward, WordPress core as well as our plugins and maybe our themes are going to need to do a better job of decoupling logic and CRUD from display. The same low-level systems will need to serve both the traditional WordPress admin and theme interfaces, as well as REST API endpoints.

New plugins have an advantage in this department, but it requires discipline and more work to make a plugin that meets the requirements I listed above. Adapting an older plugin to meet these demands without breaking backwards compatibility is more challenging.

If you’re a WordPress developer excited about the future of WordPress driven by API-powered JavaScript interfaces, then  you should learn more JavaScript. And yes choosing a JavaScript framework to learn — I recommend AngularJS — will help launch you into JavaScript development. Most importantly, you should challenge yourself to write better PHP and develop a strong respect for the separation of concerns and the single responsibility principle.

Josh is a WordPress plugin developer and educator. He is the owner and a developer for CalderaWP, makers of Caldera Forms, a different kind of and the native WordPress A/B testing solution.

More WordPress News From Torque:

There are 2 comments

Your email address will not be published. Required fields are marked *