r/learnjava • u/fishybusinessdev • 2d ago
Building a custom Java data structure library for my game, would like feedback.
I recently released JArray, a Java data structure library I've been working on.
The goal was to build something that combines dynamic sizing, specialized primitive storage, mixed data types, and multidimensional array functionality because I thought it might help me with my game-development, things like inventory, maps, and parsing save files.
it currently uses a whole bunch of primitive arrays, and metadata array to hold values. but i don't know if its better to use a single object array.
I'd appreciate feedback on the API design, storage architecture, and features that would make the library more useful, also any questions about the library.
here's the GitHub to the project. hopefully it doesn't get flagged as promotion: https://github.com/AJ-1-code/JArray
8
u/aqua_regis 2d ago
Not to be mean, but your entire library is code smell, alone the idea of your "data structure" is code smell and indicates a lack of planning beforehand.
You are not gaining anything with your data structure. Your data structure has more overhead than even the wrapping of primitives would cause (Java has autoboxing and autounboxing).
The need to store different, unrelated data types in a single data structure is smelly.
There are way too many static methods.
4
u/gekigangerii 2d ago
Seems like this is fighting against the idea of declaring your types upfront,
but ultimately you need to know what data type you stored because you have to handle it at compile time
3
u/voidiciant 2d ago
hmmm….it’s clearly missing documentation on the api. Just by looking at it, why do I have getters that take a single index and others take a list of indices, what is “Object get(int... indices)” supposed to mean?
What is the semantic of a dimension “0”?
Then, I’m not sure if I like loosing my typeinformation for my own Objects, as you can only ever return Object and I need to keep track of casting, or am I missing something (or am I too rusty).
2
u/Available_Safe1818 1d ago edited 1d ago
Can you show more examples, like where it's better than an arraylist?
Why do you have all of the static final ints in Storage.java that mirror the enum values in DataType.java?
10 arrays inside of each instance of Storage seems like a strange choice.
2
u/Ormek_II 1d ago
I like the read.me. You spend some time explaining what you are doing and you did actually benchmark and try to be complete. Well done.
You write: “The important takeaway is that JArray can offer substantial advantages for certain workloads, especially when working with homogeneous primitive data.” 🤔 if the data is homogeneous, shouldn’t you compare with Array instead of ArrayList?
What we all miss: WHY? What is it, that you wanted to do, that you needed that abstraction for?
1
2
u/vegan_antitheist 2d ago
You clone an array by copying each value. You should first learn how computers use memory. The JVM can't always optimise your code.
1
u/istarian 22h ago edited 22h ago
That's pretty much how it works when your current array is too small and you need a bigger one. You make a larger array and copy over the data.
What are you suggesting as an alternative?
2
u/vegan_antitheist 17h ago
Yes, it's not about copying arrays, it's about how you do it. Doesn't java even have a clone method on arrays? And to copy to a larger array you can just use the Arrays.copyOf method. The JRE might optimise your code, but this is guaranteed to be optimal. And it's easier to read too.
•
u/AutoModerator 2d ago
Please ensure that:
Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions
You include any and all error messages in full - best also formatted as code block
You ask clear questions
You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.
If any of the above points is not met, your post can and will be removed without further warning.
Code is to be formatted as code block (old reddit/markdown editor: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.
Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.
Code blocks look like this:
You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.
If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.
To potential helpers
Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.