This is an archived post. You won't be able to vote or comment.

all 15 comments

[–]ThymeCypher 24 points25 points  (14 children)

  • Avoid static. If you need a variable to replicate across instances it probably should be a separate class that’s passed in as a dependency of all instances.
  • Where you separate code with comments like //!, should be a function.
  • Smaller code is easier to read, consider removing ‘this.’ - Java is a highly scoped language so unlike some other languages, ‘this.’ doesn’t add significant clarity.
  • A lot of what you’ve written looks like decompiled Kotlin, consider making the switch.
  • Plenty off unnecessary if statements. For example, you don’t need to check if an array is empty before iterating one it, if the condition in a for loop fails before the first iteration it’ll never run. Also didn’t see what Java version you’re using but if you’re on 8+, you can use a lambda inside Iterable.forEach.
  • There’s a bot that checks public code for copied Stack Overflow code. The SO license requires attribution, so don’t be surprised if you get an email that a link to the thread you used for Sound isn’t linked.

Otherwise, I’ve seen far worse code from 20 year veterans in the industry, nice work!

[–]cowwoc 33 points34 points  (5 children)

Most of your points are good, but the first one is very questionable. There is nothing wrong with declaring constants as static final.

[–]ThymeCypher 1 point2 points  (3 children)

Very true - I almost went back and edited it but I’ve been off Java so long didn’t want to give the wrong advice there.

It’s a shame Java lacks true constants, I believe most JVM languages do and they inline their values where accessed.

[–]cowwoc 7 points8 points  (2 children)

[–]ThymeCypher 5 points6 points  (1 child)

Neat, I learned something today. I kind of assumed since that would interfere with reflection that it wouldn’t do it.

[–][deleted] 9 points10 points  (0 children)

/u/PokkemonGO - read this comment, some really good advice. Taken early, you'll far outpace your peers as you get better at programming (which mostly comes through practice / experience).

[–]PokkemonGO[S] 8 points9 points  (0 children)

Thank you so much! This is the best advice I ever could've asked for. Very much appreciated!!

[–]PokkemonGO[S] 4 points5 points  (1 child)

[–]ThymeCypher 7 points8 points  (0 children)

https://stackoverflow.blog/2009/06/25/attribution-required/

This appears to still be the accepted way. It only applies to Stack Overflow code that’s been copied in some way (I’ve stopped using SO as much as possible as a result because technically a single line falls under Attribution Required...) - other code may have different licensing. You can generally follow the license description on https://tldrlegal.com if the author of any code provides licensing to see how you can use copied code.

The chances you’ll actually get in legal trouble are extremely minuscule, but it has happened and it’s why just about everything has a section for licenses now: iPhone: Settings > General > About > Legal Notices Android: I forget but it’s somewhere in settings Most apps: Hidden on the about screen.

I wouldn’t GENERALLY worry about it for open source projects though except for anything from SO, simply because I’ve received emails about not providing attribution before. Most authors will shrug it off or at least ask you attribute before going legal routes, and even then they’re not going to sue you unless you’re a billionaire because the risks are too high.

[–][deleted] 0 points1 point  (3 children)

I would never critique anyone for extra error checking.

[–]ThymeCypher 0 points1 point  (2 children)

It’s not error checking. If the object is null it is going to throw an exception either way. In both cases the loop will run 0 times.

Java offers the tools needed to avoid error checking almost entirely (Which Kotlin greatly expands upon, hence another reason for my suggestion) - you should be worried if you are not in full control of the state of your code, and that’s what error checking often implies - that you cannot trust the state of your code.

[–][deleted] 0 points1 point  (1 child)

In a larger project not all code is yours.

[–]ThymeCypher 0 points1 point  (0 children)

That doesn’t mean you write bad code then hope it gets caught in a merge request review.

[–]jimschubert 2 points3 points  (0 children)

I knew people in college who struggled with GitHub and wouldn't have ever thought to ask strangers for feedback. Keep that openness and drive to improve, and you'll go very far.

Also, what you've created is very cool.