Wiki improvements

Forum for discussion about the documentation project.
Post Reply
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Wiki improvements

Post by fxm »

MrSwiss wrote:There is another (small, typo) somewhere in floating text, where you write "types" but clearly refer to: instance(s) of the type.
I tried to do a little housekeeping among all these "types (s)".
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Wiki improvements

Post by fxm »

MrSwiss wrote:Question: why use 'Dim As' (in type) as opposed to: 'As' (without Dim)?
This is one of my old manias.
I like to explicit the declarations, even for the type data fields:
Dim As ...
similarly to:
Static As ...
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Wiki improvements

Post by fxm »

I corrected an error in the explanation on 'Singleton':
Only the copy constructor may have no implementation.
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Wiki improvements

Post by fxm »

MrSwiss wrote:While (in some cases) the need to Declare, is clearly explained, there isn't anything related to Implementation (do I have to, or not?).
(this is especially true, when it concerns EMPTY (without body) constructors/operators, since all others 'have to be written' anyhow.)
Because for me, the answer is obvious and more general:
A procedure (declared for any reason) may have no implementation (no body defining) if it is never actually called in the program.

I added such a sentence in the article (in paragraph 6).
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Wiki improvements

Post by MrSwiss »

fxm wrote:Because for me, the answer is obvious and more general:
A procedure (declared for any reason) may have no implementation (no body defining) if it is never actually called in the program.
This isn't what I mean by Implementation: "do I have to write out such 'empty body' thingy?
That's the real question.
To me, its only clear on procedures, not necessarily on constructors, e.g.:

Code: Select all

Type something extends Object ' there will be a derived type
  Private:
    Declare Constructor() ' derived types use, only (in order to replace default, implict Constructor)
  Public:
    Declare Constructor(overloaded) ' default for user (destroys default, implict Constructor)
    ...
End Type

Constructor something()
End Constuctor ' doesn't make much sense, to me ...
'
Constructor something(overloaded) ' must be implemented
    ' instead of action code
End Constructor
Last edited by MrSwiss on Jun 12, 2018 20:32, edited 1 time in total.
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Wiki improvements

Post by fxm »

I do not understand the meaning of your code.
What is the "overloaded" expression, a parameter declaration?
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Wiki improvements

Post by MrSwiss »

fxm wrote:What is the "overloaded" expression, a parameter declaration?
Just a 'proxy' or 'dummy' for any variables etc.

What I gathered from your article:
  • 1) if a overloaded Constructor exists, then implicit, default Constructor is destroyed!
    2) since a derived type always calls: Base() Constructor first, we have to have one (but not user callable, thus Private:)
Therefore we *must* (do we?) Declare/Implement (our own, freshly aka: again)
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Wiki improvements

Post by fxm »

In your code, change "Private" to "Protected", otherwise one cannot access this constructor from a derived type.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Wiki improvements

Post by MrSwiss »

Should have known that, because I've checked the manual on those, yesterday.

However, apart from mentioning "inheritance" on Protected, there isn't much on:
details on them, or a direct comparison (except as stated above).

What you are saying is: Private: Type.Member isn't "inheritable", yes?
Does that cover any Member? Variables/Procedures/Operators etc. ?
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Wiki improvements

Post by fxm »

Yes and yes.
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Wiki improvements

Post by fxm »

Code: Select all

Type UDT
  Dim As Integer I
End Type

Dim As UDT u  '' this code calls the default constructor,
'             '' the implicit default constructor built by the compiler in this case

Code: Select all

Type UDT
  Dim As Integer I
  Declare Constructor (Byval I0 As Integer)
End Type

Dim As UDT u  '' this code calls the default constructor,
'             '' but as an explicit constructor exists,
'             '' there is no longer an implicit default consructor built by the compiler,
'             '' so no default constructor at all,
'             '' that induces a compile error
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Wiki improvements

Post by MrSwiss »

Well, that truely clears yet another one, of those mysteries ... thanks.

A Note on doc, related to Private: should imho state:
Everything with "private" access, cannot be inherited, as opposed to "protected" access rights.
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Wiki improvements

Post by dodicat »

A quick quirk with private constructors.

Code: Select all


Type UDT 
  Dim As Integer I=23
  private:
  Declare Constructor ()
End Type

constructor UDT ()
print "Hi"
end constructor


redim as udt temp(0)

dim as udt u=temp(0)

print u.i

'Dim As UDT u2   ''' NO

sleep

 
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Wiki improvements

Post by fxm »

KeyPgVisPrivate → fxm [Highlight that private members are not accessible from inside derived types]
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Wiki improvements

Post by fxm »

@dodicat,

For me a bug.
'Redim' with sizing does not seem to check the right of access to the constructor.
Post Reply