Question of JAVA programmer to C# programmers

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jon Skeet [C# MVP]

    #16
    Re: Question of JAVA programmer to C# programmers

    Bjorn Abelli <bjorn_abelli@D oNotSpam.hotmai l.com> wrote:

    <snip stuff we agree about>
    [color=blue]
    > It is whether the value of the variable is the actual value, or a reference
    > to the value, that decides if it's a "value type" or a "reference type". Not
    > necessarily the type itself.[/color]

    I disagree. If you're talking about boxing etc, then there are actually
    two types for each value type: there's the value type itself and the
    reference type. An object has a type regardless of whether it's in a
    variable somewhere or not.
    [color=blue]
    > That it coincides in .NET with structs vs classes as well as in Java with
    > primitive types vs classes is something else, made for convenience.
    >
    > If we lift the concepts above the actual languages and platforms it could be
    > something else. For example, if you define a class or a struct in C++, they
    > are by themselves neither value nor reference types.[/color]

    If it's a .NET type then it is deinitely one or the other though. I
    believe this is one of those topics where it doesn't make sense to talk
    details without reference to the particular platform involved.

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    • Bjorn Abelli

      #17
      Re: Question of JAVA programmer to C# programmers

      "Jon Skeet [C# MVP]" wrote...[color=blue]
      > Bjorn Abelli wrote:[/color]
      [color=blue][color=green]
      > > It is whether the value of the variable is the actual
      > > value, or a reference to the value, that decides if
      > > it's a "value type" or a "reference type". Not
      > > necessarily the type itself.[/color]
      >
      > I disagree. If you're talking about boxing etc, then
      > there are actually two types for each value type: there's
      > the value type itself and the reference type.
      > An object has a type regardless of whether it's in a
      > variable somewhere or not.[/color]

      Yes, I agree to the latter, but *conceptually* it's better to not refer to
      this as being a "value" or "reference" type.

      I actually didn't think of boxing per se, but that rather confirms my
      definitions, as the type of the instance is one thing, the type of the
      variable is another, where the type of the variable can be a "value" or
      "reference" type, regardless of which type the actual instance is.
      [color=blue]
      > If it's a .NET type then it is definitely one or the other
      > though. I believe this is one of those topics where it
      > doesn't make sense to talk details without reference
      > to the particular platform involved.[/color]

      I think you're only partially right here... :-)

      My point was taken with consideration for the OP where he actually wanted to
      know the *difference* between two platforms.

      When we *compare* the behavior between different languages/platforms I think
      it's necessary to lift the concepts to their common definitions *above* the
      platforms first, to make it possible to *then* go down to the differences in
      how they are implemented and used in each platform.

      // Bjorn A





      Comment

      • Jon Skeet [C# MVP]

        #18
        Re: Question of JAVA programmer to C# programmers

        Bjorn Abelli <bjorn_abelli@D oNotSpam.hotmai l.com> wrote:[color=blue][color=green][color=darkred]
        > > > It is whether the value of the variable is the actual
        > > > value, or a reference to the value, that decides if
        > > > it's a "value type" or a "reference type". Not
        > > > necessarily the type itself.[/color]
        > >
        > > I disagree. If you're talking about boxing etc, then
        > > there are actually two types for each value type: there's
        > > the value type itself and the reference type.
        > > An object has a type regardless of whether it's in a
        > > variable somewhere or not.[/color]
        >
        > Yes, I agree to the latter, but *conceptually* it's better to not refer to
        > this as being a "value" or "reference" type.[/color]

        I still disagree, I'm afraid - tying types to variables leaves awkward
        conceptual holes for things like intermediate expressions, eg
        o.GetType().ToS tring() where there may be no variables involved for the
        middle part (which is definitely still of type Type, as far as the
        expression is concerned).
        [color=blue]
        > I actually didn't think of boxing per se, but that rather confirms my
        > definitions, as the type of the instance is one thing, the type of the
        > variable is another, where the type of the variable can be a "value" or
        > "reference" type, regardless of which type the actual instance is.[/color]

        Certainly variables *do* have a type, but your original post implied
        (to me, anyway) that you *had* to be considering a variable in order to
        talk about type. A variable's value can have a different type to the
        variable, of course:

        object o = "string";

        The type of o is object; the type of its value is (reference to)
        string.
        [color=blue][color=green]
        > > If it's a .NET type then it is definitely one or the other
        > > though. I believe this is one of those topics where it
        > > doesn't make sense to talk details without reference
        > > to the particular platform involved.[/color]
        >
        > I think you're only partially right here... :-)
        >
        > My point was taken with consideration for the OP where he actually wanted to
        > know the *difference* between two platforms.
        >
        > When we *compare* the behavior between different languages/platforms I think
        > it's necessary to lift the concepts to their common definitions *above* the
        > platforms first, to make it possible to *then* go down to the differences in
        > how they are implemented and used in each platform.[/color]

        Certainly there are things we can make common definitions for. For
        instance, it makes sense to define value type and reference type in a
        way which is consistent between Java and C#. The fact that in C++ a
        type isn't necessarily either doesn't make that concept useless -
        unless you're trying to talk about C++!

        --
        Jon Skeet - <skeet@pobox.co m>
        Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

        If replying to the group, please do not mail me too

        Comment

        • Bjorn Abelli

          #19
          Re: Question of JAVA programmer to C# programmers


          "Jon Skeet [C# MVP]" wrote...[color=blue]
          > Bjorn Abelli wrote:[/color]
          [color=blue][color=green]
          > > Yes, I agree to the latter, but *conceptually*
          > > it's better to not refer to this as being a
          > > "value" or "reference" type.[/color]
          >
          > I still disagree, I'm afraid - tying types to variables
          > leaves awkward conceptual holes for things like intermediate
          > expressions, eg o.GetType().ToS tring() where there may be
          > no variables involved for the middle part (which is
          > definitely still of type Type, as far as the expression
          > is concerned).[/color]

          Well, you have a point there, but it rather points out the need to differ
          between the types of the actual instances, and whether the types of
          variables or intermediate expressions are value or reference types.
          [color=blue]
          > Certainly variables *do* have a type, but your original post implied
          > (to me, anyway) that you *had* to be considering a variable in order to
          > talk about type.[/color]

          My fault! I thought it would be easier to clarify the concepts by using the
          difference of types of the actual instances vs the types of variables, but
          of course intermediate expressions also falls into the latter category.

          But I think I have made my point by now. :-)

          // Bjorn A


          Comment

          • Jon Skeet [C# MVP]

            #20
            Re: Question of JAVA programmer to C# programmers

            Bjorn Abelli <bjorn_abelli@D oNotSpam.hotmai l.com> wrote:[color=blue][color=green]
            > > I still disagree, I'm afraid - tying types to variables
            > > leaves awkward conceptual holes for things like intermediate
            > > expressions, eg o.GetType().ToS tring() where there may be
            > > no variables involved for the middle part (which is
            > > definitely still of type Type, as far as the expression
            > > is concerned).[/color]
            >
            > Well, you have a point there, but it rather points out the need to differ
            > between the types of the actual instances, and whether the types of
            > variables or intermediate expressions are value or reference types.[/color]

            Agreed.
            [color=blue][color=green]
            > > Certainly variables *do* have a type, but your original post implied
            > > (to me, anyway) that you *had* to be considering a variable in order to
            > > talk about type.[/color]
            >
            > My fault! I thought it would be easier to clarify the concepts by using the
            > difference of types of the actual instances vs the types of variables, but
            > of course intermediate expressions also falls into the latter category.
            >
            > But I think I have made my point by now. :-)[/color]

            Yes, I think we're there now. It's not been in vain, btw - I'll try to
            remember to include the difference between "declared type" (or possibly
            "compile-time type") and "actual type" when I finally get round to
            writing a simple explanation of the difference between value types and
            reference types... (It's been on my list for a while...)

            --
            Jon Skeet - <skeet@pobox.co m>
            Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

            If replying to the group, please do not mail me too

            Comment

            Working...