Looks like the end of the code isn't included in the code block - to get a code block that works on all Reddit clients, you can put four spaces at the start of each line of code (the triple-tick one doesn't work on old reddit & mobile clients)
I agree. I'd love for the clients to be fixed. The problem is it's Reddit we're talking about here. They hardly ever fix bugs on their own clients (I could talk for hours about all the ways they've managed to screw up their markdown interpretation). Most of the time they just add more bugs, and they barely support their own API, making life unnecessarily hard for devs of third-party clients as well.
Until the clients are fixed (which will probably never happen), the method that works for everyone should be used, unless of course you're fine with the code being unreadable to to a significant percentage of people. In which case, go for it, but that seems to me to defeat the purpose of using code blocks in the first place.
as a language? C# if you don't want to stray too far. Other than that, pretty much every language that doesn't explicitly favor the "billion dollar mistake" or exceptions.
agreed, but let people have their journey. If they want to be stuck with a weak typesystem, treading the same path for 20 years and ignoring there are better ways that's their choice.
When you have to think about the potential failure of every step, you get more resilient code that fails more gracefully than just throwing an exception and leaving it to be somebody else's problem.
I know this is how it’s supposed to work, but I’ve been in way too many Java code reviews where a long list of caught exceptions was auto-inserted by the IDE and left with // TODO.
code that fails gracefully isn’t an accident and it’s not because of a single code pattern, it’s an intentional design choice. The alternative is just getting it written for the happy path and then handling the errors when we see them.
I mean yeah. It’s ugly at times. But it has indeed more often sparked the thought of “how do I deal with this particular case” than the exception handling in Java did. Also calling log.Fatal is not something you should do in most cases. But I assume it’s here for illustration purposes.
The warts, like error handling, would not change until the release of a hypothetical Go2. The language isnt difficult to learn and the standard library has a lot of oomph. If you are curious go check out the tour of go, pretty low investment learning.
Sure this code is bad, but I guess that a lot of MC plugin developers are younger people that want to enhance their gameplay. And I can’t say that my code was better when I first started programming…
I can see these global variables being useful in a game engine since it seems like these variable would be needed to be used in many different objects. In certain ways it’s more ergonomic to have it that way instead of having to pass around essentially wrappers for the data.
In most cases it’s better to wrap data in an object and create accessor methods but in certain cases the ergonomics of a global variable is more appealing. Game engines where there are certain variables which are required at multiple levels horizontally or vertically in abstraction.
Dependency injection is better especially when reusing part between projects. In general, Java is a good language for constructing robust libraries which can be reused. I think that’s the main appeal to Java.
However, it’s nice to recognize when and when not to create libraries. Sometimes you want something to work a specific way for ergonomics.
Having to include a pointer in each class pointing to a variable which may or may not be used in different methods in said classes is not very ergonomic. Being able to reference a global variable when needed within a method is way more ergonomic than having to declare a pointer variable in the class definition.
If you have 5 monster objects each reacts differently to player data. It’s much easier to include the player data in a global variable which each class can reference to rather than including a pointer to the player in each monster class.
Obviously in Java oop you should be defining these monster objects as a super class “monster” which has a pointer to player data. But this really starts to step toward creating a library which is more or less perpendicular to the development of the game.
Game dev is different than business dev in this regard, but relying on global variables seems to be less discoverable than having purpose-driven management objects.
When you have a large list of objects that all have the same attributes it's actually worst for compute in many cases due to cache misses, rather than having a list for each attribute.
Prepared statements only stop SQL injections if you use them properly. That means you write the queries and put placeholders for the parameters. Then you add the parameters afterwards. If you just add the parameters straight to the query, you achieve nothing
For example, here they do it correctly:
PreparedStatement pre = conn.prepareStatement("UPDATE pvpdata SET kills = ?, deaths = ? WHERE uuid = ?");
pre.setInt(1, kills.getOrDefault(p.getUniqueId().toString(), 0));
pre.setInt(2, deaths.getOrDefault(p.getUniqueId().toString(), 0));
But then here they do it incorrectly
ResultSet set = conn.prepareStatement("SELECT * FROM pvpdata WHERE uuid = '" + u + "'").executeQuery();
Though it's unclear to me if u is arbitrary data, but regardless it's very silly
I'll backpedal a little and say that I'm not against it, but I do take issue with it's ubiquity and how much its negatives are downplayed.
OOP encourages maintaining and sharing a mutable state. This leads to unpredictability and side-effects. These are often some of the more challenging issues to troubleshoot within a system.
While OOP components are certainly reused, it's not something that happens naturally. Components from application A can't be used in application B unless it's specifically designed that way. Most OOP code is one-time use.
It's ugly. But on the other hand, you have the full logic on a single page and you don't have to chase the logic going through 100 classes and methods (for the equivalent amount of functionality).
Someone asked me why Java is not my favorite language. Too many “Java developers” out there with code like this. Just makes me want to not use Java so I won’t be associated to them.
Java is not my favorite language because C# now does most of the same stuff but better lol. With the exception of platform compatibility mostly, but even that’s improving. Tho I’ve seen plenty of C# code look pretty damn bad too.
I think there’s just a general level of “do you actually have an idea of what you’re writing or how it’ll get used” that some ppl forget to achieve before typing. This code reeks of “write code first, ask questions later” to me lol
.NET core/5/6 (stupid microsoft naming conventions) pretty much solved the platform compatibility issue. You can now even run C# directly on the browser with a blazor WASM app
79
u/[deleted] Nov 02 '22 edited Nov 02 '22
Transcript:
140
u/katyalovesherbike Nov 02 '22
shouldn't have used java for such a style
2
u/drip360 Nov 03 '22
What is this exactly besides coding / API…
127
u/NeuralNetWithLimbs Nov 02 '22
Love how the method “getKills” isn’t a getter since it returns void.
But also love how it’s not even a setter because that int num isn’t even used.
Only the Player arg is used, to get a unique id to use as a key for the map.
Of course, why use the unique id for a key when you could convert it into something harder to hash and compare.
Beautiful.
52
u/Auxilor Nov 02 '22
shit like this is why i'm embarrassed to say im a spigot dev, the absolute state of some of these
25
u/CountrysFucked Nov 02 '22
Looks perfectly fine. It's functional programming, all the rage with the kids now.
Edit: Dear god please don't take me seriously here.
16
u/cellularcone Nov 02 '22
Isn’t posting Minecraft mods cheating?
27
u/SikinAyylmao Nov 02 '22
I can see these global variables being useful in a game engine since it seems like these variable would be needed to be used in many different objects. In certain ways it’s more ergonomic to have it that way instead of having to pass around essentially wrappers for the data.
In most cases it’s better to wrap data in an object and create accessor methods but in certain cases the ergonomics of a global variable is more appealing. Game engines where there are certain variables which are required at multiple levels horizontally or vertically in abstraction.
4
u/atehrani Nov 02 '22
I'm more concerned with the SQL injection potential
10
u/[deleted] Nov 02 '22
This is code that gives you the feeling of looking at an overly long paragraph. "Nah, I'm not reading this bullshit. Can I skim it? Ehhh... fuck it"
Oh wait that's just all java code
edit: actually to be fair the color scheme doesn't help
3
u/I_am_noob_dont_yell Nov 02 '22
More like OOPs
3
u/Salt-Significance702 Nov 02 '22
This is the guy in the math word problems who buys 10,000 watermelons
2
u/Sufficient-Milk-3336 Nov 02 '22
this man doesnt know the difference between javascript and java and he just went with it
2
u/[deleted] Nov 02 '22
I think I can see an opportunity for SQL injection.
2
u/[deleted] Nov 02 '22
When I say that I'm against OOP, this is not the alternative that I'm referring to.
2
u/NatasEvoli Nov 02 '22
Why would I need OOPS when I never make mistakes?
2
u/NaoPb Nov 03 '22
Can anyone recommend a good read on OOP?
5
u/Critical-Explorer179 Nov 02 '22
It's ugly. But on the other hand, you have the full logic on a single page and you don't have to chase the logic going through 100 classes and methods (for the equivalent amount of functionality).
3
u/vegetablestew Nov 02 '22
No OOP is not the issue. Casually mutating fields is more of an issue.
2
u/Errons1 Nov 02 '22
Ignore the static but the practice of try catch...
1
u/Hitman_0_0_7 Nov 02 '22
I would better quit my job
1
u/Hitman_0_0_7 Nov 02 '22
Atleast functions are small. I worked on a project with 1500 line functions.
1
u/WhAtEvErYoUmEaN101 Nov 03 '22
Hi, my name is Ben‘; DROP TABLE pvpdata --
1
u/v_maria Nov 03 '22
Haven't you heard? OOP bad
1
u/bravopapa99 Nov 03 '22
Shoot this code now, it's in pain.
1
u/Rogoreg Nov 11 '22
I didn't write this, but it looks like something I would write
1
u/owiko Nov 02 '22
Someone asked me why Java is not my favorite language. Too many “Java developers” out there with code like this. Just makes me want to not use Java so I won’t be associated to them.
-2
u/Eggimix Nov 02 '22
Honestly though fuck java good on them
0
u/[deleted] Nov 02 '22
[deleted] — view deleted comment