Why it is better to use Globals plugin than native globals in C2?

As the article states. This plugin is just an empty plugin. It does absolutely nothing so it doesn’t affect the project in any way. It’s all about the approach. You can use nearly any other plugin and achieve the same result. I just made this one to have an empty plugin so to not load unnecessary data to the memory and have a separate plugin with unique icon to make it visually distinct.

Modern languages like C# or JAVA do not allow global variables at all because it is well known among programmers that global variables are bad (mainly because of code architecture, semantics, etc. but there are also other reasons depending on the language). Therefor those languages allow only public static variables which are members of a particular class. Such variables have global access but are not globals, they are encapsulated within the class and have to be called via the class name. So assuming that you need a Score variable with global access then you don’t declare a Score global variable, but a static member of the class. Let’s say the class name is Globals then in C#/JAVA you call it with Globals.Score. This is better than global variable for a variety of reasons which of some I described in my article.

The trick with the plugin Globas that I am suggesting is to make a solution similar to what those languages force on developers. So instead of using native globals you use instance variables of Globals plugin (which you may compare to public static variables in C#/JAVA/…).

It is not easy to make a good code/events architecture in C2 but I always encourage to at least do what is possible so keep the code clean, encapsulated, maintainable, (the list of benefits is really long), …

Leave a reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">