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

Taking the pain out of refactoring - SecWed March

Taking the pain out of refactoring - SecWed 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 11, 2015
Tweet

More Decks by Adam Onishi

Other Decks in Technology

Transcript

  1. @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 Refactoring
  2. @onishiweb Clarity “Code should be clear, well- commented, and follow

    consistent rules. A developer new to the project should be able to understand it.” Refactoring
  3. @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.” Refactoring
  4. @onishiweb Efficiency “It should be easy for a developer to

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

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

    Brute forcing Reactive !important IDs Loose Class names Too much nesting Code smells
  7. @onishiweb - Robert “Uncle Bob” Martin “The act of leaving

    a mess in the code should be as socially unacceptable as littering.” http://deviq.com/boy-scout-rule/ When
  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 When
  9. @onishiweb - Partials to have <300 lines of code -

    Maximum 4 levels of nesting - Code should adhere to our “Rules” - Ability to use autoprefixer When
  10. @onishiweb - Phil Karlton “There are only two hard things

    in Computer Science: cache invalidation and naming things.” Naming
  11. @onishiweb <!-- component --> <div class="sys-filter"> [...] </div> // Sass

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

    the better it is for compression. [… therefore] the difference is likely to be inexistent.” http://www.sitepoint.com/avoid-sass-extend/ Experiments
  13. @onishiweb - Be pragmatic - Be prepared - You’re improving

    the product - Help other developers Painless
  14. @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 Be Great