How Do I Determine the Right Abstraction Boundaries in My Code?

0
5
Asked By CodeCrafter42 On

Hey everyone, I'm fairly new to programming (about 2 years in), and I'm trying to figure out how to decide the right boundaries for abstractions or APIs in my projects. I've read that a good approach is to code until you naturally need to create an abstraction, as suggested by some well-known developers. This sounds reasonable, but I often find myself second-guessing where those layers should go, or if I'm trying to plan too much ahead. Right now, I'm working on a Magic: The Gathering deck builder using C and libcurl for HTTPS support. I'm uncertain about where to build my abstractions around libcurl, as I only need to interact with three endpoints and don't want to create unnecessary complexity. How can I find the balance between letting the code guide me to create abstractions and forcing myself to plan them out ahead of time? Thanks for any insights!

2 Answers

Answered By DevDude123 On

You're on the right track with your approach! The idea of writing code until the need for abstraction becomes clear is solid. It seems like you just haven't had enough coding experiences yet to really grasp when to apply that concept. My advice? Just dive in and start coding! Refactoring is part of the process and will give you valuable experience down the line.

MagicBuilder99 -

That’s exactly how I felt too! Sometimes starting out can make you feel overwhelmed with indecision. Just charging ahead sounds like a good plan. I'm going to try that approach and see where it leads me.

Answered By ProDevAndy On

It’s smart to create abstractions around components that might change or have different implementations. For instance, if you're dealing with a game that could run on various platforms, you'll need to think about abstractions for file systems, graphics, and threading. Check if libcurl works across all your intended platforms and whether it’s likely to stay stable. Also, consider using the Facade pattern—it simplifies complex APIs by providing a cleaner interface and makes them easier to use. It’s great for situations where you might want to mock implementations for testing to ensure your unit tests don’t rely on real network connections.

CodeCrafter42 -

That makes a lot of sense! I was already looking into platform-specific threading issues, so building an abstraction there seems necessary. I definitely need to focus more on unit testing too. The Facade pattern sounds interesting; I’ll explore that further!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.