Is there some kind of Blocking Queue for D?

Steven Schveighoffer schveiguy at gmail.com
Mon Jul 14 02:10:40 UTC 2025


On Saturday, 12 July 2025 at 23:55:39 UTC, Ali Çehreli wrote:
> On 7/11/25 11:36 PM, Bienlein wrote:
>
> > Unhappily class MessageBox is private and therefore cannot be
> reused.
>
> Ah! :) That's one more data point against 'private', that 
> little feature that helps with nothing. I don't know what 
> language invented it but I wouldn't be surprised if it came to 
> D from C++.

C also has private. It's called `static`. Or sometimes `pImpl` 
(for types).

>
> The only thing 'private' achieves is this: You don't want your 
> users to be disappointed when they go out of their way to use 
> features that they are advised not to use, and those features 
> behave differently in the future. Really? That never happens. 
> Well, if it indeed happened ever, the user went out of their 
> way to be surprised, didn't they?

No, that is not what private is for.

Private means you get to define the API of your code. If you 
don't have it, anyone can come in and change anything and you 
can't do anything about it. Testing your code in a production 
environment is impossible, because *anyone can do anything*. 
Invariants can never be trusted. Nobody can reason about the code 
in any sensible way. Private data is very important when properly 
used.

In this case, the fact that `MessageBox` is unusable to a user is 
*not* the fault of `private`. It's just that the author happened 
to use the `private` attribute to prevent others from using it. 
There are other ways, and without private, they likely would have 
used one of those ways.

We have `std.internal` and `core.internal`. Perhaps the better 
mechanism than using `private` is to put it in here. Then at 
least it's known to be an internal detail, but still usable by an 
adventurous user.

Note, I have also recently run into some [foolishness in the 
library WRT private 
symbols](https://github.com/dlang/dmd/blob/e0cf19144f2afed531cc2f40eee7e051994d4e98/druntime/src/core/thread/threadbase.d#L73-L87)

Just like anything, it can be misused.

-Steve


More information about the Digitalmars-d-learn mailing list