Fabulous Adventures In Coding
Eric Lippert is a principal developer on the C# compiler team. Learn more about Eric.
My copy of Essential C# 4.0 just arrived, and it looks great. I was one of the technical reviewers of this book. Some books are a pain to edit, but the Essential C# series is one of my favourites. It totally lives up to its name; it really does give you lots of essential information for developing high-quality real-world programs in C#.
I just wanted to take this opportunity to publically congratulate Mark on his latest accomplishment in publishing and to thank him for his kind words in the acknowledgements. I’d also like to thank everyone at A-W for supporting my book editing habit and for supporting the community by publishing great books about C#. Thank you all.
That was quick... C# 4 only came out three days ago!
Did he get the latest changes, like the ---> operator?
I just got my copy today and I have to say it was definitely worth it. Easy to read and great as a reference tome for all things C#. I just wish there was a larger section devoted to PLINQ and it's underpinnings but it's understandable with a book that has to cover so much.
The part about GetHashCode get me to think think about value semantics. The book says that:
1) result of GetHashCode should not change during a lifetime of an object (it even suggests caching - I do not see how it helps)
2) GetHashCode should return equal results for equal objects
Now imagine we have overriden Equals method that uses objects' state to determine equality. Second statement means that GetHashCode should operate only on that state and result should be fully determined by that state (that's why I do not see how caching of mutable properties can help in that case. Caching may help if we'rel using reference equality though).
In other turn that means that object may change its state only in such way that it does not change its hash code. Essentially that means that objects that have value semantics should be immutable.
What bothers me that I have not seen this statement written in MSDN anywhere. Howver, I've seen several frameworks that use value semantics for business objects (of course keeping them mutable).