Thread overview | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
January 21, 2016 Please change alias ReplaceArrayWithPointer = Flag!"replaceArrayWithPointer" | ||||
---|---|---|---|---|
| ||||
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 Re: Please change alias ReplaceArrayWithPointer = Flag!"replaceArrayWithPointer" | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | 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 Re: Please change alias ReplaceArrayWithPointer = Flag!"replaceArrayWithPointer" | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | 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 Re: Please change alias ReplaceArrayWithPointer = Flag!"replaceArrayWithPointer" | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | 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 Re: Please change alias ReplaceArrayWithPointer = Flag!"replaceArrayWithPointer" | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | 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 Re: Please change alias ReplaceArrayWithPointer = Flag!"replaceArrayWithPointer" | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | 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 Re: Please change alias ReplaceArrayWithPointer = Flag!"replaceArrayWithPointer" | ||||
---|---|---|---|---|
| ||||
Posted in reply to jmh530 | 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 Re: Please change alias ReplaceArrayWithPointer = Flag!"replaceArrayWithPointer" | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jack Stouffer | 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 Re: Please change alias ReplaceArrayWithPointer = Flag!"replaceArrayWithPointer" | ||||
---|---|---|---|---|
| ||||
Posted in reply to H. S. Teoh | 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 Re: Please change alias ReplaceArrayWithPointer = Flag!"replaceArrayWithPointer" | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jack Stouffer | 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
|
Copyright © 1999-2021 by the D Language Foundation