Named constructors

Atila Neves atila.neves at gmail.com
Thu Jan 10 10:50:24 UTC 2019


On Wednesday, 9 January 2019 at 17:46:52 UTC, H. S. Teoh wrote:
> On Wed, Jan 09, 2019 at 05:30:32PM +0000, Atila Neves via 
> Digitalmars-d wrote:
>> [...]
>
> +1. That's what the type system is for.  Dummy arguments are 
> NEVER a good idea unless there's a need for the API to be 
> uniform.
>
> It also makes the calling code self-documenting without needing 
> language support for named arguments:
>
> 	auto myPerson = Person(FirstName("John"), LastName("Doe"));
>
> rather than the opaque (and thus error-prone):
>
> 	// Bug 1234: hmm, is it first name first, or last name first?
> 	//auto myPerson = Person("Doe", "John");
> 	auto myPerson = Person("John", "Doe");
>
>
> T

Fully in agreement. Now if only I write that library I've been 
meaning to that lets you pass parameters in any order if the 
types are right...


More information about the Digitalmars-d mailing list