object vs System.Object

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gaemic

    object vs System.Object

    Some argues that you should not use the C# keyword "object" instead of the
    real type System.Object.

    What would be the general rule of thumb for choosing one over the other?

    Thanks in advanced.
    --
    Gaemic!
  • Peter Jausovec

    #2
    Re: object vs System.Object

    Hi,

    I think that keyword "object" is just an direct alias for System.Object so I
    think it's the same if you use object or System.Object.

    --
    Regards,
    Peter Jausovec
    (http://blog.jausovec.net)
    "Gaemic" <Gaemic@discuss ions.microsoft. com> je napisal v sporoèilo
    news:AAFD2A22-1F71-4942-86C5-5DDDD7471AEA@mi crosoft.com ...[color=blue]
    > Some argues that you should not use the C# keyword "object" instead of the
    > real type System.Object.
    >
    > What would be the general rule of thumb for choosing one over the other?
    >
    > Thanks in advanced.
    > --
    > Gaemic![/color]


    Comment

    • Nicholas Paldino [.NET/C# MVP]

      #3
      Re: object vs System.Object

      Gaemic,

      There is no rule of thumb, it's purely personal preference. The two are
      exactly the same. "object" is an alias that the C# compiler recognizes for
      "System.Object" . "System.Obj ect" is not a "real type" compared to "object",
      they both are lexical representations of the same type.

      It truly doesn't matter what you pick (which one would think implies
      that there should be no argument about it, but people are silly like that).

      Hope this helps.

      --
      - Nicholas Paldino [.NET/C# MVP]
      - mvp@spam.guard. caspershouse.co m

      "Gaemic" <Gaemic@discuss ions.microsoft. com> wrote in message
      news:AAFD2A22-1F71-4942-86C5-5DDDD7471AEA@mi crosoft.com...[color=blue]
      > Some argues that you should not use the C# keyword "object" instead of the
      > real type System.Object.
      >
      > What would be the general rule of thumb for choosing one over the other?
      >
      > Thanks in advanced.
      > --
      > Gaemic![/color]


      Comment

      • Tom Porterfield

        #4
        Re: object vs System.Object

        On Wed, 8 Dec 2004 07:37:01 -0800, Gaemic wrote:
        [color=blue]
        > Some argues that you should not use the C# keyword "object" instead of the
        > real type System.Object.
        >
        > What would be the general rule of thumb for choosing one over the other?
        >
        > Thanks in advanced.[/color]

        C# keyword object and System.Object are the same, the first is just an
        alias for the latter. I can think of no reason to use System.Object
        instead of object. Do those who argue against the use of object also argue
        against the use of int (System.Int32), string (System.String) , byte
        (System.Byte), bool (System.Boolean ), etc.?
        --
        Tom Porterfield

        Comment

        • Jon Skeet [C# MVP]

          #5
          Re: object vs System.Object

          Nicholas Paldino [.NET/C# MVP] <mvp@spam.guard .caspershouse.c om> wrote:[color=blue]
          > There is no rule of thumb, it's purely personal preference. The two are
          > exactly the same. "object" is an alias that the C# compiler recognizes for
          > "System.Object" . "System.Obj ect" is not a "real type" compared to "object",
          > they both are lexical representations of the same type.
          >
          > It truly doesn't matter what you pick (which one would think implies
          > that there should be no argument about it, but people are silly like that).[/color]

          While it doesn't matter for object, it does matter for (say)
          Single/float - when you use it in a method name.

          While I use the C#-specific keywords everywhere when they're used *as*
          keywords, any method names should (IMO) be based on CLR names. For
          instance, I'd use ReadSingle over ReadFloat, and ReadInt64 over
          ReadLong. This makes the method names language agnostic.

          --
          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

          • Gaemic

            #6
            Re: object vs System.Object

            > Do those who argue against the use of object also argue[color=blue]
            > against the use of int (System.Int32), string (System.String) , byte
            > (System.Byte), bool (System.Boolean ), etc.?[/color]

            Yes. And what they are arguing about is that the System.xxx will never
            changed. But because the aliases (like int) actually points to System.Int32,
            nothing says in a future version that "int" could not point to (alias to)
            System.Int64 !!!

            "Tom Porterfield" wrote:
            [color=blue]
            > On Wed, 8 Dec 2004 07:37:01 -0800, Gaemic wrote:
            >[color=green]
            > > Some argues that you should not use the C# keyword "object" instead of the
            > > real type System.Object.
            > >
            > > What would be the general rule of thumb for choosing one over the other?
            > >
            > > Thanks in advanced.[/color]
            >
            > C# keyword object and System.Object are the same, the first is just an
            > alias for the latter. I can think of no reason to use System.Object
            > instead of object. Do those who argue against the use of object also argue
            > against the use of int (System.Int32), string (System.String) , byte
            > (System.Byte), bool (System.Boolean ), etc.?
            > --
            > Tom Porterfield
            >[/color]

            Comment

            • Jon Skeet [C# MVP]

              #7
              Re: object vs System.Object

              Gaemic <Gaemic@discuss ions.microsoft. com> wrote:[color=blue][color=green]
              > > Do those who argue against the use of object also argue
              > > against the use of int (System.Int32), string (System.String) , byte
              > > (System.Byte), bool (System.Boolean ), etc.?[/color]
              >
              > Yes. And what they are arguing about is that the System.xxx will never
              > changed. But because the aliases (like int) actually points to System.Int32,
              > nothing says in a future version that "int" could not point to (alias to)
              > System.Int64 !!![/color]

              Yes it does - the C# language spec does. If they're not relying on that
              to be backwardly compatible (which changing int to point to Int64
              wouldn't be) then they shouldn't be trusting the language *at all*.
              Who's to say that "null" isn't going to be replaced with "Oojimaflip "?
              Only the spec...

              --
              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

              • Tom Porterfield

                #8
                Re: object vs System.Object

                On Wed, 8 Dec 2004 10:25:02 -0800, Gaemic wrote:
                [color=blue]
                > Yes. And what they are arguing about is that the System.xxx will never
                > changed. But because the aliases (like int) actually points to System.Int32,
                > nothing says in a future version that "int" could not point to (alias to)
                > System.Int64 !!![/color]

                As Jon points out, the C# spec says it cannot be changed. Who is to say
                the System.xxx names won't ever be changed? That argument to me would be
                for using the alias. If System.Int32 were changed to System.32bitInt eger
                the int alias could be updated without having to also change its name.
                --
                Tom Porterfield

                Comment

                • Mike Schilling

                  #9
                  Re: object vs System.Object


                  "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> wrote in
                  message news:Oaqgb0T3EH A.1396@tk2msftn gp13.phx.gbl...[color=blue]
                  > Gaemic,
                  >
                  > There is no rule of thumb, it's purely personal preference. The two
                  > are exactly the same. "object" is an alias that the C# compiler
                  > recognizes for "System.Object" . "System.Obj ect" is not a "real type"
                  > compared to "object", they both are lexical representations of the same
                  > type.
                  >
                  > It truly doesn't matter what you pick (which one would think implies
                  > that there should be no argument about it, but people are silly like
                  > that).[/color]

                  The other way around. If there were a right answer, the argument would
                  eventually die down. Since it doesn't matter, the argument can go on
                  forever.


                  Comment

                  • Mike Schilling

                    #10
                    Re: object vs System.Object


                    "Tom Porterfield" <tpporter@mvps. org> wrote in message
                    news:131c6cdyko 9kr$.dlg@tpport ermvps.org...[color=blue]
                    > On Wed, 8 Dec 2004 07:37:01 -0800, Gaemic wrote:
                    >[color=green]
                    >> Some argues that you should not use the C# keyword "object" instead of
                    >> the
                    >> real type System.Object.
                    >>
                    >> What would be the general rule of thumb for choosing one over the other?
                    >>
                    >> Thanks in advanced.[/color]
                    >
                    > C# keyword object and System.Object are the same, the first is just an
                    > alias for the latter. I can think of no reason to use System.Object
                    > instead of object. Do those who argue against the use of object also
                    > argue
                    > against the use of int (System.Int32), string (System.String) , byte
                    > (System.Byte), bool (System.Boolean ), etc.?[/color]

                    I don't argue, but the convention of uppercase Object or Structure vs.
                    lowercase scalar works for me, and probably for most people coming from a
                    C++ or Java background.


                    Comment

                    • Tom Porterfield

                      #11
                      Re: object vs System.Object

                      On Thu, 9 Dec 2004 23:41:34 -0800, Mike Schilling wrote:
                      [color=blue]
                      > I don't argue, but the convention of uppercase Object or Structure vs.
                      > lowercase scalar works for me, and probably for most people coming from a
                      > C++ or Java background.[/color]

                      Hehe, I come from a C++ background. I also happen to type faster using
                      lower case letters rather than upper case. But more importantly I am not
                      coding in C++ but rather C# now.

                      So if you use Object rather than object, do you also use Int32 rather than
                      int? My point being to ask are you consistent in your usage pattern, or is
                      your usage based on baggage that you bring from some other programming
                      language?
                      --
                      Tom Porterfield

                      Comment

                      • Mike Schilling

                        #12
                        Re: object vs System.Object


                        "Tom Porterfield" <tpporter@mvps. org> wrote in message
                        news:ozsh4af7m0 cy$.dlg@tpporte rmvps.org...[color=blue]
                        > On Thu, 9 Dec 2004 23:41:34 -0800, Mike Schilling wrote:
                        >[color=green]
                        >> I don't argue, but the convention of uppercase Object or Structure vs.
                        >> lowercase scalar works for me, and probably for most people coming from a
                        >> C++ or Java background.[/color]
                        >
                        > Hehe, I come from a C++ background. I also happen to type faster using
                        > lower case letters rather than upper case. But more importantly I am not
                        > coding in C++ but rather C# now.
                        >
                        > So if you use Object rather than object, do you also use Int32 rather than
                        > int?[/color]
                        No. As I said, lowercase scalars seem intuitive to me, and, auto-boxing and
                        "unified type system" notwithstanding , there is a difference between scalars
                        and structured types.
                        [color=blue]
                        >My point being to ask are you consistent in your usage pattern, or is
                        > your usage based on baggage that you bring from some other programming
                        > language?[/color]

                        I'm bringing baggage from 25 years of software development. How do you
                        avoid that? Why would you want to?




                        Comment

                        • Daniel O'Connell [C# MVP]

                          #13
                          Re: object vs System.Object

                          >[color=blue]
                          > I'm bringing baggage from 25 years of software development. How do you
                          > avoid that? Why would you want to?
                          >[/color]

                          Because some of that baggage will hamper you. Or, if not you, cause trouble
                          with other people...and if your baggage is causing everyone else problems,
                          to my mind that is a problem on your part.

                          Some baggage is a good thing, but not all of it is.


                          Comment

                          • Mike Schilling

                            #14
                            Re: object vs System.Object


                            "Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
                            message news:OZ$2qy03EH A.2540@TK2MSFTN GP09.phx.gbl...[color=blue][color=green]
                            > >
                            >> I'm bringing baggage from 25 years of software development. How do you
                            >> avoid that? Why would you want to?
                            >>[/color]
                            >
                            > Because some of that baggage will hamper you. Or, if not you, cause
                            > trouble with other people...and if your baggage is causing everyone else
                            > problems, to my mind that is a problem on your part.
                            >
                            > Some baggage is a good thing, but not all of it is.[/color]

                            True, but some of it is vital.

                            In this case, "Object" vs "object" is a silly thing, and the reasons for the
                            choice hardly matter. Likewise

                            i++;

                            vs.

                            ++i;

                            is of no real importance, and if you find the former more comfortable
                            because you used to write PDP-11 assembly language, there's no harm done.

                            But when all those around you are saying "use structs, not objects: they're
                            faster", and decades of baggage are saying "Use value types for things with
                            value semantics and reference types for things with reference semantics.
                            Premature optimization is a sin, and incorrect semantics in the service of
                            premature optimization is a mortal sin," well, be thankful for the baggage.


                            Comment

                            • Tom Porterfield

                              #15
                              Re: object vs System.Object

                              On Sat, 11 Dec 2004 08:11:19 -0800, Mike Schilling wrote:
                              [color=blue]
                              > i++;
                              >
                              > vs.
                              >
                              > ++i;[/color]

                              True, like that there isn't much difference. But in the following, there
                              is a difference:

                              x = i++;
                              x = ++i;

                              And as far as baggage goes, there is good and bad, most good but not all.
                              --
                              Tom Porterfield

                              Comment

                              Working...