Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Javascript Clean Code - BandungJS 2017

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.

Javascript Clean Code - BandungJS 2017

A 2017 BandungJS meetup talk on writing clean, maintainable JavaScript code, grounded in Robert C. Martin's "Clean Code" principles adapted for JS. The talk covers meaningful and pronounceable naming conventions for variables, functions, and classes; writing small, single-purpose functions with no side effects and short parameter lists; vertical and horizontal code formatting using the "newspaper metaphor," team conventions, and tools like ESLint with git commit hooks; the philosophy that good code should mostly explain itself, with examples of good versus bad comments; an overview of the JS testing ecosystem (Jest, Mocha, Chai, Jasmine) including test coverage and single-concept-per-test design; and moving away from callbacks toward Promises and async/await for concurrency. Delivered at BandungJS on August 28, 2017, while serving as CTO of UrbanIndo.com.

Avatar for Petra Barus

Petra Barus

June 24, 2026

More Decks by Petra Barus

Other Decks in Technology

Transcript

  1. Hi Everyone! I am Petra Novandi Now serves as Chief

    Technology Officer at UrbanIndo.com since 2011 - Contact me at Email: [email protected] Twitter: @petrabarus
  2. Clean Code: A Handbook of Agile Software Craftsman It’s written

    for Java, but a lot of things are applicable for Javascript https://github.com/ryanmcdermott/cle an-code-javascript
  3. Javascript is now 1st class citizen » Driven by User

    Experience ⋄ Comes V8 followed by NodeJS » Highly popular and developed » Efforts for Improvements ⋄ ES5, ES6, ES7, ES8
  4. Class Name » Class name should have Noun or Noun

    Phrase. ⋄ e.g. Customer, Account, Parser
  5. Small 20 to 30 line of codes (or statements) or

    shorter My personal motto: A function can be read in one breathe
  6. Bad

  7. Bad

  8. Vertical & Horizontal Formatting Vertical Vertical Openness Vertical Density Vertical

    Distance Vertical Ordering Horizontal Horizontal Openness Horizontal Alignment Indentation
  9. Example of Bad Comments Unclear, redundant, misleading comments Changelog comments

    A comment instead of putting code into a separate function Banners, closing brace marker Commented-out code Documenting non-public API
  10. Testing Tools for Javascript Jest Mocha Jasmine Chai Istanbul JSDOM

    Karma Sinon Phantom Chrome https://medium.com/powtoon-engineering/a-complete- guide-to-testing-javascript-in-2017-a217b4cd5a2a
  11. Clean code is investment It’s possible to code clean in

    Javascript It takes discipline and teamwork, keep practising! Use newest ES. It’s there for this reason. Use automated tools to help