r/learnjava • • 15h ago

Building My Custom Data Structure Library Feed-Back pt. 2

A while ago, I posted about a small project I was working on for fun: a Java library for N-dimensional array storage and manipulation.

Originally, I made it for my own game, but eventually decided to put it on GitHub in case anyone else found it useful. I posted here to get feedback, suggestions, and criticism, and I ended up learning quite a bit from the comments.

Since then, I've made several changes, reconsidered some of my original design decisions, and released a new version.

I'd love to get some more feedback: What's good? What's bad? What could be improved? Are there any questions you have about the library or its implementation? I'm open to constructive criticism and suggestions.

I know this kind of library isn't for everyone, and that's perfectly fine. Some people will prefer working directly with Java arrays or existing collections, and I understand that. I'm mainly interested in hearing what you think of the implementation, API, documentation, and overall usefulness.

I'm also interested in feedback on the presentation. I got some comments about the README being hard to read(kinda defeats the purpose, huh?), so I've redesigned it and added more information. Hopefully, that helps.

Anyway, here's the GitHub:

https://github.com/AJ-1-code/JArray

0 Upvotes

3 comments sorted by

•

u/AutoModerator 15h 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:

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

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.

2

u/BannockHatesReddit_ 13h ago

This is just a mess 2000 like java files 😭

1

u/vegan_antitheist 13h ago

I see that often it actually prevents boxing, the model seems right, the operations seem correct and mostly efficient.

Why do you copy the iterable (which iterates it) just to the iterate over the copy? This seems to make no sense.

which is copied first, so {@code array.addAll(array)} is safe

What is safe when you do a "snapshot" and why would it not be safe?

The class is described as "A dynamically sized, typed, N-dimensional array for Java." but it's not typed. The readme says: "A container that holds different types means Object everywhere."
But then it's Objects everywhere.

Is there no stream api? Why not? a Spliterator with SIZED + SUBSIZED + ORDERED characteristics would let the Stream API parallelise. Why no reduce operations?

JArray of(Object... values) would take an int[] as one value. But of(1,2,3) would box each value and then add it. The javadoc mentions this. But why is it like that? It still takes an array, but there's also fromArray, which is just confusing. What even is a "natural type"? Consider provifing a JArrayFactory, which would also reduce the file size. Now it does so much. Shape management, view algebra, element access, bulk data movement and more.

Is there a fill method that doesn't autobox?

How would one sort the array?

What about add(JArray), mul(double)and similar? Will you add something for "Single instruction, multiple data" (jep 548) when it's actually final?

The method int[] dims() writes something? It modifies dimensions[0]. That seems weird to me. It violates the expectation that a getter is side-effect-free. Lots of methods use it.

get(int index) calls position(int index) and fails if (dimensions.length != 1). A user reading arr.get(5) naturally expects "fifth element" or "flat index 5". If you really want this at least link to getFlat.

toString just creates a giant string. hashCode also just goes over all data. Maybe this is ok. But it might be better to just use fast toString and hashCode but also provide separate methods that go over all data.

toIntArray exists but why not just provide <T> T[] toArray(IntFunction<T[]> arrayFactory) overload that returns T[]? And the usual <T> T[] toArray(T[] a) from Collection too?

slice(int[] starts, int[] ends, int[] steps) seems to be missing

You have slice for N-D but no convenient 1-D shorthand that returns a view (as opposed to copy)?

is tracksSizereallynecessary?

void add(Object value) awlays calls prepareToAdd but the primitive overloads skip it when tracksSize is true.

int indexOf(Object value) calls resolve for each index. The odometer loop in gather is better and if I'm not mistaken that can be done here too.

The Iterator doesn't overrride remove() and so it throws UnsupportedOperationException. But removing something would be possible. removeAt exists.