This repository has been archived by the owner on Nov 22, 2024. It is now read-only.
Optimization for PLReflect.java and a few other style conventions and fixes. #36
cire3wastaken
started this conversation in
Ideas
Replies: 3 comments 7 replies
-
@OtterCodes101 opinions? |
Beta Was this translation helpful? Give feedback.
6 replies
-
blud wrote a whole essay complaining about the code 💀 |
Beta Was this translation helpful? Give feedback.
0 replies
-
btw will you add eaglerforge api to resent if we fix our code? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I was scrolling through the source when I saw how you guys implemented the
getClassById
andgetClassByName
functions, which I think could be optimized better. Right now, you guys loop over the entire array of classes, and don't cache the result. I think there are 2 main ways to fix this. 1) Cache the result or 2) Instead of using an array, use a HashMap for amortized constant time retrieval, which is better than the current linear time. You could also optimize this further by creating the HashMap with the correct amount of elements, like you do with the array. Lax's idea was, in my opinion, unfairly rejected (this is pretty much the same optimization). You can avoid the brought up issue of the same function/object name in two ways: 1) If it's a function, you can simply refactor the code to make functions get grabbed from the respectiveClass<?>
or 2) synthesize member classes and anonymous classes (the java compiler does this under the hood, a member class ofclass X
calledclass Y
becomesX$Y.class
)I was also looking at the code, and there are a few style issues I feel like that should be fixed to match with Sun/Oracle coding standards. For one, I think you should 1) actually get the eaglerforge.net domain or 2) refactor the package to somewhere else, possibly
package io.github.eaglerforge
or something. There's also a few classes (such as this) that need to be refactored to fit with java style conventions.Another issue I noticed is the usage of TeaVM in the main source set. You should keep TeaVM related code in the TeaVM source set, and have a shadow class in the lwjgl source set, so desktop runtime won't be broken, and it's also a good practice. The
main
source set for eagler is pretty much acommon/main
source set.Another major issue I noticed is how you interact with the Minecraft source, and the lack of documentation on the changes. Documentation isn't required, however adding a
// EaglerForge start
and a// EaglerForge end
comment to wherever you modified the source code is required for long term scalability. Another thing, is how you guys are not very compliant with a Minimal Diff policy in modifying the source, which weakens the long term maintainability of this project. Even better, if you have code that needs to called on an event, listen to the event in a separate class in the eaglerforge package for maintainability!! Try your best to not add code within the minecraft source, unless it is absolutely needed!!(the worst offender of all of the style conventions and code conventions is probably this)
This class could probably be refactored and fixed, and there's no need to make a static field in the Minecraft class, you can get all the data you need via Minecraft.getMinecraft() and its functions.
This following part is copied from craft bukkit: https://hub.spigotmc.org/stash/projects/spigot/repos/craftbukkit/browse (thank you craftbukkit for already having this amazing explanation)
Minimal Diff Policy
The Minimal Diff Policy is key to any changes made within Minecraft classes. When people think of the phrase "minimal diffs", they often take it to the extreme - they go completely out of their way to abstract the changes they are trying to make away from editing Minecraft's classes as much as possible. However, this is not what is meant by "minimal diffs". Instead, when trying to understand this policy, it helps to keep in mind its goal: to reduce the impact of changes we make to Minecraft's internals have on our update process.
To put it simply, the Minimal Diffs Policy simply means to make the smallest change in a Minecraft class possible without duplicating logic.
Here are a few tips you should keep in mind, or common areas you should focus on:
Try to avoid duplicating logic or code when making changes.
Try to keep your changes easily discernible - don't nest or group several unrelated changes together.
All changes must be surrounded by EaglerForge comments.
If you only use an import once within a class, don't import it and use a fully qualified name instead.
Try to employ "short-circuiting" of logic if at all possible. This means you should force a conditional to be the value needed to side step the code block to achieve your desired effect.
For example, to short circuit this:
You would do this:
For checks related to API where an exception needs to be thrown in a specific case we recommend use the package Preconditions
For checking arguments we recommend using Preconditions#checkArgument where a failing check should throw a IllegalArgumentException
We recommend using this to ensure the behaviour of @NotNull in the EaglerForge API
For checking arguments we recommend using Preconditions#checkState where a failing check should throw a IllegalStateException
For example, you should use:
Instead of:
When the change you are trying to make involves removing code, or delegating it somewhere else, instead of removing it, you should comment it out.
For example:
EaglerForge Comments
Changes to a Minecraft class should be clearly marked using EaglerForge comments.
All EaglerForge comments should be capitalised appropriately. (i.e. EaglerForge, not EF/eaglerForge, etc.)
If the change only affects one line of code, use an end of line EaglerForge comment
Examples:
If the change is obvious, then you need a simple end of line comment.
If the change affects more than one line, you should use a multi-line EaglerForge comment.
Example:
The majority of the time, multi-line changes should be accompanied by a reason since they're usually much more complicated than a single line change. If the change is something important to note or difficult to discern, you should include a reason at the end of line EaglerForge comment.
Otherwise, if the change is obvious, such as firing an event, then you can simply use a multi-line comment.
All EaglerForge comments should be on the same indentation level the code block it is in.
Imports in Minecraft Classes
Do not remove unused imports if they are not marked by EaglerForge comments.
Beta Was this translation helpful? Give feedback.
All reactions