structs ...

  • Thread starter Thread starter news.microsoft.com
  • Start date Start date
N

news.microsoft.com

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.
 
news.microsoft.com said:
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.

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.
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 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.
 
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.
 
news.microsoft.com said:
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.
Very probably.


but be method
 
news.microsoft.com said:
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.

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.
 
Back
Top