Re: Me vs. MyClass

Tech-Archive recommends: Speed Up your PC by fixing your registry



On 2005-09-05, Jay B. Harlow [MVP - Outlook] <Jay_Harlow_MVP@xxxxxxxxxxxxx> wrote:
> dfoster,
>| Mkay... I find that practice awfully goofy and confusing, but to each
>| his own.
> How so? Or did you not follow the "simplicity" of my statement? :-|

No, I followed your statement completely and I understand why you prefer
this syntax. And like I said, to each his own, it's not a syntax that
bothers me significantly. But if you really want to know why I find it
goofy...

1. It implies that a special syntax is necessary to reference ctors,
whereas virtually every other OOP language I know uses the standard
instance pointer if they allow chaining overloaded ctors.

2. It uses a very rare keyword to perform an ordinary task.

3. It requires explaning a simple and common topic, chaining
constructors, in terms of a fairly complex and very rare topic,
bypassing polymorphic behavior.

4. Because you've used a unique syntax, it appears to a casual reader
that VB.Net ctors do not behave as an OOP-experienced developer would
expect them to behave.

5. Because this is the only place a developer is likely to encounter
MyClass, it implies that this is the ordinary behavior of MyClass, when
in fact it is not (as we see below).


> What I stated can be demonstrated by:
>
> Sub New()
> MyClass.New(...) ' calls a method in this specific class
> End Sub
>
> Sub Other()
> MyClass.Other(...) ' calls a method in this specific class
> End Sub
>
> Where as:
>
> Sub New()
> Me.New(...) ' calls a method in this specific class
> Me.Other(...) ' calls a possibly overridden method
> End Sub
>
> Sub Other()
> Me.Other(...) ' calls a possibly overridden method
> End Sub
>
> I hope you see in the above that using Me, I need to remember an exception
> to a rule, that is that Me.New calls a method in this specific class. Using
> MyClass I don't need to remember an exception to a rule.

Actually, you still need to remember an exception to a rule.

Sub New()
MyClass.New(5) ' will work only if THIS class defines the method
MyClass.Other(5) ' is fine if a base class defines the method
End Sub

ctors are special. 'Me' works differently with them, and 'MyClass'
works differently with them. They have all kinds of special behavior,
like the automatic calling of the base class, and no syntactical sugar
is going to cover that up.


> I can see more potential for confusion with using Me, then when using
> MyClass! Especially for beginner's.

Well, there's two kinds of beginners. For experienced developers
moving to VB.Net the 'Me' syntax works just like it does in other OOP
languages, so that's simple and doesn't really require an explanation.
For new developers, you can either go into all the weirdness of what
MyClass does, and then explain that calling MyClass.New works kinda like
MyClass.OtherMethod, but not quite. Or you can simply explain the ctors
are special in a number of ways and show how.

The ctor information is useful and important in a number of ways, and
you're going to have to cover it anyway. The MyClass information pretty
much has no usefulness in practice.

BTW, I'm tempted to say that it's Me.New(...) that acts normally here,
since it will only call a derived member if that member is declared
Overridable and Sub New can never be declared Overridable. So there's
really no exception to remember. But that would be as wrong as your
description above trying to claim that MyClass works normally in this
case. The fact is that both exhibit nonstandard behavior.

> Of course if you simply ban the use of MyClass, then yes my convention may
> seem "goofy & confusing".

Despite the length of the post above (hey, you asked for my reasons),
"goofy" is a pretty weak epithet to me. There are a lot of programming
practices I feel strongly about, but this isn't one of them. And the
docs seem ambivalent on the subject, sometimes using MyClass.New and
sometimes using Me.New, so developers have to pick up both syntaxes
(syntaxi?) at some point.


>| So we're still left with the
>| original question as to why this was seen as a needed keyword.
> As you are aware, it allows you to defeat polymorphism & explicitly call a
> method of the specific class, rather then the (potentially) overriding
> method of a derived class.
>
> I think the real question we're after is: when would we really need to do
> this.

Kind of, but I'm also wondering if this feature is there because the dev
team thought it would be useful to developers, or if they really needed
the feature for something internal (is anything internal actually
written in VB.Net, I have no idea) or for some VB6 conversion issue.

I googled this earlier cuz I was curious, and I came across a couple of
old links that implied that in very early betas all methods were virtual
in VB.Net. That would explain the strange behavior of the compiler
which seems to assume this, and also the need of the MyClass keyword.
But I'm just guessing at that...


.



Relevant Pages

  • Re: Me vs. MyClass
    ... > If I find additional info on a viable reason to call MyClass outside of ... And like I said, to each his own, it's not a syntax that ... It implies that a special syntax is necessary to reference ctors, ... >|> Sub New ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Me vs. MyClass
    ... If I find additional info on a viable reason to call MyClass outside of ... And like I said, to each his own, it's not a syntax that ... |> Sub New ... For experienced developers ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Inserting rows syntax + row #ing code in protected sheet?
    ... mentioned WP above because I'm going to reference a handy piece of syntax I ... is there is an extra command to handle "cancel" in VB? ... > Dim i As Long ... > Exit Sub ...
    (microsoft.public.excel.programming)
  • Re: Me vs. MyClass
    ... I meant an example where a call used MyClass functionality rather ... > Public Sub New ... > Public Sub New ... >| That last displays "Derived Class string" ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Copying text from an editable text box to a table cell
    ... Also tried all variants of the syntax I could think of. ... Sub DuplicateTable() ... Dim oSource_table As Table ... This is applied to a button on slide 3 which when pressed, ...
    (microsoft.public.powerpoint)