Object property inheritance - why does this this not work ?

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Object property inheritance - why does this this not work ?

4D Tech mailing list
Hi

Using the v17 dot notation I was unable to get one object to inherit another’s properties using the assignment operator. Also when I inspect $dog in the debugger after assigning the first property, it appears empty.

Code is:

C_OBJECT($animal;$dog;$cat)

$dog:=New object
$cat:=New object

$dog.sound:="bark"
$cat.sound:="meow"

$animal:=$dog
$getSound:=$animal.sound

Running this in the debugger, $dog and $cat return “{}”, yet hovering over $dog.sound with the cursor does display the property value. $animal.sound returns undefined.

Why does this not work ?

Regards

Peter

**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: Object property inheritance - why does this this not work ?

4D Tech mailing list
Peter,

I just tested your code exactly as-is and all the variables have the expected values. I used 17.2 on Mac. What version/platform did you test on? I've sent you a screenshot directly.

Regards,
 
Narinder Chandi,
ToolBox Systems Ltd.
 
I am available for new consulting opportunities…
http://4d.1045681.n5.nabble.com/ANN-4D-Developer-Available-td5765443.html
--

-----Original Message-----
From: 4D_Tech <[hidden email]> on behalf of 4D Tech Mailing List <[hidden email]>
Reply-To: 4D Tech Mailing List <[hidden email]>
Date: Sunday, 15 September 2019 at 11:12
To: 4D Tech Mailing List <[hidden email]>
Cc: Peter Jakobsson <[hidden email]>
Subject: Object property inheritance - why does this this not work ?

    Hi
   
    Using the v17 dot notation I was unable to get one object to inherit another’s properties using the assignment operator. Also when I inspect $dog in the debugger after assigning the first property, it appears empty.
   
    Code is:
   
    C_OBJECT($animal;$dog;$cat)
   
    $dog:=New object
    $cat:=New object
   
    $dog.sound:="bark"
    $cat.sound:="meow"
   
    $animal:=$dog
    $getSound:=$animal.sound
   
    Running this in the debugger, $dog and $cat return “{}”, yet hovering over $dog.sound with the cursor does display the property value. $animal.sound returns undefined.
   
    Why does this not work ?
   
    Regards
   
    Peter
   
    **********************************************************************
    4D Internet Users Group (4D iNUG)
    Archive:  http://lists.4d.com/archives.html
    Options: https://lists.4d.com/mailman/options/4d_tech
    Unsub:  mailto:[hidden email]
    **********************************************************************


**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: Object property inheritance - why does this this not work ?

4D Tech mailing list
Hi Narinder

So it does. I created a brand new structure and it now works.

I did that example in a legacy upgraded structure so maybe there’s some compatibility setting that I needed to change to fully support the new object syntax.

Many thanks for taking the time to check it and respond !

Peter

> On 15 Sep 2019, at 12:41, Narinder Chandi via 4D_Tech <[hidden email]> wrote:
>
> I just tested your code exactly as-is and all the variables have the expected values. I used 17.2 on Mac

**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: Object property inheritance - why does this this not work ?

4D Tech mailing list
Peter,

Yes, for legacy structures that are converted to v17 you have to explicitly enable Unicode support and also enable the "Use object notation..." setting under Compatibility. This is assuming that your structure has a clean bill of health in the MSC in regards to not using the period ( . ) or square bracket ( [ ] ) characters in any 4D variables, tables names, etc.

Regards,
 
Narinder Chandi,
ToolBox Systems Ltd.
 
I am available for new consulting opportunities…
http://4d.1045681.n5.nabble.com/ANN-4D-Developer-Available-td5765443.html
--

-----Original Message-----
From: 4D_Tech <[hidden email]> on behalf of 4D Tech Mailing List <[hidden email]>
Reply-To: 4D Tech Mailing List <[hidden email]>
Date: Sunday, 15 September 2019 at 11:46
To: 4D Tech Mailing List <[hidden email]>
Cc: Peter Jakobsson <[hidden email]>
Subject: Re: Object property inheritance - why does this this not work ?

    Hi Narinder
   
    So it does. I created a brand new structure and it now works.
   
    I did that example in a legacy upgraded structure so maybe there’s some compatibility setting that I needed to change to fully support the new object syntax.
   
    Many thanks for taking the time to check it and respond !
   
    Peter
   
    > On 15 Sep 2019, at 12:41, Narinder Chandi via 4D_Tech <[hidden email]> wrote:
    >
    > I just tested your code exactly as-is and all the variables have the expected values. I used 17.2 on Mac
   
    **********************************************************************
    4D Internet Users Group (4D iNUG)
    Archive:  http://lists.4d.com/archives.html
    Options: https://lists.4d.com/mailman/options/4d_tech
    Unsub:  mailto:[hidden email]
    **********************************************************************


**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: Object property inheritance - why does this this not work ?

4D Tech mailing list
Thanks Narinder.

Doesn’t this imply we need to change our entire style and approach to coding ? Language data structures, forms, the lot ?

Have you found you needed to do this ? (At least in terms of new code and optimal approaches).

Having attended the last couple of summits and various classes etc I’ve been aware of this looming in the background but the dot notation really is the breakthrough for me that warrants taking the leap across the “discontinuity gap” from old to new. It reminds me of working in Visual Basic years ago which used all this object oriented approach. 4D even lets you create a kind of “active object” now with “New Formula”.

Doesn’t this mean a complete revision of how we code form the ground up ? Finding new “best practice” approaches to absolutely everything ? (As we even have “collections” now so even the most fundamental aspect of 4D - current selections - is out of the window).

I might need to take a month off and read the whole manual again for the first time since 1988 !

Peter

> On 15 Sep 2019, at 12:52, Narinder Chandi via 4D_Tech <[hidden email] <mailto:[hidden email]>> wrote:
>
> Yes, for legacy structures that are converted to v17 you have to explicitly enable Unicode support and also enable the "Use object notation..." setting under Compatibility
**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: Object property inheritance - why does this this not work ?

4D Tech mailing list
I think our coding style will need to undergo an evolution rather than revolution. We all probably have legacy codebases to maintain where the existing code will mostly stay as-is, but newer code can be written using the new features. Over time developers will no doubt "modernise" existing code too, but that is usually driven by time and cost implications.

The new language features will certainly enhance our ability to write cleaner, leaner code and can happily co-exist with existing 4D code. I am only just starting to explore the new features in a couple of personal projects where I have the luxury of starting with clean structures. For any developer that may have used Object Tools or the native OB commands in 4D or other OOP-like languages (I have coded a lot of PHP in various frameworks) embracing the new features should be a breeze.

ORDA looks really interesting too but I haven't played with it yet, but I'm looking forward to experimenting with it soon. I also need to play with the new Form command. New formula (that you mentioned) has arrived with 17 R3. So, lots of new toys for sure!

File management with Path to object and Object to path are really great commands to finally have. For me it's immediately simplified the amount of code I often had to write to access the file system now that you can work with an object.

Of course, what we still need is the ability to create OOP-like Classes in 4D with the associated capabilities like member variables and methods, object instantiation (may be even class reflection), etc. Perhaps with v18 or v19. Oh yes, and really we do need a much improved Method Editor :P

Regards,
 
Narinder Chandi,
ToolBox Systems Ltd.
 
I am available for new consulting opportunities…
http://4d.1045681.n5.nabble.com/ANN-4D-Developer-Available-td5765443.html
--

-----Original Message-----
From: 4D_Tech <[hidden email]> on behalf of 4D Tech Mailing List <[hidden email]>
Reply-To: 4D Tech Mailing List <[hidden email]>
Date: Sunday, 15 September 2019 at 12:08
To: 4D Tech Mailing List <[hidden email]>
Cc: Peter Jakobsson <[hidden email]>
Subject: Re: Object property inheritance - why does this this not work ?

    Thanks Narinder.
   
    Doesn’t this imply we need to change our entire style and approach to coding ? Language data structures, forms, the lot ?
   
    Have you found you needed to do this ? (At least in terms of new code and optimal approaches).
   
    Having attended the last couple of summits and various classes etc I’ve been aware of this looming in the background but the dot notation really is the breakthrough for me that warrants taking the leap across the “discontinuity gap” from old to new. It reminds me of working in Visual Basic years ago which used all this object oriented approach. 4D even lets you create a kind of “active object” now with “New Formula”.
   
    Doesn’t this mean a complete revision of how we code form the ground up ? Finding new “best practice” approaches to absolutely everything ? (As we even have “collections” now so even the most fundamental aspect of 4D - current selections - is out of the window).
   
    I might need to take a month off and read the whole manual again for the first time since 1988 !
   
    Peter
   
    > On 15 Sep 2019, at 12:52, Narinder Chandi via 4D_Tech <[hidden email] <mailto:[hidden email]>> wrote:
    >
    > Yes, for legacy structures that are converted to v17 you have to explicitly enable Unicode support and also enable the "Use object notation..." setting under Compatibility
    **********************************************************************
    4D Internet Users Group (4D iNUG)
    Archive:  http://lists.4d.com/archives.html
    Options: https://lists.4d.com/mailman/options/4d_tech
    Unsub:  mailto:[hidden email]
    **********************************************************************


**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: Object property inheritance - why does this this not work ?

4D Tech mailing list
Hi Narinder

Thanks for posting your commentary. Very interesting.

Regards

Peter

> On 15 Sep 2019, at 13:58, Narinder Chandi via 4D_Tech <[hidden email]> wrote:
>
> I think our coding style will need to undergo an evolution rather than revolution

**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: Object property inheritance - why does this this not work ?

4D Tech mailing list
In reply to this post by 4D Tech mailing list
I think you should stop thinking about dot notation as object orientation. Concepts like classes and inheritance aren't supported yet, and saying $animal:=$dog isn't inheritance -- it's just assigning one object's reference to another and kind of backwards at that.

Don't try to fit a square peg into a round hole just yet. 4D has said these things are coming.

4D had a weird example in their blog, though... you could make a method called "New Animal" (yes, with a space... cheap trick), that creates an object and sets some properties for all animals. Then you could write

$dog:=New Animal

... and then start customizing the properties of dog based on the not-really-a-superclass Animal.

I think this is a waste of time knowing that a proper implementation is coming someday... and having a space in the method name is bad enough, but there's no proper support for this in the language, debugger, or compiler yet, and you'll probably end up rewriting it all someday relatively soon anyway.

> On Sep 15, 2019, at 6:12 AM, Peter Jakobsson via 4D_Tech <[hidden email]> wrote:
>
> Using the v17 dot notation I was unable to get one object to inherit another’s properties using the assignment operator. Also when I inspect $dog in the debugger after assigning the first property, it appears empty.

**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: Object property inheritance - why does this this not work ?

4D Tech mailing list

> On 15 Sep 2019, at 14:32, Jeffrey Kain via 4D_Tech <[hidden email]> wrote:
>
> Don't try to fit a square peg into a round hole just yet

Fair enough, Jeff. I won’t, and your advice is of course wise re. “the real thing is coming”.

But it’s still interesting to explore the potential evolution in approach. For example even though a pure object oriented approach isn’t possible, an object based one is since we can create stateful data structures that at least mimic the behaviour of real class based ones and are therefore easier to manage in terms of documenting and auditing their behaviour.

Peter

**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************