Should we contain to create callbacks for new APIs? #1532
-
This topic was started in this PR: #1528 (review) Currently, Mineflayer is moving away from callbacks and moving towards using Promise-based code. The main codebase has already been converted over, and most other modules and plugins for Mineflayer are planned to follow very soon. The question is should new APIs also create new callbacks for them, or should we encourage users to move away from callbacks completely? Existing callbacks will remain either way simply for backward compatibility. Our options are to continue to create callbacks for all new APIs, or depreciate the use of callbacks entire and only maintain existing ones for backward compatibility only. |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 4 replies
-
In my opinion, callbacks are there just for backwards compatibility. Any new features or breaking changes to existing features should incorporate only promise versions and not callback versions, as this will only encourage sticking to the callback system, which IMO should be slowly deprecated and then phased out. |
Beta Was this translation helpful? Give feedback.
-
Personally, I agree with this. Moving to use solely promise-based designs will produce more intuitive and readable code, especially with how asynchronous the Mineflayer API is. await bot.dig(block)
bot.setControlState('jump', true)
await bot.waitForTicks(10)
bot.setControlState('jump', false)
await bot.placeBlock(bot.entity.position.offset(0, -1, 0)) This is significantly more readable and beginner-friendly than callbacks would be. I notice that a lot of new users don't understand the async nature of Mineflayer, so they'll tend to write things like: bot.dig(...)
bot.dig(...)
bot.dig(...) then get confused why it's not working. With promises, just write the word Personally, I would go as far as printing a depreciation warning on startup when using callbacks. |
Beta Was this translation helpful? Give feedback.
-
Yes, we have the callbacks API for backwards compatibility though, if a developer who feels better with callbacks comes to us and see that we support both approaches - how much disappointment would he have when he finds out that the code he's been trying to write for last 2 hours with callbacks is only promise API? In my opinion, if we're supporting both approaches, then we are supporting them both. Like @TheDudeFromCI said, we can print a deprecation warning on first occurance of callback function. Also maybe on install? Provided we ARE going to deprecate the callback API. |
Beta Was this translation helpful? Give feedback.
-
I believe this also covers examples, as well. If we decide to support both, we'll have to maintain examples that cover both use cases. |
Beta Was this translation helpful? Give feedback.
-
I think we should indeed deprecate the callback API.
Once this is true, we can consider adding deprecation warnings and tell users not to use callback API (if someone wants to prepare a PR to do this that we won't merge right now, feel free) For the specific question of small new features, I'd say let's not add the callback version. Users wanting to use it in a callback-based app, can always do function().then(() => cb()) |
Beta Was this translation helpful? Give feedback.
-
Okay, this seems like a good direction for us to move in. I agree. |
Beta Was this translation helpful? Give feedback.
I think we should indeed deprecate the callback API.
However I think we should only do it once we are confident there are no remaining issue for the promise API.
To validate this I think it's useful to:
Once this is true, we can consider adding deprecation warnings and tell users not to use callback API (if someone wants to prepare a PR to do this that we won't merge right now, feel free)
For the specific question of small new features, I'd say let's not add the callback version. Users wanting to use it in a callback-based app, can always do function().…