DEV Community

Cover image for When You Have a Golden Hammer, Everything Looks Like a Nail
Rahul Barate
Rahul Barate

Posted on

When You Have a Golden Hammer, Everything Looks Like a Nail

A while ago I came across this awesome tool called Assembly Definitions from Unity3D. As indie developers, we love finding new tools that promise to save time. Unity’s Assembly Definition sounded like a game-changer when I first discovered it. But after trying it in a small project, I realized: just because a tool is powerful doesn’t mean it’s right for every situation.

Assembly Definitions allow you to split your scripts into multiple assemblies for modularity and faster compile times. First you separate your scripts into multiple folders like Player, NPCs, Environment, and create Assembly Definition for each. Now, when you change a script in one folder, Unity only recompiles that assembly instead of the entire project. This saves a lot of time—if your project is large enough.

Now you might be thinking, isn’t that such a wonderful feature? Yes, you’re right. It is a wonderful feature but only if you use it right. The catch is Assembly Definitions enforce a strict rule: no circular dependencies. For example, if Player Assembly references NPCs Assembly, NPCs Assembly cannot reference Player Assembly. This helps prevent spaghetti code, but in small projects, it can slow development. I tried solving this using C# events but tracking how events flowed through my project quickly became a nightmare.”

I used Assembly Definitions in my small project, which barely had 10 to 15 scripts. The compile time improvement was so small I barely noticed it. And just to dodge that Circular Dependency issue, I used to many Events that after a while it became so painful for me to backtrack how the control is flowing through my scripts. I eventually realized Assembly Definitions are great for large, team-driven projects, but unnecessary for small solo projects. So, from my experience, I’ll state the Pros and Cons of Assembly Definitions and discuss when I think they are useful and when to avoid them.

Pros:

  • Faster compile times in large projects.
  • Better modularity and maintainability.
  • Useful for platform-specific builds.
  • Helps avoid tightly coupled, spaghetti code.

Cons:

  • No runtime performance improvement.
  • Adds complexity to small projects.
  • Circular dependency restrictions require careful planning.
  • When to Use Assembly Definitions:
  • Large projects with 1,000+ scripts.
  • Multiple teams working on different modules.
  • Platform-specific builds or reusable systems.

When to Use Assembly Definitions:

  • Large projects with 1,000+ scripts.
  • Multiple teams working on different modules.
  • Platform-specific builds or reusable systems.

When to Avoid:

  • Small, solo projects.
  • Projects with tightly interconnected systems.
  • When compile times are already fast.

Conclusion:
Assembly Definitions are powerful, but like any tool, they solve specific problems. When you see a good feature, that doesn’t mean you need to immediately start using it in your project. Always weigh the pros and cons before adopting a new feature—because when you have a golden hammer, not everything is a nail.

Top comments (0)