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

Libraries <=> Abstract interfaces <=> Dotsimus code #4

Open
lost-in-action opened this issue Sep 14, 2021 · 4 comments
Open

Libraries <=> Abstract interfaces <=> Dotsimus code #4

lost-in-action opened this issue Sep 14, 2021 · 4 comments
Labels
enhancement New feature or request

Comments

@lost-in-action
Copy link
Collaborator

Abstraction

Bridge

For portability reasons, it's better to avoid using libraries like discord.js everywhere in the code, instead, rely on abstract interfaces for Dotsimus, and implement those abstract interfaces properly (implement what needed). discord.js should be used inside implementations of these interfaces and nowhere else: these interfaces act as a bridge between the libraries and dotsimus.
Currently only discord.js have to be bridged (it's the only external module) since it's a pretty big one, internal nodejs modules are fine (and small modules too).

Learn more about bridges here:

Reasons

The primary reason is for easier portability. Here are good reasons to rely on bridges instead:

  1. If discord.js discontinues (chances of it are very low but it's better to plan things in advance, this happened with discord.py) or changes, recovery should be done easily and quickly through abstract implementations: this means that most part of the Dotsimus code base remains untouched, only the abstract implementation have to be modified in order to switch to a new library
  2. If the Discord platform ever shut down, why not switching to another platform that supports bot? Revolt, Guilded, or anything else: switching to any of these platforms could be done quickly
  3. Can use unit testing: the trick would be to implement the interface to fake events and responses
  4. Probably a dumb idea, but who says abstract interfaces also says multiple implementations, which mean... Multi-platform bot, this is just an idea of course

Overall if something ever change in the Discord API and/or in the library, then it shouldn't affect the entire codebase, those are ideas. Hope you understand 😃

@Jasius Jasius added the enhancement New feature or request label Sep 14, 2021
@Jasius
Copy link
Member

Jasius commented Sep 14, 2021

Certainly, an interesting idea, I personally never had to do abstractions to this level thus I don't really know what hurdles this entails and how much extra complexity it adds.

@Jasius
Copy link
Member

Jasius commented Sep 14, 2021

and I like the Golden Bridge joke there ;)

@lavgup
Copy link
Contributor

lavgup commented Sep 15, 2021

Regarding unit testing, it's a tough area to dive in, and most implementations I've seen do it just for the sake of having tests and not to speed up/help development. It's probably better to not mock the API (leave that to the library developers), but to test the bot core in that everything works fine. This could branch down to utilities such as message formatters and case helpers.

Also, about your main point about using library functions, I somewhat agree. It is probably best to not use high-level interfaces too much but we shouldn't sacrifice general code quality just in the chance that discord.js may be discontinued in the future (also keep in mind that discord.py only had one core maintainer, whereas discord.js has like 4). Just for the record, discord.js helpers such as @discordjs/builders and @discordjs/rest can be appropriately be used as they are library-agnostic should we ever need to switch libraries.

@lost-in-action
Copy link
Collaborator Author

Regarding unit testing, it's a tough area to dive in, and most implementations I've seen do it just for the sake of having tests and not to speed up/help development. It's probably better to not mock the API (leave that to the library developers), but to test the bot core in that everything works fine. This could branch down to utilities such as message formatters and case helpers.

Also, about your main point about using library functions, I somewhat agree. It is probably best to not use high-level interfaces too much but we shouldn't sacrifice general code quality just in the chance that discord.js may be discontinued in the future (also keep in mind that discord.py only had one core maintainer, whereas discord.js has like 4). Just for the record, discord.js helpers such as @discordjs/builders and @discordjs/rest can be appropriately be used as they are library-agnostic should we ever need to switch libraries.

I agree, and actually after some thinking, I don't think the abstract interface is the best idea, it's time-consuming and can get complex when trying to support various libraries.
So maybe, Multi-layered software architecture as a replacement for abstract interfaces? (dotsimus seems to be doing this on some part of the code anyway) https://en.wikipedia.org/wiki/Multitier_architecture

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

No branches or pull requests

3 participants