Thread overview
[Issue 7726] New: 'virtual' keyword please
Mar 18, 2012
Manu
Mar 18, 2012
Walter Bright
Mar 18, 2012
Piotr Szturmaj
Mar 19, 2012
Manu
Mar 19, 2012
Piotr Szturmaj
Mar 19, 2012
Manu
Mar 19, 2012
Manu
Mar 19, 2012
Piotr Szturmaj
Mar 19, 2012
Manu
Mar 21, 2012
timon.gehr@gmx.ch
March 18, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7726

           Summary: 'virtual' keyword please
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: critical
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: turkeyman@gmail.com


--- Comment #0 from Manu <turkeyman@gmail.com> 2012-03-18 05:59:22 PDT ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 18, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7726


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@digitalmars.com
           Severity|critical                    |enhancement


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 18, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7726


Piotr Szturmaj <pszturmaj@tlen.pl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pszturmaj@tlen.pl


--- Comment #1 from Piotr Szturmaj <pszturmaj@tlen.pl> 2012-03-18 13:07:32 PDT ---
Instead, please use final: at the bottom of the class.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 19, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7726



--- Comment #2 from Manu <turkeyman@gmail.com> 2012-03-19 04:09:50 PDT ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 19, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7726



--- Comment #3 from Piotr Szturmaj <pszturmaj@tlen.pl> 2012-03-19 05:08:26 PDT ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 19, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7726



--- Comment #4 from Manu <turkeyman@gmail.com> 2012-03-19 06:25:25 PDT ---
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() {}


}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 19, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7726



--- Comment #5 from Manu <turkeyman@gmail.com> 2012-03-19 06:33:04 PDT ---
*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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 19, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7726



--- Comment #6 from Piotr Szturmaj <pszturmaj@tlen.pl> 2012-03-19 07:00:07 PDT ---
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...

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 19, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7726



--- Comment #7 from Manu <turkeyman@gmail.com> 2012-03-19 10:02:13 PDT ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 21, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7726


timon.gehr@gmx.ch changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |timon.gehr@gmx.ch


--- Comment #8 from timon.gehr@gmx.ch 2012-03-21 12:45:15 PDT ---
(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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------