Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A few improvements to the classes #2

Open
DarkSeraphim opened this issue Oct 26, 2017 · 2 comments
Open

A few improvements to the classes #2

DarkSeraphim opened this issue Oct 26, 2017 · 2 comments

Comments

@DarkSeraphim
Copy link

DarkSeraphim commented Oct 26, 2017

  • Don't statically fetch the plugin instance, use dependency injection instead (pass it through the constructor, as a parameter)
  • Do mind the random imports.
  • Don't use public on fields unless they're final & immutable (or at least, 99% of the time).
  • Do use == for enum comparison (the enum class does this in it's equals method anyway, but == is null safe).
  • Do prefer if (!statement) { return; } // rest of code over if (statement) { // rest of code } as it reduces nesting depth by a great deal (EDIT: some classes seem to use it, some don't).
  • Sometimes there's still section signs, try to stick to ChatColor.
  • Do avoid asynchronous tasks for small things, and absolutely do avoid them when Bukkit / Minecraft is involved and it's not guaranteed to be thread safe.
  • Do prefer Runnables over BukkitRunnable if you're not using the cancel() method. (this means you should probably use it in all cases of runTask and runTaskLater).
  • Liskov Substitution Principle! Program against abstractions rather than implementations (i.e. use List rather than ArrayList, Set rather than HashSet, Map rather than HashMap, etc, when choosing a type for a variable, parameter or field).
  • Sets are faster than Lists. Importing a List once and converting it to a Set will give you a nice performance boost if your List gets large.

And sometimes a few spelling errors which I cannot bother to link (but who cares about that, the compiler sure doesn't).

Still, probably one of the cleaner tutorials I've seen online.

[EDIT] Seems it doesn't like multiline codeblocks in lists :/

@X-yl
Copy link

X-yl commented Mar 15, 2018

Adding on to this,

  • Follow Java naming conventions! No uppercase letters in packages!!!
  • indent your damned code.
  • Don't use the bungee ChatColor
  • You use your own serialisation for Location even though it implements ConfigurationSerializable.
  • Using NMS methods for no apparent reason
  • Not using @OverRide annotations.
  • There are more...

Actually, these also apply to your other repositories. Please actually know what you're doing before you make tutorials for others to soak up your bad practice.

Shout-out from the Spigot forums. Your tutorials have apparently become quite popular, and users often suggest them. Unfortunately, you don't hit the nail on the head every-time which is what is expected of a tutorial. Especially one that is targeted towards beginners.

@JollyPerson
Copy link

Add Java colouration on your GitHub code!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants