Hipreme's #1 Tip of the day
Hipreme
msnmancini at hotmail.com
Wed Oct 19 23:28:46 UTC 2022
Hey guys, I'm going to start making a tip of the day (although
I'm pretty sure I won't be able to give every day a tip), but
those things are really interesting to newcomers to know and may
be obvious to some of the old schoolers there.
Always public import a type that the user (including you) is
expected to interact with:
Imagine we have a module A that define a tree
```d
module a;
struct Tree(T){}
```
If you create a module b containing a function that returns a
tree:
```d
module b;
import a;
Tree!string getDirectoryTree(string entry){return null;}
```
This is virtually unusable! One must `public import a: Tree;`
This will make your API a lot easier to interact with, keep in
mind to always public import some type that is used from another
dependency like this, but try to not overdo it.
More information about the Digitalmars-d-learn
mailing list