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

The Intro to Abstraction I Wish I'd Received

The Intro to Abstraction I Wish I'd Received

So much talk about good software revolves around finding the “right abstraction”. Even programming itself is an act of abstracting the world into some form of bits and bytes. If, like me, you missed out on a proper introduction to such a fundamental concept, this talk will teach you what abstraction is and why it’s important to software development.

We’ll also dig into a real-world example of fighting a troublesome abstraction and learn strategies for identifying when one no longer works for you—the first step toward imagining new abstractions for your code to take shape.

Stephanie Minn

December 13, 2024
Tweet

More Decks by Stephanie Minn

Other Decks in Programming

Transcript

  1. Stephanie Minn | RubyConf 2021 Hi RubyConf! I’m Stephanie. I’m

    currently a developer at a small software consultancy called Tandem, based in Chicago, IL.
  2. Stephanie Minn | RubyConf 2021 For all the discourse about

    “proper abstractions”, how often does this concept get properly taught to early career developers?
  3. Stephanie Minn | RubyConf 2021 I had internalized topics like

    duck-typing and SOLID without understanding the fundamental concept that holds them up.
  4. Stephanie Minn | RubyConf 2021 This talk will cover 1.

    What is abstraction? a. In life b. In software development 2. What happens when your abstraction isn’t quite right? 3. What else could be wrong with your abstraction? 4. How do you identify those pain points?
  5. Stephanie Minn | RubyConf 2021 I hope you leave this

    talk feeling inspired by the possibilities of abstraction, and not confined to troublesome code.
  6. Stephanie Minn | RubyConf 2021 “Conceptual abstractions may be formed

    by filtering the information of a concept or an observable phenomenon, selecting only the aspects which are relevant for a particular subjectively valued purpose.” — Wikipedia
  7. Stephanie Minn | RubyConf 2021 “Abstraction, for me, is this

    idea of getting rid of everything that’s not essential to making a point.” —Christoph Niemann
  8. Stephanie Minn | RubyConf 2021 So abstractions... 1. Deal with

    general qualities or characteristics 2. Filter information for some purpose 3. Are used to make a point
  9. Stephanie Minn | RubyConf 2021 A map is an abstraction

    of terrain that exists in reality.
  10. Stephanie Minn | RubyConf 2021 • History • Linguistics •

    Art • Mathematics • General semantics • Music Abstraction is used in all these disciplines! • Neurology • Philosophy • Psychology • Social theory • Computer science
  11. Stephanie Minn | RubyConf 2021 I don’t always understand abstract

    art... The Ten Largest, Adulthood, No. 7 by Hilma af Klint Yellow Islands by Jackson Pollock
  12. Stephanie Minn | RubyConf 2021 … but I can tell

    this is a mosquito! Christoph Niemann / Sunday Sketching
  13. Stephanie Minn | RubyConf 2021 Some benefits of abstraction •

    Simplify • Generalize • Make code more flexible
  14. Stephanie Minn | RubyConf 2021 Oftentimes, we don’t need to

    know the internals of a function to use it... ✨ magic ✨ inputs outputs
  15. Stephanie Minn | RubyConf 2021 … except when it doesn’t

    do what you thought it did. bark() “quack” (my dog, Hickory)
  16. Stephanie Minn | RubyConf 2021 “You should make a service

    class to generate the data for each sheet.” Disclaimer: I will not be discussing the pros/cons of service classes in this talk 😬 * *
  17. Stephanie Minn | RubyConf 2021 1. Parse raw data from

    third party notification system 2. Query additional data from DB 3. Munge and filter data to sheet one requirements 4. Write sheet to report 5. Format sheet 1. Parse raw data from third party notification system 2. Query additional data from DB 3. Munge and filter data to sheet two requirements 4. Write sheet to report 5. Format sheet 1. Parse raw data from third party notification system 2. Query additional data from DB 3. Munge and filter data to sheet three requirements 4. Write sheet to report 5. Format sheet create_report() sheetOneGenerator.call() sheetTwoGenerator.call() sheetThreeGenerator.call()
  18. Stephanie Minn | RubyConf 2021 create_report() Data specific to each

    sheet’s requirements that has different implementations but shares a public interface Report data Sheet-specific data Sheet presentation Data written to the sheet in the correct format and order Aggregated data from both the third party system and the DB, used by all sheets in the report
  19. Stephanie Minn | RubyConf 2021 What could be wrong with

    an abstraction? • Does too many things
  20. Stephanie Minn | RubyConf 2021 What could be wrong with

    an abstraction? • Does too many things • Reveals too much
  21. Stephanie Minn | RubyConf 2021 What could be wrong with

    an abstraction? • Does too many things • Reveals too much Adapted from Practical Object-Oriented Programming in Ruby by Sandi Metz
  22. Stephanie Minn | RubyConf 2021 What could be wrong with

    an abstraction? • Does too many things • Reveals too much • Reveals too little
  23. Stephanie Minn | RubyConf 2021 What could be wrong with

    an abstraction? • Does too many things • Reveals too much • Reveals too little ◦ Or worse, is too abstract and does something it doesn’t say it’s doing
  24. Stephanie Minn | RubyConf 2021 What could be wrong with

    an abstraction? • Does too many things • Reveals too much • Reveals too little ◦ Or worse, is too abstract and does something it doesn’t say it’s doing • Is unnecessary or are there are too many
  25. Stephanie Minn | RubyConf 2021 Difficult to explain communication patterns

    • Passing around too many arguments • Complex or unclear transformation from inputs to outputs • Confusing relationships between objects
  26. Stephanie Minn | RubyConf 2021 Difficult to test • Too

    much overhead • Mocking a lot of methods • Not unit-testable/many complex test cases
  27. Stephanie Minn | RubyConf 2021 Difficult to change and extend

    • Not sure where in the code to make the change • Difficulty isolating the area you need to change ◦ Changing files all over the codebase ◦ Breaking tests in many/ unexpected places • Feeling like the code wasn’t built for the ask
  28. Stephanie Minn | RubyConf 2021 Abstractions open up a world

    of possibility! • What is complex about your abstraction? ◦ What if my service class was more object-oriented? • What could it be missing? ◦ What if I created a class for this huge hash being passed around?
  29. Stephanie Minn | RubyConf 2021 Resources • Netflix’s Abstract: The

    Art of Design • My blog post “A Case Study in Learning Code Abstraction” that turned into this talk • Practical Object-Oriented Design in Ruby by Sandi Metz • “Abstraction” from An Introduction to Object-Oriented Programming by Timothy Budd