Some Guiding Principles

Before we talk about JavaScript in context, there are some platform-independent things that can make your life much easier.

Avoid Classical OO Patterns

JavaScript is powerful. It provides object composition with prototypal inheritance as well as functional programming. Using these two “Pillars of JavaScript” over classical OO patterns allows you to take better advantage of that power. The more composable and modular your application, the easier it will be for you to refactor and expand in the future.

Be Extremely Lazy

Currently there are over 200,000 modules on NPM. Time is money; the more time you spend maintaining code that didn’t need to be written, the more expensive you are to your employers.

I’m referring to operational services and tools as well. Don’t build your own analytics platform until you have scaled beyond what SaaS solutions like Google Analytics, Mixpanel, or Keen.io can provide. Using services to handle non product specific functionality allows you to focus on the one thing that matters, the product.

Don’t waste time worrying about managing dependencies or other distractions. Move that work to third party solutions when possible. Use services like greenkeeper.io and codeclimate.com to ensure your software does not regress and that your dependencies are up to date. This allows engineers to focus on generating value instead of managing code quality.

If You Do Nothing Else, Be Consistent

One of the biggest productivity killers is rummaging around in unfamiliar code. Use a style guide and have identifiable patterns. The same styles and patterns means new projects will feel familiar.

I currently prefer Airbnb’s style guide. It has over 160 contributors and 169k downloads per month. They also have an ESLint plugin which means no configuration on your end unless you want to override something.

Crowdsourcing your style guides gives you the benefit of using the current patterns and styles used by thousands of other JavaScript engineers.

Use a linter to ensure there is conformity among your team(s). ESLint is currently my favorite linter due to its plug-ability, as well as it’s continued support from the open source community. There are also plugins for ESLint for just about every text editor and IDE.

Yeoman allows you to take consistency to the next level by creating application templates that help you start each new project. This makes sure you use the same base dependencies, coding patterns, and styles for each application.

Take Advantage of Tooling

JavaScript happens to have one of the best tooling ecosystems of any programming language. Take advantage of it! Some tools like iron-node, react devtools, and redux devtools simply can’t be replaced.

Electron and React Native provide access to native environments allowing you to create applications for a multitude of platforms. All while getting large amounts of code reusability.

Keep Things As Small As Possible

Breaking up your applications in to many smaller modules is the true key to composable JavaScript. Following the FIRST philosophy (Focused, Independent, Reusable, Small, Testable) helps keep down complexity while promoting testability and reuse.

“Whether it’s a client or server-side component, a Node module or a piece of visual UI, components that are large are inherently more complex to maintain than those that are small.” — Addy Osmani

Remember that no piece of functionality is too small for a module. In fact, the smaller the module, the easier it will be to gain reuse from it.

Use ES2015

Use it for your APIs, your SPAs and everything in between. Tools like Babel, my transpiler of choice, give you a huge advantage. Being able to use something like ES2015 today means you can build applications with smaller, cleaner code. Don’t let fear of vendor lock-in or the availability of these tools deter you from using them. Babel has over 160 contributors and over 400 releases.

There is no reason not to use Babel right now! Babel can handle plain old vanilla JavaScript right next to any other type of compiled code, meaning that you can migrate modules right back to plain ES5 at any time.