Welcome to Phrogram Sign in | Join | Help
in Search


Bug #39: Nested Sturctures not copied properly

Last post 09-05-2008, 1:23 PM by The Dragon Rider. 19 replies.
Page 2 of 2 (20 items)   < Previous 1 2
Sort Posts: Previous Next
  •  08-15-2008, 5:04 PM 7072 in reply to 7066

    Re: Structures Reference

    I had no idea of this history. At least there is a good reason for all the hassle.

    Just to be 100% confident let me make sure about something. Objects are reference types. But the properties (aka fields) of an object like its strings and integers and structures are still value types. I would guess this is analogous to arrays, which are reference types, while the elements of an array are value types.

    Here is a more interesting question: does Phrogram support passing messages between objects? I think those are the term I am looking for though in this case it would be more like retrieving messages. Specifically is it possible to retrieve the properties of an instance of an object defined in one class from within the methods in another class? or i guess even the same class. Currently when I want to accomplish this I send the properties of the first object as parameters to the methods or functions of the second class. And this is working well for my designs. But I am sure I will come across cases where the more direct "message passing" option would be useful.

  •  08-15-2008, 5:39 PM 7073 in reply to 7072

    Re: Structures Reference

    Not all properties are value types...

    struct foo
    {
        int i;
        string s;
        object o;
    }

    foo is a value type

    foo.i is a value type

    foo.s is a reference type (becuase string is an object)

    foo.o is a reference type

    The rule also doesn't apply to arrays, while the array itself is a reference type you can have arryas of value types int[] and reference types object[]

     

    I'm not 100% what you mean by message passing - feel free to give me an example in a different language or a scenario that you can think of. In general the purpose fo putting things into classses is to encapusalte the things that each class neds and then you procive access through the classes external interface only. Diving into the structures of another class would violate that encapsualtion.

    The message passing between classes is generally done using method calls (see http://en.wikipedia.org/wiki/Object-oriented_programming#Fundamental_concepts)  which are supported in Phrogram. Though in this case Message Passing is about classes communicating rather than directly exposing their innards directly.

     


    Managed DirectX and XNA ? Check out http://www.thezbuffer.com
  •  08-17-2008, 7:45 AM 7075 in reply to 7073

    Re: Structures Reference

    //How is this for a better example? I finally see the need for reference types!

    Program ClassFromClass

     Class creature
      Private Define _Spooked As Boolean
      
      Property Spooked As Boolean
       Get
        Return _Spooked
       End Get
       Set(value As Boolean)
        _Spooked = value
       End Set
      End Property
     End Class
     
     Class explorer
      Method photograph(NearbyWombat As creature,Brush As String,Direction As String)
       If Brush = "dry leaves" Or Direction="downwind" Then
        NearbyWombat.Spooked=True
       End If
      End Method
     End Class
     
     Method Main()
      Define Bill As explorer
      Define Wombat As creature
      
      Wombat.Spooked=False
      Bill.photograph(Wombat,"dry leaves","upwind")//(Wombat,"clay","upwind")//
      consolewriteline(converttostring(Wombat.Spooked))
     End Method

    End Program

    //results
    //"true" for uncommented-out code
    //"false" for commented-out code
    //theory
    //Wombat is passed as a parameter called NearbyWombat. This is how Bill inspects Wombat.
    //NearbyWombat is a reference type. This is how Bill affects Wombat.

    Filed under:
  •  09-04-2008, 2:49 PM 7117 in reply to 7075

    Re: Structures Reference

    Yes wombat is indeed a reference. If it was a value type you would be passing in a copy of the wombat, not the original and changes would not affect it.
    Managed DirectX and XNA ? Check out http://www.thezbuffer.com
  •  09-05-2008, 1:23 PM 7118 in reply to 7117

    Re: Structures Reference

    I'm not sure what's you're going through all this trouble to do here..

    Why don't you just make _Spooked public and reference it directly( Wombat._Spooked = true )? 

Page 2 of 2 (20 items)   < Previous 1 2
View as RSS news feed in XML