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

Don't Aim for Reusability

Don't Aim for Reusability

Michael Sauter

January 26, 2018
Tweet

More Decks by Michael Sauter

Other Decks in Programming

Transcript

  1. “ Investing effort to make the code so smart /

    perfect / generic / etc. that it’ll pay off many times in the future. AIMING FOR REUSABILITY IS …
  2. I WILL SAVE TIME IN THE LONG RUN ➤ You’re

    underestimating development work and overestimating manual work ➤ You’re neglecting maintenance effort
  3. IT WILL ALSO NEED TO HANDLE X ➤ Feature creep

    is inevitable if you build for the unknown ➤ “Best practices” from Google, Facebook, …
  4. I’M A GENIUS, A HACK WON’T DO ➤ Social pressure

    - we want to appear smart ➤ It’s fun to write complex stuff
  5. SOMEONE WILL REMEMBER TO REUSE MY CODE ➤ People come

    and go ➤ Documentation needs to be written and read
  6. LOOKING AT OLD CODE … Oh interesting. That’s really weird

    … What on earth?! WHO WROTE THIS?! git blame Oops, that was me ….
  7. I’LL WANT TO REUSE WHAT I AM WRITING NOW ➤

    No matter how good you are, your code will look bad to you tomorrow ➤ Newer tech might solve the problem much easier in the future
  8. REUSING IS FASTER THAN WRITING FROM SCRATCH ➤ Why is

    it so much faster to do greenfield development? ➤ Understanding existing code takes time
  9. “ Coincidence is a lot more common than the human

    brain thinks it is.
 There might not actually be a general case,
 even if you see it clear as day. - Mattias Petter Johansson https://www.quora.com/Should-you-write-reusable-code-or-write-code-that-fits-the-use-case-Whenever-I-start-to- design-my-classes-I-start-thinking-about-re-usability-and-then-I-start-creating-more-classes-Whats-the-right-way- of-designing-classes
  10. I CAN PREDICT THE FUTURE ➤ Good abstractions need many

    examples ➤ Businesses change ➤ Product Managers People change their requirements minds
  11. “ We should be less fearful of writing code well

    suited to the requirements, but with little regard for reuse potential, and then rewrite a better version from scratch the next time. - Tony Davis https://www.red-gate.com/simple-talk/blogs/whats-the-use-of-code-reuse/
  12. I WILL SAVE TIME
 IN THE LONG RUN YOU TAKE

    THE SHORTEST
 WAY TO DELIVERY
  13. I’M A GENIUS, A HACK WON’T DO YOU CARE MORE

    ABOUT BUSINESS IMPACT THAN YOUR EGO
  14. I’LL WANT TO REUSE WHAT I AM WRITING NOW YOU

    CAN IGNORE YOUR STUPID OLD CODE
  15. AIMING FOR DELETION LEADS TO MAINTAINABILITY Time Cost of Change

    Design Done Maintenance Wall of Unmaintainability Boehm’s curve
  16. “ No code runs faster than no code. No code

    has fewer bugs than no code. No code uses less memory than no code. No code is easier to understand than no code. - Mike Perham http://www.mikeperham.com/2016/02/09/kill-your-dependencies/ AIMING FOR DELETION LEADS TO MAINTAINABILITY
  17. I. SHIFTING MINDSET (Hobby) (Business) generic code that can do

    everything specific code that does exactly what is needed vs
  18. II. DRY IS A TRAP • DRY is one of

    the most popular principles in the Ruby world • DRY is dangerous • Don’t fear code duplication - it’s required for the right abstraction
  19. III. DECREASE IMPACT • Obviously, globals are the hardest things

    to delete • Callbacks and validations need to be interaction specific • Let presenters wrap views • Find the smallest scope, the loosest connection