"Change is constant" is a very popular quote, it's one we love to embrace most of the time as it provides hope that things can get better (or worse if care isn't taken ๐ ). Be that as it may, there are times when we need stability more than we need change, and there are areas where we want more static than excitement.
Tradition, among other human constructs, is one such area. It turns out that the field of software development happens to inherit a lot from human ideologies (obviously because we're the designers of software ๐). Today we'll be looking at the word "static". If you recall, I shared a snippet of code recently when I wrote about functions and in the screenshot, the word "static" kept popping up, I plan to get into what static represents today.
A relatable explanation
Static is assigned to creations within software development that can't be created (weird I know ๐), static is different from things like "const", "readonly", and the likes in the sense that when used with a class, new instances of that class can't be created. We create new instances of classes when we want to pass in new values within the scope of a specific backend logic. When using static, we can't create new instances, we can simply refer to the static class directly and work with it as it is.
Static classes are pretty useful when you consider the fact that they're alive throughout the lifetime of the software solution, you do not need to give birth to a new one whenever you want to run some computation. It's not all fun and games with static classes though, because the modifier "static" is used to ensure rigidity in classes, method, functions, and variables, the data type of anything with the term "static" must be outrightly specified.
The above by default makes static more stressful as we developers are known to use the keyword "var" when we don't know the data type we're using but want the machine to figure it out ๐. Also, objects with the "static" keyword can't be inherited, nor can they be inherit from other objects. Every property of a static object must also be static too, which makes for a very "all or nothing" situation ๐.
Finally
Static modifiers are incredibly useful when used by people who know the rules and plan to abide by them strictly, it can make for faster development when you don't have to create a new instance of an object before gaining access to the properties of the said object. All in all, as with all things related to software development; use case is key and use case is bound by context.