1 | ||
1 | ||
1 | ||
1 |
public static HighlightManager Instance { get; private set; }
public GameObject buildingHighlightObject; // Prefab or object to use for highlighting
void Awake()
{
if (Instance != null && Instance != this)
Destroy(gameObject);
else
Instance = this;
}
---
what is the downside of the above flow? Why use EDA (event driven arch) if i can just instance things? I dunno, maybe a dumb question, but asking anyways. Is it racing conditions? Its racial isn't it.
That would be my style.
Instead I like to adapt patterns from functional language programming into iterative programming languages. Functional programming is better programming, iterative languages are better languages. The only thing wrong with functional programmers is they use absolutely awful pure functional languages.
So if you were doing functional programming you are first looking for edge cases and putting them at the top of the function.
So I basically do things in an order where I multiply (exceptionality of the conditional) (length of the conditional in code) (length of the related block in code).
The more exceptional and concise things are the more they end up a the top of the code, with the goal of returning if possible. This means that the code below only has to consider more narrowed cases turning the larger more complicated code even more simple.
This is also technically better for performance because the cpu is assuming conditionals are likely to be false and so branch prediction loads code past your conditional. The CPU is loading the exceptional code like it is the main block.
The last one often means that there are fewer states that could exist below the first if statement so the subsequent if statements end up more simple.
So instead of:
You are more likely to end up with:
Also this is better: Is better than: if(Conditional that is true 999/1000 times) { //Main block of code for 30 lines } else { //Handle exception } ```
For some reason they teach the beginner level object oriented programmers to do it the second way. It's very java and ugly. Where as assembly programmers, C programmers, and functional programmers all handle exceptions first and main sequence of logic second. Do things the way functional programmers do. They are very good programmers because they have to make up for using the shittiest languages.