183
u/IAmAnIssue Jun 15 '20
3
4
7
8
Seems legit. Bonus points for storing indexes as Strings.
64
5
-38
u/WurschtChopf Jun 15 '20
And even more bonus points for not making them 'final'...
37
Jun 15 '20
They are final
6
u/WurschtChopf Jun 16 '20
uff.. you're absolutely right. Guess I should run an update for my eyes
1
u/Terrain2 Jun 23 '20
Software update in progress.
52% Complete.
Please do not turn off your computer.
28
34
52
u/Sv443_ Jun 15 '20
This isn't really bad code. Sure, there's maybe better ways to do it but this isn't bad.
28
u/whizvox int getRand() { return 4; } Jun 15 '20
This just raises a lot of questions.
Why are the indexes stored as strings?
Why do the values not correspond to the index in the variable name?
What even is a "server index"?
16
u/Sv443_ Jun 15 '20 edited Jun 18 '20
Maybe they have at least eight (or nine) servers and indexed them with numbers. The program only uses four of these servers and these variables are set depending on which ones have the least load or which ones are active. I don't know if it's the professional term but I call these kinds of things "mappings".
4
u/valkon_gr Jun 15 '20
Maybe the index is part of something else as well. "XXCCHH" + Server index or something
1
1
u/lpreams Jun 16 '20
It's definitely not that bad, but I can still see how it's kind of bad. At the very least, those numbers look like data that should be kept separate from code and passed in as arguments or a config file. If those indeces ever change, the whole program would have to be recompiled from source. Args and config files are much easier to update.
1
u/Sv443_ Jun 18 '20
That's true but it might be one of those things that change so rarely it's more efficient to just recompile the code instead of spending a lot of time making a config reader module or something like that.
1
u/lpreams Jun 18 '20
If it's that rare, I'd fear the source code (or even just knowledge of how to compile it) getting lost forever between now and the next time someone needs to compile if. So I'd still want to move them out of the code.
1
u/Sv443_ Jun 18 '20
We're missing context to say if that's the case, maybe it's something really really obvious like a file named
config.javain the project's root or maybe they even have an external wiki (we do at work so it's not that far fetched).-20
u/WurschtChopf Jun 15 '20
Huh? Declaring a variable with public static but not final is quite damm bad
21
8
7
4
u/TheUnlocked Jun 16 '20
This isn't so bad, at least not out of context. It's better than magic numbers, and there are perfectly valid reasons to want to set things up this way (say, maybe compatibility with older code or data that used/uses hard-coded constants).
2
2
u/PizzaRollExpert Jun 15 '20
I have to wonder if there are better names than SERVER_INDEX_x possible, the fact that server 1 doesn't have index 1 (or 0 for that matter) seems to imply that it's not just an arbitrary server but rather that it matters that it's that particular server. Why does it matter which particular server it is? That should go in the name.
1
u/actionscripted Jun 16 '20
This looks like decent code for a bad existing code base or system.
Also index could refer to string position. They might have a server name string and the parts for how it’s named start at those indexes or those are parts of an array for the name.
1
u/OneHitPlunder Jun 16 '20
While I would have used a public static final String array for this, it's not too bad.
1
u/peabnuts123 Jun 16 '20
The worst part about this is that they are looking up servers by indices in an array, rather than literally any other means
1
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Sep 08 '20
Image Transcription: Code
public class ProfilesConst {
public static final String SERVER_INDEX_1 = "3";
public static final String SERVER_INDEX_2 = "4";
public static final String SERVER_INDEX_3 = "7";
public static final String SERVER_INDEX_4 = "8";I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!
0
0
Jun 15 '20
[deleted]
30
17
22
u/MCWizardYT Jun 15 '20
So this is Java. public allows other classes to see it, static makes it accessible without instantiating the class, and final makes it a constant.
The variable name is all uppercase with underscores because that’s the naming convention for constants in Java.
0
Jun 15 '20
[deleted]
3
u/xigoi Jun 15 '20
I'd make it a crime to use SCREAMING_CASE for anything.
0
Jun 16 '20
[deleted]
1
u/xigoi Jun 16 '20
I mean, Rust isn't exactly the pinnacle of beauty.
0
Jun 16 '20
[deleted]
1
u/xigoi Jun 16 '20
I'm talking about syntax, not about design. In my opinion, the C++-like syntax with
{};::<>everywhere looks ugly.
103
u/[deleted] Jun 15 '20
Hey, at least they had the foresight to make static strings to begin with?
It's ugly, but that's what these are there for lol