image by James Emery
Once upon a time, there was a young girl who was just learning how to program. Her name was Goldilocks. On a fine day, her mother told her to go onto the Internet and learn something new, but not to venture off too far otherwise she might find a troll or two. "I know mom..." said Goldilocks, and flipped open her Macbook Air, opened up Google Chrome, and started searching the web.
Dr. Majorus Extreme-Abstractus : Super Senior Architect of MegaCorp
The first site she came to was the blog of a Dr. Majorus Extreme-Abstractus. The Dr. proclaimed, "All problems can be solved with another layer of abstraction!" He proceeded to display large amounts of code that contained interfaces, abstract base types, and every pattern he could think of. The next line expressed in confidence, "This code will never break and is ready for composition and reuse." Sadly Goldilocks felt the Dr.'s solution was over architected. It may have looked elegant to him, but it was hard to follow and most likely brittle due to its complexity. Goldilocks thought, "This style is too abstract for me... I think I will continue looking."
Max Hacker : Coding Ninja for Startuply
Soon after leaving the blog of the Dr. she came upon the blog of a startup programmer called Max Hacker. The subtitle of the blog read, "just get it done." The code samples were easy to follow, but had a lot of hardcoded strings and one-off implementations. Additionally, there was absolutely no abstraction which left no room for code reuse. Max claimed, "We support millions of users with this code, and it only breaks twice a day." Max continued to express his coding philosophy. "I like how I used bare metal languages like C and C++ that offer little abstraction. I love to manage all my memory myself." Sadly Goldilocks could see a few missed pointer releases in his code samples and thought she could easily make the same mistakes. "This style is not abstract enough for me... I think I will continue looking."
Sam Simple : Software Developer for TechGurus
Goldilocks was starting to get frustrated. She had read two whole blogs and still felt she hadn't learned anything. Actually, that was not true, she had learned what she didn't like. She finally came to the blog of Sam Simple. His blog subtitle stating "Keep It Simple Sam". She had a good feeling about this blog. His code samples showed how he abstracted common infrastructure code like data access, authentication, and logging. He also took advantage of many of the abstractions the languages and tools he used offered him, not opting to re-invent his own approach every time. Sam wrote "I want to focus on the code I need to write to get the task complete, but I also want to make sure I can reuse and alter it later." Goldilocks liked the sound of that, so she read further. "Abstractions are great, but you should always be mindful of how many you use. Too many can confuse you and your team members." How true, Goldilocks thought. The last line of the post read "Only introduce an abstraction when it is absolutely necessary, you will know when development becomes slow or even painful." "Wow," Goldilocks thought, "This amount of abstraction is just right!".
So what did Goldilocks learn on her journey through the internet? She learned that you should use abstractions in your code, but use them sparingly. Too much abstraction and can lead to complexity and confusion. Too little abstraction can make it hard to alter and change your code. The right amount of abstraction will make coding easier, while keeping your code clean and easy to comprehend. So kids, please, use your abstractions wisely.