Bug 19638 – Demos should not use auto

Status
RESOLVED
Resolution
INVALID
Severity
enhancement
Priority
P1
Component
dlang.org
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-02-02T16:02:26Z
Last change time
2019-02-02T16:51:54Z
Assigned to
No Owner
Creator
Faissal bensefia

Comments

Comment #0 by faissaloo — 2019-02-02T16:02:26Z
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