core-java icon indicating copy to clipboard operation
core-java copied to clipboard

Rename `Nothing` type to avoid confusion with Kotlin's

Open alexander-yevsyukov opened this issue 4 years ago • 6 comments

Kotlin has standard type which is named Nothing. It is used in function declarations when it never returns because of throwing an exception.

We have a specialized Message type, io.spine.server.model.Nothing, which serves as a return type of handler methods that do not return anything. These methods do return an instance of such message and exit normally.

This may bring various confusions for Kotlin people:

  • Why do we have a handler method that never completes? Just by looking at the method signature, it's not possible to tell that it's Spine-specific Nothing, not the standard Kotlin's one.
  • What doesn't this handler work? I don't know what declaring wrong Nothing in a Kotlin code for a handler would cause, but I'm not sure it would be OK.
  • Fully-qualified Spine's Nothing when the user's code needs to use Kotlin's one.
  • etc.

In order to avoid this confusion we need to have a type with another name.

alexander-yevsyukov avatar Nov 27 '20 17:11 alexander-yevsyukov

To be mentioned as breaking change in Release Notes.

alexander-yevsyukov avatar Dec 04 '20 18:12 alexander-yevsyukov

Suggested alternative name: None.

alexander-yevsyukov avatar Dec 04 '20 18:12 alexander-yevsyukov

Previously suggested empty Tuple type won't work because our Nothing is frequently used in tules like this: EitherOf2<JobComplete, Nothing>.

alexander-yevsyukov avatar Oct 30 '22 09:10 alexander-yevsyukov

We currently have two typealias-es called NothingHappened and NoReaction. This should ease the name clash with the standard Kotlin type.

See the io.spine.server.model.EventExts.kt file for details.

alexander-yevsyukov avatar Apr 16 '24 16:04 alexander-yevsyukov

@alexander-yevsyukov We can only return Nothing in reaction to some event, which we may or may not want to react upon. It is impossible to return Nothing from a command handler for obvious reasons.

NoReaction reflects what we want to say perfectly:

"Something has happened, and we could potentially react on it. But at this time, we chose not to."

Using NothingHappened is misleading, because it sounds like an event. But as stated earlier, some event has happened—we just don't want to react.

Therefore, I'd stick to NoReaction as a typealias. And I would drop NothingHappened.

armiol avatar Apr 16 '24 17:04 armiol

Therefore, I'd stick to NoReaction as a typealias. And I would drop NothingHappened.

Yeah, see this commit.

alexander-yevsyukov avatar Apr 16 '24 17:04 alexander-yevsyukov

Resolved by #1554.

alexander-yevsyukov avatar Oct 10 '24 14:10 alexander-yevsyukov