DIP 1030--Named Arguments--Community Review Round 1 Discussion

H. S. Teoh hsteoh at quickfur.ath.cx
Fri Feb 7 21:57:18 UTC 2020


On Fri, Feb 07, 2020 at 07:59:41PM +0000, matheus via Digitalmars-d wrote:
> On Friday, 7 February 2020 at 19:26:10 UTC, H. S. Teoh wrote:
> > ...
> > However, I *have* also found myself desiring nameable arguments for
> > the sake of self-documenting code, for example:
> > 
> > 	myRange.process(nRetries: 2);
> > 
> > as opposed to:
> > 
> > 	myRange.process(2); // what does '2' mean?!
> > ...
> 
> Yes this is one case that people will argue in favor of named
> arguments, but on the other hand I would point out: Why is he using a
> magic number in a code? :)

<rant>

IMNSHO, the obsession with getting rid of magic numbers is a bunch of
hooey.  There's a time and place for that, e.g., you don't want two
pieces of code to go out of sync when the constants they use must match
a common value.  But pushing this to the extremes leads to stupid code
like this:

	enum two = 2; // look, ma! I know how to name magic numbers!
	myRange.process(two); // yay, no more magic numbers!

which is completely ridiculous.

If the constant only appears in one place, just write the damn constant
out already, that's why the programming language has integer literals,
dammit. Giving it a name just because "magic numbers are Bad(tm)" is
stupid.

</rant>


[...]
> https://docs.microsoft.com/en-us/dotnet/api/system.dayofweek?view=netframework-4.8#examples
> 
> You will see a example of DateTime usage like this:
> 
> > // Assume the current culture is en-US.
> > // Create a DateTime for the first of May, 2003.
> >    DateTime dt = new DateTime(2003, 5, 1);
> 
> They didn't even bother to use named arguments there. They just warned
> about culture en-US. :)

Actually, that's not en-US. In *true* American style, the correct order
of arguments should be (5, 1, 2003). :-P

(Which IMNSHO is a stupid, illogical convention, which gets especially
bad when they drop the first 2 digits of the year, and then you get
incomprehensible dates like 10/12/11: is it Oct 12, 2011? Dec 10, 2011?
Or Dec 11, 2010?  Or maybe Nov 12, 2010? Who even knows. Everyone should
just stick with ISO-style yyyy-mm-dd, dangit!!)


> Well in my opinion I would prefer to see development in other areas
> than in this particular case.
[...]

True, Walter himself has said D needs to have a small number of powerful
tools that are very expressive, rather than be a kitchen sink full of
every feature you can think of but each is anemic and more-or-less
redundant.


T

-- 
Do not reason with the unreasonable; you lose by definition.


More information about the Digitalmars-d mailing list