Library settings, best practices?
Adam D. Ruppe
destructionator at gmail.com
Sat Dec 8 17:05:50 UTC 2018
On Saturday, 8 December 2018 at 16:58:24 UTC, Vladimirs Nordholm
wrote:
> Is there a best practice to enabling specific parts of a
> library?
For my terminal library, I put it all in a struct. Then the user
gets to choose how to initialize it, and its destructor gets a
chance to cleanup when done. The terminal object also contains
its methods so you feel like you are getting something out of it
by using them.
I know you prefer not to have the user call initializer
functions, but I really do think it is the cleanest way to do it.
Alternatively, you could perhaps have it keep an internal
is_initialized flag and lazily call init on your other function
calls if it is not already done. Then if the user wants to
customize settings, they just call init before calling anything
else, and if not they skip the init call and it gets default
setup first time they try to use it.
More information about the Digitalmars-d-learn
mailing list