What are the prominent downsides of the D programming language?

H. S. Teoh hsteoh at quickfur.ath.cx
Tue Sep 29 16:46:19 UTC 2020


On Tue, Sep 29, 2020 at 03:35:42PM +0000, ddcovery via Digitalmars-d wrote:
[...]
> My "difficulty" (I assume it is my problem) is when reading
> documentation about methods returning "auto"... it's hard, at the
> beginning, to transform this mentally in something I can understand
> (trying not to hide mentally the information)... D plasticity differs
> to other simplest "generics" type systems (like Scala) and you need
> double effort to understand it.

IMO, this is more a problem with the documentation than with `auto`
itself.  The documentation really should be stating exactly what you can
/ cannot do with the returned object.  But beyond that, a function that
returns `auto` really means "the return type is not important to be able
to use this function", and by extension, "you really shouldn't need to
know what the concrete type is; if you do, you're probably using this
function wrong".

This is where it's extremely important for the docs to be as clear as
possible about what you can do with the opaque return value.


> An added difficulty  (that I don't know if the "swift developers" will
> suffer with xcode) is the missing of a good "autocomplete" or "type
> inference" that helps developers to understand the type that an "auto"
> function is really returning in the context of an evocation (i.e.:
> Right now, I am working with flutter/dart and vscode shows me the
> inferred type of a variable when hovering with the mouse).
[...]

This is a tooling problem; if an issue hasn't been filed already, it
should be filed so that this can be improved.  Technically speaking,
it's just a matter of inserting `pragma(msg, typeof(return));` into the
function; but of course if this were automated by an IDE plugin that
would be ideal.

Note that knowing the concrete type may or may not help you always;
sometimes the concrete type may be a complex internal implementation
type that may be even harder to understand than reading properly-written
docs. :-P  Or sometimes it's a Voldemort type with a generic name like
`Result` that doesn't really give you very much information (the point
being, if the function was designed properly and used properly, you
should not need to care what the actual type is).


T

-- 
Ignorance is bliss... until you suffer the consequences!


More information about the Digitalmars-d mailing list