Postfix type notation - readability and parsing?
Simen Kjærås
simen.kjaras at gmail.com
Wed Mar 6 07:53:42 UTC 2019
On Tuesday, 5 March 2019 at 22:29:33 UTC, aliak wrote:
> 1) putting the variable name at the end makes it hard to see
> and you'd need to scroll horizontally to get to see what this
> type is for.
>
> 2) doing it like the above is confusing to see which name
> belongs to which type because you're so used to a type
> declaration being on one line.
>
> 3) Splitting it over multiple lines like:
>
> static immutable Option!(
> ushort,
> "p|port",
> "Sets the port used for serving.",
> "PORT",
> 8888
> ) port;
>
> 4) Deciding to go with a mixin approach so you can have the
> variable name on the left and on the same line like:
>
> mixin Option!("port", ushort, "p|port", "Sets the port used
> for serving.", "PORT", 8888);
>
> 5) putting it on the right after an opAssign ala:
>
> auto port = Option!(...)
Just to add a 6) to the mix:
alias port = Option!(immutable ushort, "p|port", "Sets the port
used for serving.", "PORT", 8888);
static this() {
port = 1234;
}
template Option(T, string s, string s2, string s3, T
defaultValue) {
import std.traits : Unqual, CopyTypeQualifiers;
struct Impl {
Unqual!T _value;
alias _value this;
this(T t) {}
}
CopyTypeQualifiers!(T, Impl) Option;
}
// Also does the right thing in structs and classes:
struct S {
static alias port = Option!(immutable ushort, "p|port", "Sets
the port used for serving.", "PORT", 8888);
}
static this() {
S.port = 1234;
}
--
Simen
More information about the Digitalmars-d
mailing list