10
luaq
6y

I recently got into an argument with some people, and I want your opinion. I did a speed code in Java (just sped up clip of programming, because it looks cool lol), and someone commented:

"Way too much static abuse here. Jesus"

In which I replied:

"Actually, sir. There is near none at all, just because I use static methods does not make it static abuse. A static method belongs to the class, and is somewhat permanent. It is not a type (instance, cat, dog, animal, etc.) class, it is a Utility class, much like other dependencies you'd use are Utilities and not types."

To which they reply:

"Getting and setting is a Utility?"

Boi. If it is a static variable, yes. Like, what?

Comments
  • 1
    @zlice back when I was a new developer, I did a lot of static abuse. Static is somewhat of a strong keyword, when using static I make sure that it is necessary or it is a private final method. Really, anything that is private and final can be static as well, just so if you do happen to use it in a static method there are no issues. I myself am not an expert on static abuse, but I do not believe that the code I had was static abuse. When first was told that I have a lot of static abuse; no clue what it was. But, now being quite a bit better in Java, know when and how to use static methods/variables.
  • 0
    Mixed feelings about static and I can see why your coworkers were picky as well. Did you eventually settle on the matter?
  • 0
    The problem with static variables is that it couples the code to that implementation harder. Sometimes it's fine. But should probably not be used if there is any way of doing it.

    I.e. the problem is if you realize you want to use another implementation, but you are now dependant on some global state to function in a certain way. Which can result in difficulties when refactoring. It also can make the code unnecessarily complex. Generally one should avoid side effects of methods.

    But iirc there are function classes in java. So one could implement a function class for each utility function.
  • 0
    Static variables... *shivers*
  • 1
    This sounds like you posted some shit online... And you are talking to randoms, why bother :?
Add Comment