auto arr = [1, 2, 3] should be a static array, not a GC allocated array
ryuukk_
ryuukk.dev at gmail.com
Thu Jul 14 14:37:34 UTC 2022
On Thursday, 14 July 2022 at 13:30:58 UTC, jfondren wrote:
> On Thursday, 14 July 2022 at 13:14:59 UTC, ryuukk_ wrote:
>> It is misleading, nobody expect this to be GC allocated
>
> People expect that who try to append to it later on in the
> function. The book "Learning D" really emphasizes stuff like
> this, useful but potentially surprising parts of the native
> types of the language.
Then the compiler should tell them that it is a static array and
they should be explicit if they want to append
Corner cases from clueless people shouldn't make the default
useless and misleading
> All languages have stuff like this. D has a performance hazard
> in treating dynamic arrays like stacks; Go avoids that while
> having the fun design where appending to a slice might modify a
> different slice.
I disagree hard, not "all languages have stuff like this" D has
stuff like this
Maybe Java/C# but they don't have the concept of static arrays,
again, who's the target audience of D?
>
>> It should be equal to:
>>
>> ```D
>> int[3] arr = [1, 2, 3]
>> ```
>>
>> Also why it is GC allocated without requiring ``new``?
>
> D doesn't have a principle like "GC allocations should all be
> signposted with `new`". These visual-signposting principles are
> neat and all, but as long as the language has pervasive
> function-calling, every single one can violate the principle.
> What D *does* have is `@nogc`
>
> https://dlang.org/spec/garbage.html#op_involving_gc
It is a mistake then
Little rant:
As time goes by, i'm thinking more and more to finally learn
language programming and fork D to get rid of all these stuff
that makes me want to look for an alternative language
Every once in a while i get reminded why i had that thought,
thanks to issues i encounter like this one, very frustrating when
you take into account that nobody wants new features and instead
want to rely on template soup indefinitely
static arrays? just use
```D
import std;
auto arr staticArray!int(1,2, 3);
```
"no need to change the language"
More information about the Digitalmars-d
mailing list