Is there a nice syntax to achieve optional named parameters?

H. S. Teoh hsteoh at quickfur.ath.cx
Thu Jan 17 10:47:57 UTC 2019


On Thu, Jan 17, 2019 at 10:29:13AM +0000, John Burton via Digitalmars-d-learn wrote:
[...]
> Well window was just an example really, my real use case is a similar
> object that needs a lot of configuration where mostly the default
> works but you might want to override, and the config is needed to
> create the object in the first place.
[...]

When I encounter similar situations in my code, my go-to solution is to
use a struct with default field values as a configuration object that
you pass to the ctor. You can either pass .init to the ctor to get
default behavior, or declare an instance of the struct and customize as
you see fit before handing it to the ctor.


--T


More information about the Digitalmars-d-learn mailing list