refactor: Replace a bunch of global vars with macro #151
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.


I'm not 100% why, but you can't reference a macro directly, i.e.
array_length(macro)fails on build. Because of that, I had to assign macro into local vars beforehand.I just want to generally note: globals that are used as constants are a bad practice. Very bad.

Todo:
I want to see if it's possible to replace global static structs with something. Macro can't hold structs, so it should be something else.You can use a function, that'll return a struct, but this is no better in terms of reference overhead and additionally creates struct to be garbage collected on every call. So, no, there is no better way, I don' think.Figure out if using static variables is actually worse for performance than locals.They are. Unless you want a variable to preform like a persistent instance variable of a function, that you can modify and reference throughout your code, kinda like a global var, you shouldn't use static vars. They take up memory and are never freed, the same way as globals.Honestly, I'm not even sure how are they different from globals. Maybe only in how you reference them, with
function_name.static_name.