-
-
Notifications
You must be signed in to change notification settings - Fork 342
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
Ongoing Minor Issue List (OCD list) #221
Comments
OCD is good for those kind of things, haha. |
Maybe we should cleanup the checked ones? |
@kenzierocks I considered deleting, but let's keep them there for history. Any new issues will go in a new comment. EDIT: Github does not track todo items outside of the original issue topic and they're already in the commit history so I'll delete. |
Creeper.java line 36: "Gets whether or not the creeper has been struck by lightning." shouldn't it be "Gets whether or not the creeper is powered.", considering plugins can power them. |
@ST-DDT why would we use a nullable when we could use an optional with an overloaded helper? |
i.e. two methods or even just the second one. |
Because null can still fit into both, Optionals are designed for return types. http://java.dzone.com/articles/java-8-optional-how-use-it
|
@ryantheleach I haven't seen any official Oracle statements that have said or implied that Optionals are only for return types, and the Optional used here is not the Java optional anyway. In my opinion moving the possibly of a missing value into the type system is beneficial in many situations, not just for method return statements. |
I'm offering this up as an opinion and I hope there is some truth to it. TL;DR In Java we're left with either consuming a result that is either wrapped in some class (eg., the Optional idiom) or else testing a return value specifically (eg., null). NTL;R The way I'd suggest looking at this is to treat the SpongeAPI as a black box. When we use The example is: public Optional<T> getSomethingFromSponge();
// ...
// and in the caller:
Optional<T> result = getSomethingFromSponge();
if ( result.isAbsent() ) {
// proceed down sad path
} else {
// proceed down happy path
} vs. public T getSomethingFromSponge()
// ...
// and in the caller:
T result = getSomethingFromSponge();
if ( result == null ) {
// proceed down sad path .. Gee, I think.does null mean it truly failed?
} else {
// proceed down happy path .. Hmm, a non null value may mean success, perhaps?
} I'd rather see the use of Optional in the general case because that API signature conveys to the developer relative safety in the result value. It's harder (much harder) to accidently NPE with a result. On the other hand, when we look at arguments to methods: doAnotherThing( T arg) I'd rather there be no Optional in the API for arguments. The main reason (going back to the black-box metaphor) is Optional arguments to methods implies that the caller knows that the method may not need the argument. That insider knowledge of the implementation is worrisome. Methods in the Sponge are (or will be) well crafted and do the right amount of due diligence on the arguments passed to them. Using Optional arguments puts the onus on the plugin author to wrap all their calls to Sponge methods with extra protection just in case Sponge isn't careful with the arguments. I can see why some may be skeptical of any new API implementation, but this is an extreme amount of caution. Another case for methods with Optional arguments comes up when the Sponge tries to deal with Magic Numbers. These magic numbers are the values used internally to represent meaning or behavior. The magic numbers are not meant ever to be known to the caller. Optional<T> getSomethingFromSponge( int arg ) {
// ...
if (arg <= 0) {
// resort to some default behavior
this.internalParameter = -1;
} else {
// the argument has quality we can use
this.internalParameter = arg;
}
// return something ...
} The problem with this kind of code IMHO is that the caller must know in advance that when arg is less or equal to 0, that the internal behavior of the class has a default case. A case where perhaps the behavior in that area is turned off or disabled. So thus, the argument for Optional in the method parameters would suggest: public Optional<T> getSomething( Optional<Integer> arg ) {
// ...
if ( arg.isAbsent() ) {
// setup behavior to cope with sad-path
} else {
// setup behavior to cope with happy path
}
// ...
// return something ...
} I'd counter that this excuse for Optional is overlooking that the API is simply missing the method: public Optional<T> getSomething() Why pass in an Optional that is known by the caller to be literally absent. The caller would have to explicitly make it so. I cannot make the blanket statement for Sponge that methods shall not have Optional arguments, but I find their use to be specialized. I could make a blanket statement for Sponge API design that recommends Optional for the return of objects especially when the attempt to produce the result has a non-zero probability of failing while not killing the server with an unnecessary NPE. All of this is syntax sugar to overcome the fact that Java is merely pass-by-value. There is simply no way to do what we do with pointers in C/C++: RESULT doSomething( int x, T* pArg ) {
// whatever the case may be choose:
// A) modify the whatever pArg points to and then return S_OK or
// B) leave pArg alone and return E_FAIL;
}
// and in the caller:
if ( SUCCEEDED ( doSomething ( n, pFoo ) ) ) {
// proceed down happy path
} else {
// proceed down sad path
} |
There is, since objects can be passed in and their reference is passed by value, you can just modify the object passed in and return a result. (of course this changes if you are passing in a primitive)
But the reason why I am against using Optionals in parameters is
|
As mentioned here this is a big fat no:
|
|
|
|
SPAWNER_REQURED_PLAYER_RANGE - typo |
I already fixed that in #860. |
That was also already fixed in my PR. |
@bloodmc Might need discussion, but things related to For example: // Current
Map<BlockTrait<?>, ?> getTraitMap();
// Proposed
Map<BlockTrait<?>, ? extends Comparable<?>> getTraitMap();
// or
Map<BlockTrait<?>, Comparable<?>> getTraitMap(); |
|
@phroa mind updating the issue description of the various OCD things listed here? |
|
@ryantheleach I think only one would be needed - the value of one is simply the opposite of the other. |
|
Changes include: * Per-world scoreboards have been removed * The 'server' scoreboard is now accessible through the API * Teams are now registered to only one scoreboard at a time
|
|
|
|
@ryantheleach feature requests aren't minor changes, those should be an issue. |
Creating a new OCD list for beta See #1000 Any still unresolved issues from here that I may have missed should be reported there. |
@Saladoc remake your concern as an issue as well |
https://github.com/SpongePowered/SpongeAPI/blob/master/src/main/java/org/spongepowered/api/entity/EntityTypes.java#L64 shouldn't it be |
Track at #860
Minor Issues List
Direction:30
GameMode
javadoc uses fully qualified link toPlayer
Some method declarations inappears to have been refactored so I won't touchDataHolder
are generic although they don't have to. This leads to worse usability / more raw casts. See comment: Ongoing Minor Issue List (OCD list) #221 (comment)AbstractInventoryProperty
could extendAbstractProperty
. See comment: Ongoing Minor Issue List (OCD list) #221 (comment) for moreCheckstyle warnings
The text was updated successfully, but these errors were encountered: