Jump to page: 1 210  
Page
Thread overview
Sealed classes - would you want them in D? (v2)
May 17, 2018
KingJoffrey
May 17, 2018
KingJoffrey
May 17, 2018
Neia Neutuladh
May 17, 2018
KingJoffrey
May 17, 2018
KingJoffrey
May 17, 2018
KingJoffrey
May 17, 2018
KingJoffrey
May 17, 2018
arturg
May 17, 2018
KingJoffrey
May 17, 2018
arturg
May 17, 2018
KingJoffrey
May 17, 2018
Neia Neutuladh
May 17, 2018
Zoadian
May 17, 2018
KingJoffrey
May 17, 2018
Uknown
May 19, 2018
0xEAB
May 20, 2018
KingJoffrey
May 21, 2018
KingJoffrey
May 17, 2018
Piotr Mitana
May 17, 2018
KingJoffrey
May 17, 2018
KingJoffrey
May 17, 2018
KingJoffrey
May 18, 2018
KingJoffrey
May 18, 2018
Dave Jones
May 18, 2018
KingJoffrey
May 18, 2018
KingJoffrey
May 18, 2018
Dave Jones
May 18, 2018
KingJoffrey
May 18, 2018
Gheorghe Gabriel
May 18, 2018
aliak
May 18, 2018
Gheorghe Gabriel
May 18, 2018
aliak
May 18, 2018
KingJoffrey
May 18, 2018
bachmeier
May 18, 2018
KingJoffrey
May 18, 2018
bachmeier
May 18, 2018
Gheorghe Gabriel
May 19, 2018
KingJoffrey
May 19, 2018
KingJoffrey
May 19, 2018
Uknown
May 19, 2018
KingJoffrey
May 19, 2018
Uknown
May 19, 2018
KingJoffrey
May 19, 2018
Neia Neutuladh
May 20, 2018
KingJoffrey
May 19, 2018
Neia Neutuladh
May 19, 2018
Gheorghe Gabriel
May 20, 2018
KingJoffrey
May 20, 2018
Dave Jones
May 21, 2018
KingJoffrey
May 21, 2018
Dave Jones
May 21, 2018
KingJoffrey
May 21, 2018
12345swordy
May 21, 2018
KingJoffrey
May 21, 2018
Dave Jones
May 22, 2018
bauss
May 22, 2018
Sir Ronald Fisher
May 19, 2018
KingJoffrey
May 21, 2018
Sjoerd Nijboer
May 21, 2018
KingJoffrey
May 21, 2018
Sjoerd Nijboer
May 21, 2018
KingJoffrey
May 21, 2018
Dave Jones
May 21, 2018
rikki cattermole
May 21, 2018
Dave Jones
May 21, 2018
KingJoffrey
May 21, 2018
Gheorghe Gabriel
May 21, 2018
12345swordy
May 22, 2018
KingJoffrey
May 18, 2018
Gheorghe Gabriel
May 19, 2018
KingJoffrey
May 18, 2018
Dave Jones
May 18, 2018
Chris M.
May 18, 2018
Dave Jones
May 18, 2018
Maurice Huuskes
May 19, 2018
KingJoffrey
May 19, 2018
KingJoffrey
May 18, 2018
Mike Parker
May 18, 2018
KingJoffrey
May 18, 2018
Mike Parker
May 18, 2018
aliak
May 18, 2018
Chris M.
May 18, 2018
KingJoffrey
May 22, 2018
VectorThis
May 22, 2018
Bjarne Stroustrup
May 22, 2018
Grady Booch
May 22, 2018
12345swordy
May 22, 2018
Dave Jones
May 17, 2018
I propose an idea, for discussion (robust discussion even better ;-)

Add an new attribute to class, named 'sealed'.

No, not sealed as in Scala.

No, not sealed as in C#

sealed as in oxford dictionary (close securely, non-porous).

when sealed is applied on the class, this means the class is sealed.

the sealed attribute only makes sense within a module, and affects nothing outside of the module.

When sealed is applied to the class, then, interfacing to a class within a module, from code outside that class - but still within the module, can now only occur via the published interface of the class.

outside code in the module, can no longer directly access your private parts!

The class is sealed.

May 17, 2018
On Thursday, 17 May 2018 at 02:32:07 UTC, KingJoffrey wrote:
> I propose an idea, for discussion (robust discussion even better ;-)  ....

oh, and it would be great, if the D 'elite' could way in to the discussion as well, as opposed to only waying in *after* a DIP is put forward.

All ideas would be helpful, including how complex it 'might' be to implement (compiler people).

Would it, or could it, break compatability - in any way..etc.etc...

May 17, 2018
Can you provide even one anecdote where this would have been useful and the workaround that has been suggested to you multiple times (putting the type in its own module) wouldn't have worked or would have caused other problems?

I mean, usually we need to do a cost/benefit analysis, and the first part of that, the one that people generally do instinctively, is try to describe the benefit. You seem to view the benefit as self-evident, but we've told you many times that it isn't self-evident to us, so you have more work to do if you want to convince anyone.

If you just want to vent, though, you might say that explicitly.
May 17, 2018
On Thursday, 17 May 2018 at 04:01:11 UTC, Neia Neutuladh wrote:
>
> If you just want to vent, though, you might say that explicitly.

This is hardly a great way to start the discussion.

When I said robust, I meant useful too.

May 17, 2018
On Thursday, 17 May 2018 at 04:01:11 UTC, Neia Neutuladh wrote:
> Can you provide even one anecdote where this would have been useful and the workaround that has been suggested to you multiple times (putting the type in its own module) wouldn't have worked or would have caused other problems?
>

My opening discussion outlines what I want, very very clearly.

The hack you mention, is not what I am asking for in my opening discussion.

Please go back and read my opening discussion properly.
May 17, 2018
On Thursday, 17 May 2018 at 04:01:11 UTC, Neia Neutuladh wrote:
> so you have more work to do if you want to convince anyone.

Again, a reminder, this is not a DIP. It's *just* a discussion.

The purpose of the discussion is not necessarly to convince anyone, of anything.

The purpose of the discussion is to gather peoples views, thoughts, ideas, concerns.....
May 17, 2018
On Thursday, 17 May 2018 at 04:01:11 UTC, Neia Neutuladh wrote:
>
> I mean, usually we need to do a cost/benefit analysis, ...

The benefit is explained in my opening discussion.

That is, i can have more than just a single class in a module file, as still be able to 'program to the interface' of the class, rather than implicitely give all other code in that module access to the private parts of my class.

Programming to the interface, is clear design philosophy of mine. Which is why I actually like the C++ friend attribute - because that is an explicit part of the defined interface.

An additional benefit is, that a class not marked as sealed (in a module), is a warning sign that anything else in the module (but outside of the class), may ignore the your class interface (i.e. can access it's private parts). So it could be helpful attribute for the way in which you approach analysing the code within the module.

For me, personally, I see this as a benefit. I do not see any downside (from a user perspective).

It does not change the benefit others get from having the status quo - which would remain unaffected - and while the status quo does indeed have benefits (as I've discovered in the other thread), it also has retains the downside of other local code in the module being able to bypass a declared interface.

If people want to propose putting each class in it's own module, that does not address my requirements, and therefore is not helpful to this discussion.

May 17, 2018
On Thursday, 17 May 2018 at 05:06:54 UTC, KingJoffrey wrote:
>
> If people want to propose putting each class in it's own module, that does not address my requirements, and therefore is not helpful to this discussion.

you could declare the public api of your class inside an actual interface then use it instead of the class, that wont give you access to the private members of the class.
May 17, 2018
On Thursday, 17 May 2018 at 06:03:19 UTC, arturg wrote:
>
> you could declare the public api of your class inside an actual interface then use it instead of the class, that wont give you access to the private members of the class.

you mean like this?

--------------------
module test;

interface Animal { string makeNoise(); }

class Dog : Animal
{
    private string noiseType = "woof";

    override string makeNoise()
    {
        return this.noiseType;
    }
}

void main()
{
    import std.stdio;

    auto dog = new Dog;
    dog.noiseType = "meow"; // grr!
    writeln(dog.makeNoise()); // wtf! Thanks to D, my dog can now meow!
}

--------------------
May 17, 2018
On Thursday, 17 May 2018 at 07:30:58 UTC, KingJoffrey wrote:
> On Thursday, 17 May 2018 at 06:03:19 UTC, arturg wrote:
>>
>> you could declare the public api of your class inside an actual interface then use it instead of the class, that wont give you access to the private members of the class.
>
> you mean like this?
>
> --------------------
> module test;
>
> interface Animal { string makeNoise(); }
>
> class Dog : Animal
> {
>     private string noiseType = "woof";
>
>     override string makeNoise()
>     {
>         return this.noiseType;
>     }
> }
>
> void main()
> {
>     import std.stdio;
>
>     auto dog = new Dog;
>     dog.noiseType = "meow"; // grr!
>     writeln(dog.makeNoise()); // wtf! Thanks to D, my dog can now meow!
> }
>
> --------------------

no, that uses type inferance.
you have to do
Animal dog = new Dog;
« First   ‹ Prev
1 2 3 4 5 6 7 8 9 10