structs ...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • news.microsoft.com

    #1

    structs ...

    Hi,

    I am using structs and am also using property accessors to access those
    private member fields... TO me this is a good way of handling them, but I
    find alot of people using direct access to the struct memebers, since
    structs is just a type similar to a class (with differences I know) why
    should I allow direct access like that... I looked at the Size and other
    parts on Control etc and I find its the same way by using property
    accessors.

    Seems to me people think struct = direct access, small, and easy.. Its just
    a type like all the rest (except with differences i Know blah blah) but why
    why why allow direct access. its just lazyness.. Code it once, and thats it,
    where is the saving? I mean if its coded well in the first place then you
    dont have to keep engineering it so its not exactly a lot of work to use
    those extra lines..

    I also find ppl balk at the concept of using parameterized constructors and
    methods in a struct, theyre just not thinking .NET , and are thinking the
    old way of structs on C. The object is still lightweight even tho there are
    methods, properties, and constructors..

    I just hate lazy coding.

    /End gripe.



  • Daniel O'Connell

    #2
    Re: structs ...


    "news.microsoft .com" <discussion@dis cussion.microso ft.com> wrote in message
    news:%23Aipc1So DHA.3732@tk2msf tngp13.phx.gbl. ..[color=blue]
    > Hi,
    >
    > I am using structs and am also using property accessors to access those
    > private member fields... TO me this is a good way of handling them, but I
    > find alot of people using direct access to the struct memebers, since
    > structs is just a type similar to a class (with differences I know) why
    > should I allow direct access like that... I looked at the Size and other
    > parts on Control etc and I find its the same way by using property
    > accessors.
    >[/color]

    It really depends on what your doing, when doing quick, dirty interop code,
    writing property accessors is usually not important, and is infact a real
    waste. However, exposing properties is often the best choice (in some cases
    the only choice) to provide a simpler interface for structs that may be
    accessed externally. However there is no hard and fast rule that I follow.
    [color=blue]
    > Seems to me people think struct = direct access, small, and easy.. Its[/color]
    just[color=blue]
    > a type like all the rest (except with differences i Know blah blah) but[/color]
    why[color=blue]
    > why why allow direct access. its just lazyness.. Code it once, and thats[/color]
    it,[color=blue]
    > where is the saving? I mean if its coded well in the first place then you
    > dont have to keep engineering it so its not exactly a lot of work to use
    > those extra lines..
    >
    > I also find ppl balk at the concept of using parameterized constructors[/color]
    and[color=blue]
    > methods in a struct, theyre just not thinking .NET , and are thinking the
    > old way of structs on C. The object is still lightweight even tho there[/color]
    are[color=blue]
    > methods, properties, and constructors..
    >[/color]
    I use methods, properties, and constructors where appropriate. I don't break
    my back to add property accessors on structs sometimes, if it will just be a
    get\set combo wrapped around a field. I would much prefer to see a method on
    a struct than a static method that takes a parameter on that struct if at
    all possible.[color=blue]
    > I just hate lazy coding.
    >[/color]
    Don't we all, ;).[color=blue]
    > /End gripe.
    >
    >
    >[/color]


    Comment

    • news.microsoft.com

      #3
      Re: structs ...

      No i agree for quicn n dirty stuff but I mean for things that are going to
      be used outside like components and user controls..

      I seen people write formatting methods when its more sensible to override
      ToString in the object and I just think they dont fully understand the
      concept of an object. Theyre thinking straight C.



      "Daniel O'Connell" <onyxkirx@--NOSPAM--comcast.net> wrote in message
      news:Kk5pb.8372 9$Fm2.63853@att bi_s04...[color=blue]
      >
      > "news.microsoft .com" <discussion@dis cussion.microso ft.com> wrote in[/color]
      message[color=blue]
      > news:%23Aipc1So DHA.3732@tk2msf tngp13.phx.gbl. ..[color=green]
      > > Hi,
      > >
      > > I am using structs and am also using property accessors to access[/color][/color]
      those[color=blue][color=green]
      > > private member fields... TO me this is a good way of handling them, but[/color][/color]
      I[color=blue][color=green]
      > > find alot of people using direct access to the struct memebers, since
      > > structs is just a type similar to a class (with differences I know) why
      > > should I allow direct access like that... I looked at the Size and other
      > > parts on Control etc and I find its the same way by using property
      > > accessors.
      > >[/color]
      >
      > It really depends on what your doing, when doing quick, dirty interop[/color]
      code,[color=blue]
      > writing property accessors is usually not important, and is infact a real
      > waste. However, exposing properties is often the best choice (in some[/color]
      cases[color=blue]
      > the only choice) to provide a simpler interface for structs that may be
      > accessed externally. However there is no hard and fast rule that I follow.
      >[color=green]
      > > Seems to me people think struct = direct access, small, and easy.. Its[/color]
      > just[color=green]
      > > a type like all the rest (except with differences i Know blah blah) but[/color]
      > why[color=green]
      > > why why allow direct access. its just lazyness.. Code it once, and thats[/color]
      > it,[color=green]
      > > where is the saving? I mean if its coded well in the first place then[/color][/color]
      you[color=blue][color=green]
      > > dont have to keep engineering it so its not exactly a lot of work to use
      > > those extra lines..
      > >
      > > I also find ppl balk at the concept of using parameterized constructors[/color]
      > and[color=green]
      > > methods in a struct, theyre just not thinking .NET , and are thinking[/color][/color]
      the[color=blue][color=green]
      > > old way of structs on C. The object is still lightweight even tho there[/color]
      > are[color=green]
      > > methods, properties, and constructors..
      > >[/color]
      > I use methods, properties, and constructors where appropriate. I don't[/color]
      break[color=blue]
      > my back to add property accessors on structs sometimes, if it will just be[/color]
      a[color=blue]
      > get\set combo wrapped around a field. I would much prefer to see a method[/color]
      on[color=blue]
      > a struct than a static method that takes a parameter on that struct if at
      > all possible.[color=green]
      > > I just hate lazy coding.
      > >[/color]
      > Don't we all, ;).[color=green]
      > > /End gripe.
      > >
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • Daniel O'Connell

        #4
        Re: structs ...


        "news.microsoft .com" <discussion@dis cussion.microso ft.com> wrote in message
        news:e39GM%23So DHA.1764@tk2msf tngp13.phx.gbl. ..[color=blue]
        > No i agree for quicn n dirty stuff but I mean for things that are going to
        > be used outside like components and user controls..
        >
        > I seen people write formatting methods when its more sensible to override
        > ToString in the object and I just think they dont fully understand the
        > concept of an object. Theyre thinking straight C.
        >[/color]
        Very probably.[color=blue]
        >
        >
        > "Daniel O'Connell" <onyxkirx@--NOSPAM--comcast.net> wrote in message
        > news:Kk5pb.8372 9$Fm2.63853@att bi_s04...[color=green]
        > >
        > > "news.microsoft .com" <discussion@dis cussion.microso ft.com> wrote in[/color]
        > message[color=green]
        > > news:%23Aipc1So DHA.3732@tk2msf tngp13.phx.gbl. ..[color=darkred]
        > > > Hi,
        > > >
        > > > I am using structs and am also using property accessors to access[/color][/color]
        > those[color=green][color=darkred]
        > > > private member fields... TO me this is a good way of handling them,[/color][/color][/color]
        but[color=blue]
        > I[color=green][color=darkred]
        > > > find alot of people using direct access to the struct memebers, since
        > > > structs is just a type similar to a class (with differences I know)[/color][/color][/color]
        why[color=blue][color=green][color=darkred]
        > > > should I allow direct access like that... I looked at the Size and[/color][/color][/color]
        other[color=blue][color=green][color=darkred]
        > > > parts on Control etc and I find its the same way by using property
        > > > accessors.
        > > >[/color]
        > >
        > > It really depends on what your doing, when doing quick, dirty interop[/color]
        > code,[color=green]
        > > writing property accessors is usually not important, and is infact a[/color][/color]
        real[color=blue][color=green]
        > > waste. However, exposing properties is often the best choice (in some[/color]
        > cases[color=green]
        > > the only choice) to provide a simpler interface for structs that may be
        > > accessed externally. However there is no hard and fast rule that I[/color][/color]
        follow.[color=blue][color=green]
        > >[color=darkred]
        > > > Seems to me people think struct = direct access, small, and easy..[/color][/color][/color]
        Its[color=blue][color=green]
        > > just[color=darkred]
        > > > a type like all the rest (except with differences i Know blah blah)[/color][/color][/color]
        but[color=blue][color=green]
        > > why[color=darkred]
        > > > why why allow direct access. its just lazyness.. Code it once, and[/color][/color][/color]
        thats[color=blue][color=green]
        > > it,[color=darkred]
        > > > where is the saving? I mean if its coded well in the first place then[/color][/color]
        > you[color=green][color=darkred]
        > > > dont have to keep engineering it so its not exactly a lot of work to[/color][/color][/color]
        use[color=blue][color=green][color=darkred]
        > > > those extra lines..
        > > >
        > > > I also find ppl balk at the concept of using parameterized[/color][/color][/color]
        constructors[color=blue][color=green]
        > > and[color=darkred]
        > > > methods in a struct, theyre just not thinking .NET , and are thinking[/color][/color]
        > the[color=green][color=darkred]
        > > > old way of structs on C. The object is still lightweight even tho[/color][/color][/color]
        there[color=blue][color=green]
        > > are[color=darkred]
        > > > methods, properties, and constructors..
        > > >[/color]
        > > I use methods, properties, and constructors where appropriate. I don't[/color]
        > break[color=green]
        > > my back to add property accessors on structs sometimes, if it will just[/color][/color]
        be[color=blue]
        > a[color=green]
        > > get\set combo wrapped around a field. I would much prefer to see a[/color][/color]
        method[color=blue]
        > on[color=green]
        > > a struct than a static method that takes a parameter on that struct if[/color][/color]
        at[color=blue][color=green]
        > > all possible.[color=darkred]
        > > > I just hate lazy coding.
        > > >[/color]
        > > Don't we all, ;).[color=darkred]
        > > > /End gripe.
        > > >
        > > >
        > > >[/color]
        > >
        > >[/color]
        >
        >[/color]


        Comment

        • Peter van der Goes

          #5
          Re: structs ...


          "news.microsoft .com" <discussion@dis cussion.microso ft.com> wrote in message
          news:%23Aipc1So DHA.3732@tk2msf tngp13.phx.gbl. ..[color=blue]
          > Hi,
          >
          > I am using structs and am also using property accessors to access those
          > private member fields... TO me this is a good way of handling them, but I
          > find alot of people using direct access to the struct memebers, since
          > structs is just a type similar to a class (with differences I know) why
          > should I allow direct access like that... I looked at the Size and other
          > parts on Control etc and I find its the same way by using property
          > accessors.
          >
          > Seems to me people think struct = direct access, small, and easy.. Its[/color]
          just[color=blue]
          > a type like all the rest (except with differences i Know blah blah) but[/color]
          why[color=blue]
          > why why allow direct access. its just lazyness.. Code it once, and thats[/color]
          it,[color=blue]
          > where is the saving? I mean if its coded well in the first place then you
          > dont have to keep engineering it so its not exactly a lot of work to use
          > those extra lines..
          >
          > I also find ppl balk at the concept of using parameterized constructors[/color]
          and[color=blue]
          > methods in a struct, theyre just not thinking .NET , and are thinking the
          > old way of structs on C. The object is still lightweight even tho there[/color]
          are[color=blue]
          > methods, properties, and constructors..
          >
          > I just hate lazy coding.
          >
          > /End gripe.
          >
          >[/color]

          You've hit the nail on the head with "and are thinking the old way of
          structs on C".
          Structs and unions are UDT's that predate the OO revolution. People who are
          "into" OO will find the defaults associated with structs bothersome, as they
          provide no OO benefits. From an OO perspective, struct defaults need a lot
          of "fixing", but that's not always the context in which they're used.

          --
          Peter - [MVP - Academic]


          Comment

          Working...