Creating a pointer array

H. S. Teoh hsteoh at quickfur.ath.cx
Wed Aug 19 20:25:08 UTC 2020


On Wed, Aug 19, 2020 at 08:09:31PM +0000, bachmeier via Digitalmars-d-learn wrote:
[...]
> Maybe I'm the only one, but I think double*[] is hideous, and I'd sure
> hate for someone not used to D to see it.

IMO, double*[] is absolutely logical. It's a natural consequence of type
syntax.


> Alias is your friend. I think this is much nicer:
> 
> void main() {
>     alias double* DoublePtr;
>     DoublePtr[] arr;
[...]

IMO, this is far too verbose.  If I had 10 arrays of 10 different types
of pointers, I wouldn't want to write 10 aliases just for that. Plus,
hiding things behind an alias means someone who reads your code has to
look up the alias definition to figure out what it means, whereas if
they see double*[] the exact meaning is immediately obvious.

I'd only use an alias for inordinately-long type names, like function
pointers or delegates with lots of parameters, or verbose type names
like const(int[])[string]. (And even in the latter case, only when the
name occurs frequently.)

But as they say, YMMV. :-)


T

-- 
"A man's wife has more power over him than the state has." -- Ralph Emerson


More information about the Digitalmars-d-learn mailing list