June 08, 2022

On Wednesday, 8 June 2022 at 07:30:43 UTC, forkit wrote:

>

I don't want to be told I have to do the one-class-per-file thing, and I don't want to have to go off and write a linter/static-analyser.

Writing a linter is no more work than making the compiler do it. You've got the DMD source.

So what you basically say is that you don't want to write the linter, you want somebody else to do it for you.

In other words you don't nobody cares enough about this issue to put in the work.

Which isn't particularly surprising since this is one of the minor issues in the language.

June 08, 2022

On Wednesday, 8 June 2022 at 06:45:24 UTC, forkit wrote:

>

The proof is already there - i.e. C++/Java/C# programmers, already use and rely upon this feature. Imagine if those languages took it away.

Ok, you don't get why I (and D) like it to not conflate things that don't need access to the innards of a class within the same file.

I on the other side don't get why you think forbidding access from outside of one file is not encapsulation. It is. And it is easy to control: you put all friends in the same file, and nothing else. You don't have to search where all the friends may be implemented. And if you want something to have no access to the privates, just move it to some other file. Don't tell me this is error-prone or hard to review. It's much easier than to look for all friends in the whole project. I personally hate it if I should review a file and then need to look into dozends of other files to do this. And C++ tend to always require this. One of my main reasons to drop C++.
Java doesn't even allow friends or subclasses to reside within the same file, and nobody complains about that or claims that this is not encapsulation.

June 08, 2022
On Wednesday, 8 June 2022 at 06:56:50 UTC, Walter Bright wrote:
>
> The unit of encapsulation in D is the module, not the class.

Why is it less of an abomination? Class is the unit of encapsulation by the very definition of OOP. D just forces you into the class-per-module paradigm, basically redefining modules as classes. That is just as abominable, given friends are rare in "properly" designed OOP code.
June 08, 2022

On Wednesday, 8 June 2022 at 08:11:41 UTC, Dom Disc wrote:

>

look for all friends in the whole project. I personally hate it if I should review a file and then need to look into dozends of other files to do this. And C++ tend to always require this. One of my main reasons to drop C++.

I think many such issues actually are tooling issues and architecture issues just as much as language issues.

It is very difficult to talk of C++ being this or that since the language itself doesn't impose much structure. You can have a good or bad structure, and it really comes down to modelling, design patterns, software architecture choices and discipline.

Other languages impose more firm structure and that can be good, or bad, depending on what you try to achieve, but you can also use tooling to establish a structure so…

Is the language dominating the strucuture?

Or is the structure a result of the culture of the people using it?

Most of the time it is the latter, it is the culture and the people.

June 08, 2022
On Wednesday, 8 June 2022 at 08:23:31 UTC, Max Samukha wrote:
> That is just as abominable, given friends are rare in "properly" designed OOP code.

Not in C++. E.g. operator overloads with the class as second operand but some basic type as first operand _can't_ be member functions (because C++ doesn't have op_right). But operators tend to really need access to the innards, so most of the time they have to be friends. And there are many operators, hence many friends...
June 08, 2022

On Wednesday, 8 June 2022 at 08:23:31 UTC, Max Samukha wrote:

>

On Wednesday, 8 June 2022 at 06:56:50 UTC, Walter Bright wrote:

>

That is just as abominable, given friends

>

are rare in "properly" designed OOP code.

Right!

June 08, 2022

On Wednesday, 8 June 2022 at 08:45:54 UTC, zjh wrote:

>

That is just as abominable, given friends

>

are rare in "properly" designed OOP code.

Right!

I even forgot friend. I don't need friend.

June 08, 2022

On Wednesday, 8 June 2022 at 08:41:36 UTC, Dom Disc wrote:

>

But operators tend to really need access to the innards, so most of the time they have to be friends. And there are many operators, hence many friends...

This is something that can be fixed by a dedicated IDE though. So this is just syntax.

What you might want to do in C++ is to implement "*=", "+=" etc inside the class and then the external operators can be created without access to the internals.

June 08, 2022
On Wednesday, 8 June 2022 at 08:36:10 UTC, Ola Fosheim Grøstad wrote:
>
> Is the language dominating the strucuture?
>
> Or is the structure a result of the culture of the people using it?
>
> Most of the time it is the latter, it is the culture and the people.

In D, it's certainly the language that is dominating the structure here.

4 facts:

(1) A class is THE 'central' notion to OO programming.

(2) A class implements a type.

(3) The OO features in D, all come from the class.

(4) In D, classes are (also) programmer defined types.

A module should not have ownership over the specification of a type. That ownership should belong to the person writing that specification. It's the language that is enforcing a different structure (in terms of OO design) here.

Fine. D has decided that module will make the decision, by making everthing within a module a friend of any type declared within that module. If this was a design decision because of the problems of 'friend' in C++, fine. That makes sense. I get it. But does it really make sense that you cannot unfriend? This should be a decision the programmer at least has the 'option' of making.

In my 'perfect world' view of D, the module should only have ownership of 'the aggregation' of the related abstractions that are contained within it, thus providing a nice barrier to the outside world for that 'aggregation'.

When the module owns the specifications of all the abstractions contained within it, there are consequences. How can type conformance be enforced within a module? It can't. Imagine if I could, accidently, willy nilly, put a "wtf!" into an int, and not even know about it, till it was too late.

Walter has his firm view. I have mine.
June 08, 2022

On Wednesday, 8 June 2022 at 09:34:09 UTC, forkit wrote:

>

Walter has his firm view. I have mine.

Sure, your viewpoint would make sense for D3, but then there would be many such adjustments to make.

To make all those adjustments in D2 with no breaking change would @lead @to @a @mess.