Введение
Introduction
Clean code always looks like it was written by someone who cares. – Michael Feathers, author of Working Effectively with Legacy Code
Most game developers would agree that you need clean code: Code that is easy to read and efficient to maintain and reuse. Once your logic is functional, then the process of refactoring and cleaning up begins. There are good reasons for this congruence. Something that might be obvious to you as the original author might be less apparent to another developer. By the same token, when you implement some logic now, you might not remember what that same code snippet does three months later. Chances are you already have preferences for how to write your code today. However, your teammates of tomorrow will most likely have different preferences. While there is no right solution this guide provides some tips on how you can leverage a style guide to agree on standards.
This guide compiles advice from industry experts on how to use or adapt existing industry standard code style guides. Establishing such a guide for everyone in your team to follow will help ensure your codebase can grow your project to a commercial-scale production. These tips and tricks will help your development process in the long term, even if they cost you extra effort up front. A cleaner, more scalable codebase also facilitates the efficient onboarding of new developers as you expand your team. Keep your code clean to make life easier for yourself and everyone involved in the project. Clean code aims to make development more scalable and conform to a set of production standards, including: —
Follow consistent naming conventions
Format your code for legibility
Organize classes and methods to keep them small and readable
Comment on any code that isn’t self-explanatory
Whether you’re building a puzzler for mobile or a massive MMORPG targeted at consoles, keeping your codebase clean reduces the total cost of software maintenance. You can then implement new features or patch your existing software more easily. Your future teammates – and your future self – will be thankful for that.
Note: This is the second edition of this e-book, now updated for Unity 6.
Contributors This guide was written by Wilmer Lin, an independent game developer and educator. Significant contributions were also made by technical content marketing manager Thomas Krogh-Jacobsen and senior Unity engineers Peter Andreasen, Scott Bilas, and Mihai Popescu.