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

Taking the pain out of refactoring - MKGN March

Taking the pain out of refactoring - MKGN March

Refactoring can be tough. To look in detail at old code you've written to identify the weaknesses can be a really soul destroying experience. Whether it's finding code you've written that retrospectively could have been better, or forcing yourself to look at code you thought was brilliant but instead see the flaws and improvements that could be made.

But refactoring doesn't have to be a painful experience, it can be a joy. To watch your code improve, become more succinct, more thought out, and more performant is fantastic. In this talk, I'll cover some of the great sides to refactoring a front-end project, looking at recent work from a large project refactor I've been working on. I'll look at how you can set some good rules and goals for your refactoring. Take a look at tools to make the job easier. As well as things like how to prepare your state of mind for what can be a very tough process.

Adam Onishi

March 05, 2015
Tweet

More Decks by Adam Onishi

Other Decks in Technology

Transcript

  1. @onishiweb - me “…we’re constantly evolving our practices so regularly

    with the environment changing around us every day, you look back on code you wrote a few months ago and wonder what on Earth you were thinking.” http://bit.ly/old-code-sucks Hello!
  2. @onishiweb - Martin Fowler “The process of changing a software

    system in such a way that it does not alter the external behaviour of the code yet improves its internal structure.” http://bit.ly/refactoring-book What is Refactoring
  3. @onishiweb Clarity “Code should be clear, well-commented, and follow consistent

    rules. A developer new to the project should be able to understand it.” Importance
  4. @onishiweb Maintainability “Code should be easy to update & maintain,

    not requiring hacks or over- specific styles. It should be clear where files and styles belong.” Importance
  5. @onishiweb Efficiency “It should be easy for a developer to

    find where styles live, write new styles, fix bugs, or find documentation and instructions.” Importance
  6. @onishiweb DRY “Don't repeat yourself! Code should be reusable, have

    efficient selectors, and not be overly repetitive or nested.” Importance
  7. @onishiweb http://bit.ly/css-smells Undoing styles Magic Numbers Qualified/ Dangerous selectors Hard-coded

    values Brute forcing Reactive ! important IDs Loose Class names Bad code
  8. @onishiweb - Amaury Moulron “We have currently 9,000+ selectors —

    that’s pre-refactoring. Once done, we’re aiming at 5,000 selectors.” http://bit.ly/buzzfeed-sass Preparation
  9. @onishiweb Partials to have <300 lines of code Maximum nesting

    of 4 levels deep Code should adhere to The Rules Ability to use autoprefixer In practice
  10. @onishiweb <!-- component --> <div class="sys-filter"> [...] </div> // Sass

    file "_sys-filter.scss" .sys-filter { [...] } In practice
  11. @onishiweb - Hugo Giraudel “the more a string is repeated,

    the better it is for compression. [… therefore] the difference is likely to be inexistent.” In practice http://www.sitepoint.com/avoid-sass-extend/
  12. @onishiweb - James Higgs “A good developer can code. A

    really good developer can write clean code. A great developer knows when clean code is a waste of time.” http://youtu.be/znBtzBAS9Bo Summary