Skip to main content

Where to start ;-p

Eric Lippert's blogEric Lippert's blog is always good for a quote:

This is yet another reason why mutable value types are evil. Try to always make value types immutable.

First, you tend to lose changes quite easily... for example, getting things out of a list:

Foo foo = list[0]; foo.Name = "abc"; 

what did that change? Nothing useful...

The same with properties:

myObj.SomeProperty.Size = 22; // the compiler spots this one 

forcing you to do:

Bar bar = myObj.SomeProperty; bar.Size = 22; myObj.SomeProperty = bar; 

less critically, there is a size issue; mutable objects tend to have multiple properties; yet if you have a struct with two ints, a string, a DateTime and a bool, you can very quickly burn through a lot of memory. With a class, multiple callers can share a reference to the same instance (references are small).

Where to start ;-p

Eric Lippert's blog is always good for a quote:

This is yet another reason why mutable value types are evil. Try to always make value types immutable.

First, you tend to lose changes quite easily... for example, getting things out of a list:

Foo foo = list[0]; foo.Name = "abc"; 

what did that change? Nothing useful...

The same with properties:

myObj.SomeProperty.Size = 22; // the compiler spots this one 

forcing you to do:

Bar bar = myObj.SomeProperty; bar.Size = 22; myObj.SomeProperty = bar; 

less critically, there is a size issue; mutable objects tend to have multiple properties; yet if you have a struct with two ints, a string, a DateTime and a bool, you can very quickly burn through a lot of memory. With a class, multiple callers can share a reference to the same instance (references are small).

Where to start ;-p

Eric Lippert's blog is always good for a quote:

This is yet another reason why mutable value types are evil. Try to always make value types immutable.

First, you tend to lose changes quite easily... for example, getting things out of a list:

Foo foo = list[0]; foo.Name = "abc"; 

what did that change? Nothing useful...

The same with properties:

myObj.SomeProperty.Size = 22; // the compiler spots this one 

forcing you to do:

Bar bar = myObj.SomeProperty; bar.Size = 22; myObj.SomeProperty = bar; 

less critically, there is a size issue; mutable objects tend to have multiple properties; yet if you have a struct with two ints, a string, a DateTime and a bool, you can very quickly burn through a lot of memory. With a class, multiple callers can share a reference to the same instance (references are small).

Probably done with this thought now
Source Link
Marc Gravell
  • 1.1m
  • 273
  • 2.6k
  • 3k

Where to start ;-p

Eric Lippert's blog is always good for a quote:

This is yet another reason why mutable value types are evil. Try to always make value types immutable.

First, you tend to lose changes quite easily... for example, getting things out of a list:

Foo foo = list[0]; foo.Name = "abc"; 

what did that change? Nothing useful...

The same with properties:

myObj.SomeProperty.Size = 22; // the compiler spots this one 

forcing you to do:

Bar bar = myObj.SomeProperty; bar.Size = 22; myObj.SomeProperty = bar; 

less critically, there is a size issue; mutable objects tend to have multiple properties; yet if you have a struct with two ints, a string, a DateTime and a bool, you can very quickly burn through a lot of memory. With a class, multiple callers can share a reference to the same instance (references are small).

(still thinking...)

Where to start ;-p

Eric Lippert's blog is always good for a quote:

This is yet another reason why mutable value types are evil. Try to always make value types immutable.

First, you tend to lose changes quite easily... for example, getting things out of a list:

Foo foo = list[0]; foo.Name = "abc"; 

what did that change? Nothing useful...

The same with properties:

myObj.SomeProperty.Size = 22; // the compiler spots this one 

forcing you to do:

Bar bar = myObj.SomeProperty; bar.Size = 22; myObj.SomeProperty = bar; 

less critically, there is a size issue; mutable objects tend to have multiple properties; yet if you have a struct with two ints, a string, a DateTime and a bool, you can very quickly burn through a lot of memory. With a class, multiple callers can share a reference to the same instance (references are small).

(still thinking...)

Where to start ;-p

Eric Lippert's blog is always good for a quote:

This is yet another reason why mutable value types are evil. Try to always make value types immutable.

First, you tend to lose changes quite easily... for example, getting things out of a list:

Foo foo = list[0]; foo.Name = "abc"; 

what did that change? Nothing useful...

The same with properties:

myObj.SomeProperty.Size = 22; // the compiler spots this one 

forcing you to do:

Bar bar = myObj.SomeProperty; bar.Size = 22; myObj.SomeProperty = bar; 

less critically, there is a size issue; mutable objects tend to have multiple properties; yet if you have a struct with two ints, a string, a DateTime and a bool, you can very quickly burn through a lot of memory. With a class, multiple callers can share a reference to the same instance (references are small).

added 385 characters in body
Source Link
Marc Gravell
  • 1.1m
  • 273
  • 2.6k
  • 3k

Where to start ;-p

Eric Lippert's blog is always good for a quote:

This is yet another reason why mutable value types are evil. Try to always make value types immutable.

First, you tend to lose changes quite easily... for example, getting things out of a list:

Foo foo = list[0]; foo.Name = "abc"; 

what did that change? Nothing useful...

The same with properties:

myObj.SomeProperty.Size = 22; // the compiler spots this one 

forcing you to do:

Bar bar = myObj.SomeProperty; bar.Size = 22; myObj.SomeProperty = bar; 

What else..less critically, there is a size issue; mutable objects tend to have multiple properties; yet if you have a struct with two ints, a string, a DateTime and a bool, you can very quickly burn through a lot of memory. With a class, multiple callers can share a reference to the same instance (thinkingreferences are small).

(still thinking...)

Where to start ;-p

First, you tend to lose changes quite easily... for example, getting things out of a list:

Foo foo = list[0]; foo.Name = "abc"; 

what did that change? Nothing useful...

The same with properties:

myObj.SomeProperty.Size = 22; // the compiler spots this one 

forcing you to do:

Bar bar = myObj.SomeProperty; bar.Size = 22; myObj.SomeProperty = bar; 

What else... (thinking)

Where to start ;-p

Eric Lippert's blog is always good for a quote:

This is yet another reason why mutable value types are evil. Try to always make value types immutable.

First, you tend to lose changes quite easily... for example, getting things out of a list:

Foo foo = list[0]; foo.Name = "abc"; 

what did that change? Nothing useful...

The same with properties:

myObj.SomeProperty.Size = 22; // the compiler spots this one 

forcing you to do:

Bar bar = myObj.SomeProperty; bar.Size = 22; myObj.SomeProperty = bar; 

less critically, there is a size issue; mutable objects tend to have multiple properties; yet if you have a struct with two ints, a string, a DateTime and a bool, you can very quickly burn through a lot of memory. With a class, multiple callers can share a reference to the same instance (references are small).

(still thinking...)

Source Link
Marc Gravell
  • 1.1m
  • 273
  • 2.6k
  • 3k
Loading