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

Lazy loading Discord objects #49

Open
pmdevita opened this issue Nov 13, 2023 · 0 comments
Open

Lazy loading Discord objects #49

pmdevita opened this issue Nov 13, 2023 · 0 comments

Comments

@pmdevita
Copy link
Owner

pmdevita commented Nov 13, 2023

Hikari's rest interface and its cache present two alternate ways to perform many tasks, either through an object from the cache or directly on the rest API. While this makes sense from Hikari's perspective as a foundation for other libraries, it can pose a challenge to developers who must decide on the correct interface for each task. Worse as well, the consequences for choosing the wrong interface may not be immediately obvious. To break out The Zen of Python,

There should be one-- and preferably only one --obvious way to do it.

A solution I've seen for this implemented in other API libraries is lazy loading objects. For example, a TextChannel could be instantiated from purely its Snowflake ID, which would be enough to perform many operations through the rest interface. Attempts to access a property could then pull in information from the cache.

This is something that should be considered carefully though because its implementation greatly increases scope and documentation requirements. There's also the problem of async and lazy loading properties, a developer isn't going to await a property access. Would be cool to get other opinions on this but I think I'm still the only person using this library 🥲


As an example for a pattern for loading properties asynchronously, asyncpraw simply returns None unless you have called refresh().

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

No branches or pull requests

1 participant