Why is D unpopular

forkit forkit at gmail.com
Mon Jun 13 09:58:59 UTC 2022


On Monday, 13 June 2022 at 07:59:24 UTC, bauss wrote:
>
> ....
> D states it is "module private" but really it is neither 
> "module private" or "class private" it's a mix between the 
> two... and I'm not sure whether that's good or not.

on the issue of 'good or bad', well the answer is subjective.

It depends on what you want, and expect.


// ----
module test;
@safe:

import std;

void myFunc()
{
     int a = 100; // a is bound (private) to scope, not module
                  // so = good, I wanted and expected this.
}

class foo
{
     static private int b = 200; // b is bound to module scope
                                 // even though I thought I was 
binding it to local scope
                                 // This is not what I wanted or 
expected.
                                 // so module global = bad.
}

class bar
{
     static private(module) int c = 300; // c is bound to module 
scope
}                                       // good, that's what I 
wanted and expected.

void main()
{
     writeln(a); // won't compile = good

     writeln(foo.b); // will compile = bad.
                     // bad cause compiler has no idea what i 
wanted,
                     // cause i can't tell it what I wanted.
                     // there is no feature in D to do this.

    writeln(bar.c); // will compile = good. It's what I wanted and 
expected.
}

// --------


More information about the Digitalmars-d mailing list