Skip to content

Use an interface instead of method reflection to call the API#523

Open
SquidDev wants to merge 1 commit intodan200:masterfrom
SquidDev-CC:feature/api-interface
Open

Use an interface instead of method reflection to call the API#523
SquidDev wants to merge 1 commit intodan200:masterfrom
SquidDev-CC:feature/api-interface

Conversation

@SquidDev
Copy link
Copy Markdown
Contributor

This makes it easier to verify at compile time that API methods are valid. I also think it makes the API code substantially easier to read, but that may just be me.

This makes it easier to verify at compile time that API methods are
valid.
Copy link
Copy Markdown
Contributor

@Lignum Lignum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also think it makes the API code substantially easier to read, but that may just be me.

Not just you, this is beautiful. Looks good to me.

@theoriginalbit
Copy link
Copy Markdown

theoriginalbit commented Mar 25, 2018

I also think it makes the API code substantially easier to read, but that may just be me.

Definitely a much better way to do it! Though if ComputerCraft is using Java 8 then it could be made a little cleaner with Optionals.

@dmarcuse
Copy link
Copy Markdown
Contributor

dmarcuse commented Mar 25, 2018

Though if ComputerCraft is using Java 8 then it could be made a little cleaner with Optionals.

It could be made even cleaner on top of that using Guava's Suppliers.memoize (Minecraft/forge already has Guava as a dependency, right?)

e.g. write a supplier to get an optional containing the API impl, memoize it with Guava, and then just use apiSupplier.get().ifPresent(...)

SquidDev added a commit to cc-tweaked/CC-Tweaked that referenced this pull request Dec 10, 2018
This is originally based on dan200/ComputerCraft#523, but being more
liberal in how it breaks backwards compatibility. 1.14 and all that
after all.

There's several reasons for this change:
 - Make the API code cleaner and less error prone by removing
   reflection.
 - Try to make ComputerCraft.java less monolithic by moving
   functionality into separate module-specific classes.
 - Hopefully make the core class less Minecraft dependent, meaning
   emulators are a little less dependent on anything outside of /core.
SquidDev added a commit to cc-tweaked/CC-Tweaked that referenced this pull request Dec 17, 2018
This is originally based on dan200/ComputerCraft#523, but being more
liberal in how it breaks backwards compatibility. 1.14 and all that
after all.

There's several reasons for this change:
 - Make the API code cleaner and less error prone by removing
   reflection.
 - Try to make ComputerCraft.java less monolithic by moving
   functionality into separate module-specific classes.
 - Hopefully make the core class less Minecraft dependent, meaning
   emulators are a little less dependent on anything outside of /core.
SquidDev added a commit to cc-tweaked/CC-Tweaked that referenced this pull request Dec 17, 2018
This is originally based on dan200/ComputerCraft#523, but being more
liberal in how it breaks backwards compatibility. 1.14 and all that
after all.

There's several reasons for this change:
 - Make the API code cleaner and less error prone by removing
   reflection.
 - Try to make ComputerCraft.java less monolithic by moving
   functionality into separate module-specific classes.
 - Hopefully make the core class less Minecraft dependent, meaning
   emulators are a little less dependent on anything outside of /core.
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

Successfully merging this pull request may close these issues.

4 participants