8 Tips for C++/C# Unity Programmers
By: Alphi Henry
Source: Stroustrup, B. (2018). The C++ programming language. Pearson.
8. Don’t feel the need for your program to be 100% original.
Chances are, with some variance, your code has been done before and done better. Use resources like GitHub, Google, and Stackoverflow and copy/paste code from there. Unless you are a first-time coder, you are probably already doing this. Finding code online saves time and may build upon your ideas. It’s way better to learn to read other people’s code and use theirs, than spending hours creating your own.
7. Express ideas directly to code; Understand ideas independent of code.
Be clear on the concepts you can code and the ones you cannot. In the aspect of a game, you cannot directly code something like a scary experience. Breakdown the variables of what you think a scary experience contains. It may seem obvious, but as you go into detail, it may become difficult. Ask yourself, what does it mean to code a scary jump scare? You can think of something like timing and anticipation. Yet, timing is codable while anticipation is not. Now think of the variables for anticipation. Ideas that can be translated into variables and methods are the only things you can code. Breakdown ideas and think of as many variables as you can, then start your code.
6. When constructing a project like a video game in unity, don’t write code that makes a single level. Create the code that can create multiple levels.
Code things with some abstraction. Instead of creating a single level with code. Create the code that can make multiple levels with variance. Make your code versatile and have functions and classes that work independently of a game or project. Create interfaces and GUIs to better build your game.
5. Avoid "voids" when necessary and use precise statements and explicit types.
Don’t over abstract. If you can code things to an explicit type, do it. Code that has an explicit type are the most useful in terms of reusability. Voids tend to be used for unique codes that will be unusable in other circumstances at the end of a program.
4. Understand what programming style you are using and be consistent.
Maintaining a certain style reduces errors in programming. Be clear on the goal and try not to mix different styles. Research different programming styles if you are unclear on a style to use.
3. Keep things very simple and abstract. Be efficient.
Create a single class or method for something as simple as adding. As redundant as it my seem, keep things very simple. This may enable you to use certain classes in ways you don’t expect. Separate your code accordingly. In my opinion, versatility is much more important than overly abstract. However, be aware that being overly abstract can cost time and create confusion.
Ps. If you’re like me, the meaning of abstraction is confusing. The way is works is if you have an existing code, then extract and edit a code out of it that can solve another codes problem while also solving the original, this is abstraction.
2. Keep a code repository for your favorite or most useful lines of code.
Often, code is recycled. Depending on how abstract you make the code, you should rip parts of your code and store it somewhere. If you work on many projects, you will most definitely run into a situation where you feel like you have coded this before and chances are you have. Use online tools like GitHub or you can even use a text file. Store your code and don’t leave it in projects.
1. Take notes and maintain a manual.
As your lines of code goes into thousands, it’s a given that it will start to be tough to remember things. Note the name of classes and its function. Treat it as a manual on how to use your code for your project. Eventually you may want to publish your code to be used by other people. Therefore, a how-to manual will make things easy.