What’s the usecase? There’s no concept of optional import in most languages, so it doesn’t seem so necessary to me.
Well I’m not agreeing about it. This concept is quite used in Ruby, but not only in Ruby. In some languages, there’s concept of optional import. Just yesterday, toying with dwm:
#ifdef XINERAMA
#include <X11/extensions/Xinerama.h>
#endif /* XINERAMA */
In Ruby, it’s very common pattern
In cpp it uses flags to add or remove features on build. I’m just thinking this is obsolete with a language like Crystal. Since the shards are present in a relative lib
directory, we can assume than if we install a specific shard in our project, it’s for using it.
Example
Let’s assume I’ve a shard to upload in a bucket some files. I offer interface for AWS, Google Cloud Storage, and Digital Ocean.
For each of these gateway I’ve a dependent shard I use to connect to theses API.
Currently:
- When someone is installing my shard, it will install all the dependent shards, for AWS, Google Cloud etc…
- The source-code will bloat, while the final user want only one environnement, not all the providers.
OR
- Explain to the final user how to include the dependency for the environment he wants
- Ask the final user to require both my shard (
require "myshard"
) and the file connecting to gateway he wants (require "myshard/aws"
)
Now with this feature, the process for the final user would be:
- If the user want to use a specific gateway without the shard installed, will drop a compile-time raise error which describe what to do.