The use of auto in the runnable demos is pervasive across the language documentation however this is extremely unhelpful when trying to adapt these demos into useful programs as I cannot infer the type of the variable myself. There are situations where one may wish to initialise a variable differently based on a condition and so I will need to forward declare the variable however I cannot do this because I do not know the type I should be using to declare because it has been obscured by the use of auto in the demo.
Comment #1 by greeenify — 2019-02-02T16:51:54Z
> so I will need to forward declare the variable however I cannot do this because I do not know the type I should be using to declare because it has been obscured by the use of auto in the demo.
Are you aware of e.g. `typeof`?
---
auto r = 10.iota;
---
is equal to:
---
typeof(10.iota) r;
...
r = 10.iota;
---
I will close this as invalid, because:
- for many functions in Phobos one doesn't even now the type
- `auto` is easier to read (less visible space)
- `auto` is smarter as you don't need to change anything if you refactor code (also good for copy&paste examples)
I encourage you to look up Voldemort types (https://wiki.dlang.org/Voldemort_types) and post to the Learn group for more questions