Please change alias ReplaceArrayWithPointer = Flag!"replaceArrayWithPointer"
H. S. Teoh via Digitalmars-d
digitalmars-d at puremagic.com
Thu Jan 21 13:58:59 PST 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
More information about the Digitalmars-d
mailing list