Bug 7726 – 'virtual' keyword please

Status
RESOLVED
Resolution
DUPLICATE
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-03-18T05:59:00Z
Last change time
2014-02-12T12:58:06Z
Assigned to
nobody
Creator
turkeyman

Comments

Comment #0 by turkeyman — 2012-03-18T05:59:22Z
Used in conjunction with 'final:' at the top of the class, gives access to explicit virtual code. Allow implementation of such a policy for a large code team.
Comment #1 by pszturmaj — 2012-03-18T13:07:32Z
Instead, please use final: at the bottom of the class.
Comment #2 by turkeyman — 2012-03-19T04:09:50Z
Then I can't use private:, since that suffers from the same problem of not having a corresponding 'public'. { [public virtual methods] private: [data members] final: [non-virtual methods] // are now private } { [public virtual methods] final: [non-virtual methods] private: [data members] // error because of the 'final:' bug } This all leads to messy, and rather difficult to follow classes. I like to keep associated stuff together. I also really like the virtual keyword, it states in the API clearly how to extend the class, and you can grep for it.
Comment #3 by pszturmaj — 2012-03-19T05:08:26Z
You can tag individual members with public/private and final. final: and final { } are just for convenience. You can also try something like this: { void virtualMethod() {} private: int privateMember; public final: void finalMethod() { } // public } I guess you are opting for virtual: keyword to just disable existing final: specifier. There are other possible solutions without adding a new keyword: - Use default: to restore public and virtual. - Use negation, like !final: to disable specifiers that differ from public and virtual. But I'm ok with current approach.
Comment #4 by turkeyman — 2012-03-19T06:25:25Z
No actually, I want a 'virtual' keyword to write in front of virtual methods. Not 'virtual:', I don't believe that would be very useful. What I want is the ability to work exactly the same way C++,C# is, and how every programmer that exists expects: class MyClass { final: this() void method(); @property void thing(int t) {} @property int thing() {} }
Comment #5 by turkeyman — 2012-03-19T06:33:04Z
*crap, I tapped tab and the 'commit' button gained focus, and when I pressed space bar, it posted.* class MyClass { final: this(); @property void property1(int t) @property int property1() @property void thing(int t) @property int thing() void doThing() void addUnrelated(Unrelated x); Unrelated getUnrelated(); virtual void updateUnrelateds(); // etc. private: virtual void update(); virtual void draw(); void handlerDelegate(); void handlerDelegate2(); int data1; float data2; ... } Ie. logically group stuff, mark the occasional virtual explicitly, continue as final. This looks like a fairly realistic class to me. I really want to be able to explicitly mark each function that is virtual in this way.
Comment #6 by pszturmaj — 2012-03-19T07:00:07Z
You can write it like this: class MyClass { final { this(); @property void property1(int t) @property int property1() @property void thing(int t) @property int thing() void doThing() void addUnrelated(Unrelated x); Unrelated getUnrelated(); } void updateUnrelateds(); // etc. private: void update(); void draw(); final { void handlerDelegate(); void handlerDelegate2(); } int data1; float data2; ... } IMHO it makes no sense to introduce virtual keyword since virtual in D is the default...
Comment #7 by turkeyman — 2012-03-19T10:02:13Z
Yeah, I'll do that in the mean time, but it's not a 'solution'. I still can't grep for virtual (important). And it's really ugly; breaks indentation policy, separates things in and out of braces. D is meant to be cleaner and tidier than C++. Certainly not messier.
Comment #8 by timon.gehr — 2012-03-21T12:45:15Z
(In reply to comment #4) > What I want is the ability to work exactly the same way C++,C# is, and how > every programmer that exists expects: > I'd be careful with strong/wrong statements of this kind. They make your argument seem feeble even if it is not.
Comment #9 by andrej.mitrovich — 2014-02-12T12:58:06Z
*** This issue has been marked as a duplicate of issue 11616 ***