DIP 1030--Named Arguments--Community Review Round 1 Discussion
matheus
matheus at gmail.com
Fri Feb 7 22:28:27 UTC 2020
On Friday, 7 February 2020 at 21:57:18 UTC, H. S. Teoh wrote:
> 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.
>...
Hold your rant buddy I was just replying to your example :)
>> > myRange.process(2); // what does '2' mean?!
But of course seeing a code like:
> enum two = 2; // look, ma! I know how to name magic numbers!
> myRange.process(two); // yay, no more magic numbers!
Would be totally nonsense to me too. On the other hand:
> myRange.process(nRetries);
For me would be ok and a standard where I work. And the IDE would
give me the hint about the value of nRetries.
Talking about magic numbers, well I had enough of it after diving
into code like[1]:
> tempy = 0x80000000;
> for(i=-131072;i<=131072;i+=(2048>>gride))
> plc = x1+mulscale12((2047-y1)&4095,inc);
> i = ((y1+2048)>>12); daend = ((y2+2048)>>12);
And need to understand each number. :)
Matheus.
[1] -
https://github.com/videogamepreservation/dukenukem3d/blob/master/SRC/ENGINE.C
More information about the Digitalmars-d
mailing list