Jump to page: 1 2
Thread overview
Please change alias ReplaceArrayWithPointer = Flag!"replaceArrayWithPointer"
Jan 21, 2016
Ilya
Jan 21, 2016
Ilya Yaroshenko
Jan 21, 2016
Guillaume Piolat
Jan 21, 2016
Jack Stouffer
Jan 21, 2016
H. S. Teoh
Jan 22, 2016
Marc Schütz
Jan 22, 2016
Zekereth
Jan 21, 2016
jmh530
Jan 21, 2016
Brad Anderson
Jan 22, 2016
Jacob Carlborg
Jan 22, 2016
Ilya
Jan 23, 2016
Jacob Carlborg
January 21, 2016
The correct idiom involving Flag is:

* Use the name Flag!"frob" for the type of the flag

* Use Yes.frob and No.frob for the flag values

* Do NOT alias Flag!"frob" to a new name. This is unnecessary, unhelpful, and wasteful.

Can somebody please change the respective code in std.experimental.ndslice?


Thanks,

Andrei
January 21, 2016
On Thursday, 21 January 2016 at 19:31:19 UTC, Andrei Alexandrescu wrote:
> The correct idiom involving Flag is:
>
> * Use the name Flag!"frob" for the type of the flag
>
> * Use Yes.frob and No.frob for the flag values
>
> * Do NOT alias Flag!"frob" to a new name. This is unnecessary, unhelpful, and wasteful.
>
> Can somebody please change the respective code in std.experimental.ndslice?
>
>
> Thanks,
>
> Andrei

OK --Ilya
January 21, 2016
On Thursday, 21 January 2016 at 19:31:19 UTC, Andrei Alexandrescu wrote:
> The correct idiom involving Flag is:
>
> * Use the name Flag!"frob" for the type of the flag
>
> * Use Yes.frob and No.frob for the flag values
>
> * Do NOT alias Flag!"frob" to a new name. This is unnecessary, unhelpful, and wasteful.
>
> Can somebody please change the respective code in std.experimental.ndslice?
>
>
> Thanks,
>
> Andrei

https://github.com/D-Programming-Language/phobos/pull/3946
January 21, 2016
On Thursday, 21 January 2016 at 19:31:19 UTC, Andrei Alexandrescu wrote:
> The correct idiom involving Flag is:
>
> * Use the name Flag!"frob" for the type of the flag
>
> * Use Yes.frob and No.frob for the flag values
>
> * Do NOT alias Flag!"frob" to a new name. This is unnecessary, unhelpful, and wasteful.
>
> Can somebody please change the respective code in std.experimental.ndslice?
>
>
> Thanks,
>
> Andrei

Found these guidelines useful:

http://p0nce.github.io/d-idioms/#Using-std.typecons.Flag-like-a-pro
January 21, 2016
On Thursday, 21 January 2016 at 19:31:19 UTC, Andrei Alexandrescu wrote:
> * Do NOT alias Flag!"frob" to a new name. This is unnecessary, unhelpful, and wasteful.

I disagree. Making an alias means the user does not have to import std.typecons in their code, and as a purely subjective measure, ReplaceArrayWithPointer.Yes looks better than Flag!"replaceArrayWithPointer".Yes.
January 21, 2016
On Thursday, 21 January 2016 at 19:31:19 UTC, Andrei Alexandrescu wrote:
> The correct idiom involving Flag is:
>
> * Use the name Flag!"frob" for the type of the flag
>
> * Use Yes.frob and No.frob for the flag values
>
> * Do NOT alias Flag!"frob" to a new name. This is unnecessary, unhelpful, and wasteful.
>
> Can somebody please change the respective code in std.experimental.ndslice?
>
>
> Thanks,
>
> Andrei

Perhaps
https://dlang.org/phobos/std_typecons.html#.Flag
should be adjusted. It recommends aliasing.
January 21, 2016
On Thursday, 21 January 2016 at 20:42:56 UTC, jmh530 wrote:
> On Thursday, 21 January 2016 at 19:31:19 UTC, Andrei Alexandrescu wrote:
>> The correct idiom involving Flag is:
>>
>> * Use the name Flag!"frob" for the type of the flag
>>
>> * Use Yes.frob and No.frob for the flag values
>>
>> * Do NOT alias Flag!"frob" to a new name. This is unnecessary, unhelpful, and wasteful.
>>
>> Can somebody please change the respective code in std.experimental.ndslice?
>>
>>
>> Thanks,
>>
>> Andrei
>
> Perhaps
> https://dlang.org/phobos/std_typecons.html#.Flag
> should be adjusted. It recommends aliasing.

https://github.com/D-Programming-Language/phobos/pull/3947
January 21, 2016
On Thu, Jan 21, 2016 at 08:42:17PM +0000, Jack Stouffer via Digitalmars-d wrote:
> On Thursday, 21 January 2016 at 19:31:19 UTC, Andrei Alexandrescu wrote:
> >* Do NOT alias Flag!"frob" to a new name. This is unnecessary, unhelpful, and wasteful.
> 
> I disagree. Making an alias means the user does not have to import std.typecons in their code, and as a purely subjective measure, ReplaceArrayWithPointer.Yes looks better than Flag!"replaceArrayWithPointer".Yes.

Yeah, and it looks even worse in function signatures, especially when default arguments are present:

	auto myFunc(T)(T data, Flag!"replaceArrayWithPointer" replaceArrayWithPointer = Flag!"replaceArrayWithPointer".Yes)
	{ ... }

vs.

	alias ReplaceArrayWithPointer = Flag!"replaceArrayWithPointer";
	auto myFunc(T)(T data, ReplaceArrayWithPointer replaceArrayWithPointer = ReplaceArrayWithPointer.Yes)
	{ ... }

Still pretty bad, but at least it's a few characters less.

On a tangential note, default arguments seriously should allow abbreviated syntax, to prevent the blatant violation of DRY as shown above:

	auto myFunc(T)(T data, ReplaceArrayWithPointer replaceArrayWithPointer = .Yes)
	{ ... }

Basically, inside a default argument spec, it should be as though the delcaration were encased in a `with(T) { ... }` block where T is the type of the argument.

Even better would be a way to not have to type out the variable name when it is just the type name camelcased, but I haven't thought of a way of doing this that fits in with D's current syntax just yet.  Some manner of "eponymous variable", along the same idea as eponymous templates.


T

-- 
Programming is not just an act of telling a computer what to do: it is also an act of telling other programmers what you wished the computer to do. Both are important, and the latter deserves care. -- Andrew Morton
January 21, 2016
On 01/21/2016 04:58 PM, H. S. Teoh via Digitalmars-d wrote:
> 	auto myFunc(T)(T data, Flag!"replaceArrayWithPointer" replaceArrayWithPointer = Flag!"replaceArrayWithPointer".Yes)
> 	{ ... }

auto myFunc(T)(T data,
    Flag!"replaceArrayWithPointer" flag = Yes.replaceArrayWithPointer)


Andrei

January 21, 2016
On 01/21/2016 03:42 PM, Jack Stouffer wrote:
> On Thursday, 21 January 2016 at 19:31:19 UTC, Andrei Alexandrescu wrote:
>> * Do NOT alias Flag!"frob" to a new name. This is unnecessary,
>> unhelpful, and wasteful.
>
> I disagree. Making an alias means the user does not have to import
> std.typecons in their code, and as a purely subjective measure,
> ReplaceArrayWithPointer.Yes looks better than
> Flag!"replaceArrayWithPointer".Yes.

That would be Yes.replaceArrayWithPointer. -- Andrei
« First   ‹ Prev
1 2