Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
luaq35936y@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.
-
psukys2326yMixed feelings about static and I can see why your coworkers were picky as well. Did you eventually settle on the matter?
-
BigBoo23126yThe 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. -
D--M22666yThis sounds like you posted some shit online... And you are talking to randoms, why bother :?
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?
rant