It is currently Sat Nov 28, 2020 6:35 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 19 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: [Done] Remove the confusion with "Extends"
PostPosted: Fri Sep 18, 2020 12:56 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Jun 25, 2014 5:25 pm
Posts: 429
Location: Germany
Code:
Structure Main
  var1.i
EndStructure

Structure Sub Extends Main
  var2.i
EndStructure
If you read these structures, you would normally assume that the structure "Main" is extended by the structure "Sub".

In the code:
Quote:
Structure Sub Extends Main

As it really is:
Quote:
Structure Main Extends Sub

I have not looked at how it is with other programming languages. Anyway, it is confusing.

If at some point a PB version is released that is incompatible with the previous PB versions, it might be good to remove this confusion.

_________________
Image
Why OpenSource should have a license
PureBasic-CodeArchiv-Rebirth: Git-Repository / Download – Any help is welcome!
Manjaro Xfce x64 (Main system) :: WindowsXP/Xubuntu x86 (VirtualBox) :: PureBasic (Linux: x86/x64, Windows: x86) :: All are up to date


Last edited by Sicro on Sun Sep 20, 2020 11:41 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Remove the confusion with "Extends"
PostPosted: Fri Sep 18, 2020 1:13 pm 
Offline
Addict
Addict

Joined: Thu Apr 18, 2019 8:17 am
Posts: 1089
Sicro wrote:
If you read these structures, you would normally assume that the structure "Main" is extended by the structure "Sub".

I don't use structures, but I assume the opposite; that a new structure called "Sub" is created that is an extended version of the existing structure called "Main". Isn't that how Extends works?


Top
 Profile  
Reply with quote  
 Post subject: Re: Remove the confusion with "Extends"
PostPosted: Fri Sep 18, 2020 1:31 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Dec 23, 2009 10:14 pm
Posts: 3346
Location: Boston, MA
BarryG wrote:
I don't use structures
:shock:
I cannot believe this statement.

Anyway, EXTENDS is perfectly reasonable as is.
I use it to add some unique traits to a base structure.
I have thousands of lines of Structures.

_________________
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum


Top
 Profile  
Reply with quote  
 Post subject: Re: Remove the confusion with "Extends"
PostPosted: Fri Sep 18, 2020 3:02 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Jun 25, 2014 5:25 pm
Posts: 429
Location: Germany
BarryG wrote:
a new structure called "Sub" is created that is an extended version of the existing structure called "Main". Isn't that how Extends works?
Yes, that is how it works.

skywalk wrote:
Anyway, EXTENDS is perfectly reasonable as is.
I use it to add some unique traits to a base structure.
I have thousands of lines of Structures.
This thread is not about removing the feature "Extends", but about removing the confusion. I̶̶t̶̶ ̶̶s̶̶h̶̶o̶̶u̶̶l̶̶d̶̶ ̶̶w̶̶o̶̶r̶̶k̶̶ ̶̶l̶̶i̶̶k̶̶e̶̶ ̶̶t̶̶h̶̶i̶̶s̶̶: It looks like the keyword could work like this:
Code:
Structure Main
EndStructure

Structure Sub1 Extends Main
  var1.i
EndStructure

Structure Sub2 Extends Main
  var2.i
EndStructure

Define.Main test
test\var1 = 10
test\var2 = 20

If I read
Code:
Structure Sub Extends Main
than I understand that the structure sub extends the structure main.

If I read
Code:
Structure Sub ExtendWith Main
than I understand that the structure sub is extended with the main structure.

_________________
Image
Why OpenSource should have a license
PureBasic-CodeArchiv-Rebirth: Git-Repository / Download – Any help is welcome!
Manjaro Xfce x64 (Main system) :: WindowsXP/Xubuntu x86 (VirtualBox) :: PureBasic (Linux: x86/x64, Windows: x86) :: All are up to date


Last edited by Sicro on Sun Sep 20, 2020 8:12 pm, edited 2 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Remove the confusion with "Extends"
PostPosted: Fri Sep 18, 2020 3:07 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Feb 19, 2011 3:47 am
Posts: 2325
Location: Singapore
Sicro wrote:
I have not looked at how it is with other programming languages.
This is known as inheritance, and it is the general convention used in most object-oriented programming languages.

Basically, the child or derived object (Sub in your example), inherits all the properties of the parent or base object (Main in your example), and extends it with more properties.

_________________
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too!


Top
 Profile  
Reply with quote  
 Post subject: Re: Remove the confusion with "Extends"
PostPosted: Fri Sep 18, 2020 3:14 pm 
Offline
Addict
Addict

Joined: Thu Aug 30, 2007 11:54 pm
Posts: 1278
Location: right here
It would not make sense. If you know the definition of structure Main it would be useless or at least incomplete because it could have additions from anywhere else in the code, bad idea. Also in this case the unextened version of Main would be gone?, retroactively during compiletime? And what would Sub actually be in the end? I guess an independent structure without fields of Main? You have to think that through a bit more, it would be way more confusing. :)


Top
 Profile  
Reply with quote  
 Post subject: Re: Remove the confusion with "Extends"
PostPosted: Fri Sep 18, 2020 3:42 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Apr 05, 2020 11:28 am
Posts: 337
Location: Pandora
skywalk wrote:
BarryG wrote:
I don't use structures
:shock:
I cannot believe this statement.


Well, it always depends on what he codes and for whom.

Primarily he can code everything he wants without structures, the code is then probably better readable and understandable for him.

I myself accept this without reservation.

I think structures are very useful, but you can also use them to make codes more difficult to read.

_________________
地球上の平和


Top
 Profile  
Reply with quote  
 Post subject: Re: Remove the confusion with "Extends"
PostPosted: Fri Sep 18, 2020 3:58 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Dec 23, 2009 10:14 pm
Posts: 3346
Location: Boston, MA
Nope. Structures are so fundamental to programming, it is silly to argue.
If you pass parameters ByRef, you use Structures.
If you use drawing libs and POINT or RECT you use Structures.
If you use List() or Map() with only native types, your code is infinitely more complex to understand.

_________________
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum


Top
 Profile  
Reply with quote  
 Post subject: Re: Remove the confusion with "Extends"
PostPosted: Fri Sep 18, 2020 4:05 pm 
Offline
Addict
Addict

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3965
Location: Berlin, Germany
Sicro, you know how Extends works.
You just think that that isn't the proper keyword for this purpose, right?

Well, both of us are not native English speakers ...
Anyway, maybe the following temporary solution is better readable for you: :-)
Code:
Macro IsAnExtensionOf
   Extends
EndMacro
; -------------------------

Structure Main
   var1.i
EndStructure

Structure Sub IsAnExtensionOf Main
   var2.i
EndStructure

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
 Post subject: Re: Remove the confusion with "Extends"
PostPosted: Fri Sep 18, 2020 6:34 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2730
Location: Germany
The behaviour of the functions corresponds to the rules and behaves in the same way as with interfaces.

This is also important if you do this several times in inheritance.

If the "Extends XYZ" was not put in front of it, it would not work.
Code:
;-TOP

Structure sBase
  Name.s
EndStructure

Procedure SetName(*Data.sBase, Name.s)
  *Data\Name = Name
EndProcedure

Procedure.s GetName(*Data.sBase)
  ProcedureReturn *Data\Name
EndProcedure

; ----

Structure sAddress Extends sBase
  Street.s
  City.s
EndStructure

Procedure SetAddress(*Data.sAddress, Street.s, City.s)
  With *Data
    \Street = Street
    \City = City
  EndWith
EndProcedure

Procedure.s GetAddress(*Data.sAddress)
  Protected r1.s
 
  With *Data
    r1 = \Name + ";" + \Street + ";" + \City
  EndWith
 
  ProcedureReturn r1
EndProcedure

; ----


This means that the basic functions can be used over and over again, regardless of the subsequent structures and functions.

Example with different structures: Mini Thread control

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: Remove the confusion with "Extends"
PostPosted: Fri Sep 18, 2020 11:40 pm 
Offline
Addict
Addict

Joined: Thu Apr 18, 2019 8:17 am
Posts: 1089
skywalk wrote:
BarryG wrote:
I don't use structures
:shock:
I cannot believe this statement.

My comment was a bit wrong. What I mean is I'll have them in my code when I import other people's code for my apps, but I never actually create my own structures.


Top
 Profile  
Reply with quote  
 Post subject: Re: Remove the confusion with "Extends"
PostPosted: Sat Sep 19, 2020 11:08 am 
Offline
Addict
Addict
User avatar

Joined: Sat Feb 13, 2010 3:45 pm
Posts: 1143
Sicro wrote:
If I read
Code:
Structure Sub Extends Main
than I understand that the structure sub extends the structure main.
This is exactly how the command works. The main command is 'Structure Sub' and the secondary command 'Extends Main' specifies that this structure is extended.

Sicro wrote:
If I read
Code:
Structure Sub ExtendWith Main
than I understand that the structure sub is extended with the main structure.
This is complete nonsense, this suggests that 'Structure Sub' is extended by the structure 'Main', which would mean that 'Main' is appended to the end of 'Sub'.

_________________
sorry for my bad english


Top
 Profile  
Reply with quote  
 Post subject: Re: Remove the confusion with "Extends"
PostPosted: Sun Sep 20, 2020 11:40 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Jun 25, 2014 5:25 pm
Posts: 429
Location: Germany
Little John wrote:
Sicro, you know how Extends works.
You just think that that isn't the proper keyword for this purpose, right?
Exactly.
The keyword Extends can be understood in two ways:

  • Variant 1 (correct):
    Code:
    Structure Main
      var1.i
    EndStructure

    Structure Sub Extends Main
      ; Structure Sub extends structure Main
      var2.i
    EndStructure

    Define.Main example
    example\var1

  • Variant 2 (wrong):
    Code:
    Structure Main
      var1.i
    EndStructure

    Structure Sub Extends Main
      ; Structure Sub extends structure Main
      var2.i
    EndStructure

    Define.Main example
    example\var1
    example\var2

Little John wrote:
IsAnExtensionOf
Your keyword is good and reflects the correct function of the keyword Extends. Shorter would be: ExtensionOf

Josh wrote:
This is complete nonsense, this suggests that 'Structure Sub' is extended by the structure 'Main', which would mean that 'Main' is appended to the end of 'Sub'.
You are right, ExtendWith would be an incorrect keyword.


I sometimes use Extends in structures, but this time I just thought that this keyword can be understood ambiguously, although the second interpretation makes little sense.

Obviously nobody has problems with it. All is well. But I think it is good to have mentioned it.

_________________
Image
Why OpenSource should have a license
PureBasic-CodeArchiv-Rebirth: Git-Repository / Download – Any help is welcome!
Manjaro Xfce x64 (Main system) :: WindowsXP/Xubuntu x86 (VirtualBox) :: PureBasic (Linux: x86/x64, Windows: x86) :: All are up to date


Top
 Profile  
Reply with quote  
 Post subject: Re: [Done] Remove the confusion with "Extends"
PostPosted: Sun Sep 20, 2020 4:35 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Dec 23, 2003 3:54 am
Posts: 1863
Also, as long as PureBasic remains a "single pass compiler", this proposal would cause all sorts of dangerous edge cases.

Earlier parts of the code would think a Structure is one size, and later parts of the code would think it's another size?? See example.

I agree to leave the functionality as-is, maybe the documentation could be clarified.


Code:
; this is all hypothetical............!

Structure MyStruct
  Var1.l ; 4 byte
EndStructure

Procedure.i CreateStruct()
  ProcedureReturn AllocateMemory(SizeOf(MyStruct)) ; allocates 4 bytes of memory
EndProcedure

*A.MyStruct = CreateStruct()

; ...

Structure MyStructEx Extends MyStruct ; If this actually resized the MyStruct structure......
  Var2.l ; 4 more bytes
EndStructure

Procedure.i AnotherFunction()
  ProcedureReturn AllocateMemory(SizeOf(MyStruct)) ; this allocates 8 bytes of memory!?
EndProcedure

*B.MyStruct = AnotherFunction()
*B\Var2 = 10 ; OK...

*A\Var2 = 10 ; this would crash, since CreateStruct() only allocated 4 bytes, not 8 ???

_________________
On GitHub: PB Includes - IDE Tools - Color Themes - IDE Branches - TabBarGadget Mods


Top
 Profile  
Reply with quote  
 Post subject: Re: [Done] Remove the confusion with "Extends"
PostPosted: Sun Sep 20, 2020 8:05 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Jun 25, 2014 5:25 pm
Posts: 429
Location: Germany
@kenmo:
Thanks for the clarification. This thread was primarily about the ambiguity of the keyword Extends. I do not want to suggest any other functionality of the keyword here. Later, I mistakenly wrote that the keyword should work differently (It should work like this:). I meant it looks like the keyword could work differently.

_________________
Image
Why OpenSource should have a license
PureBasic-CodeArchiv-Rebirth: Git-Repository / Download – Any help is welcome!
Manjaro Xfce x64 (Main system) :: WindowsXP/Xubuntu x86 (VirtualBox) :: PureBasic (Linux: x86/x64, Windows: x86) :: All are up to date


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 19 posts ]  Go to page 1, 2  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye