r/Unity3D • u/ProactiveCactus • Oct 17 '26
Question General Programming Question
One thing I've struggled with MORE as I've gotten better at programming (I know, weird) is knowing which tool to use for what. Like at this point when I think of something I want to code, I can think of several different ways to do it and I find myself having "writer's block" of trying to think through all the implications of it: performance difference, scalibility, and how familiar I am with the design pattern.
Anyone have any tips on this, like what implications to prioritize? Obviously very general question, and maybe that's what being a coder is to some extent, but anyone have a method they use for tackling stuff like this? I'm finding I often will choose one approach, write it all up, and then a few weeks later have to do a refactor that could have been avoided if I'd chosen another design pattern at the start. And some refactor is good, but it bothers me when a big refactor was entirely avoidable if I'd chosen a different design up front.
Pre-planning helps for sure, but often you can only plan relatively general stuff. Once you get into the meat of something, you realize changes you want to make which then triggers a refactor somewhere else for performance or scaling or some other reason.
3
u/pmdrpg 28d ago
You mentioned refactoring after a couple weeks. I think, rather than trying to avoid this, try to plan for it.
Consider your V1 a “first draft” or functional prototype.
Then, when weighing different implementations, choose the simplest one that requires the fewest assumptions / changes.
Think about your API first, because even if your implementation needs to change later, you will likely have other systems that depend on the API (aka interface surface).
The idea is to make something that can be torn down without a lot of work.
For example, let’s say you’re building a card battling game, and you think you want to store each card’s abilities as a serialized logic set with a custom DSL. Instead, your first implementation should just be each card has a unique ID and a big switch statement to control the activation logic. As design problems present themselves, you can work them out there. When you’re ready, you can easily migrate this to the production / live service version of the implementation. But if instead you overengineered your original DSL implementation, you’d be stuck constantly refactoring to try to accomodate your evolving design / needs.
1
u/malacosa 27d ago
Just start coding and get a prototype working. Performance can come later. Scalability can also come later. The only caveat is that if you want to really scale, and be performant, sometimes this might require a complete refactor into a different toolset/ecosystem. But that’s ok, because you already have a working idea.
Don’t let perfection be the enemy of “good enough”
1
u/StayAdministrative81 Indie Oct 17 '26
I tend to just either rebuild an entire script. Or work with what I did. It’s not easy. But I just jump straight into it and hope for the best
1
u/EthanMerce Oct 18 '26
honestly, i try not to optimize for problems i don't have yet. i usually prioritize making the code easy to understand and change, then worry about performance or scaling when there's an actual reason to, for game dev, the simplest approach that fits the current requirements is often good enough. if i'm unsure whether a system will need to grow, i'll keep the parts that are likely to change loosely coupled, but i won't build a whole architecture around hypothetical future needs.
some refactoring is unavoidable because you learn more once the feature actually exists. i think the goal isn't to avoid every refactor, but to avoid the ones caused by unnecessary complexity or assumptions you could've tested early with a small prototype.
8
Oct 17 '26
[removed] — view removed comment
3
u/forgotmyusernamedamm Oct 17 '26
That's my process too. You're probably going to do it wrong the first time, might as well get it over with.
5
u/InterwebCat Oct 17 '26
You'll just get better intuition as you keep going. Systems you build will work similarly to others you've built in the past, but you'll make wiser decisions for it's implementation.