Posts

Someone I know recently got stung by this, so I thought I’d mention it... static void Main(string[] args) {   int a = 1;   int b = a;   Console.WriteLine(AreSame(a, b).ToString());   Console.ReadLine(); } static bool AreSame(object a, object b) {   return a == b; } What’s the output to the console? Does a equal b? Even if you didn’t know the answer you will have guessed it is False otherwise this blog would be totally pointless! It’s false because the parameter types of AreSame are both "object". For a value type such as "int" to be passed as an object it needs to be boxed, so a new object instance is created which stores the value "1", but this is done for both parameters so we end up with 2 new instances both holding the value 1. 1 equals 1 for value types but the default comparison for System.Object is to compare references. If they are not the exact same object (and in this case they are not) then the result is false. Now if we typecast both a and

I don't like AccuRev

A company I have been contracting for decided to use AccuRev as its source control solution. I've not liked it from the start because it is too much work, the terminology in it is quite frankly stupid, and it is far too "chatty" when you work remotely.  Anyway, for some time now I have suspected it has been losing source code. On a few occasions I have found myself looking at source code and thinking "I could swear I have already done this!". Well, last week I wrote some pretty nice code which used multiple threads in a test case to ensure I experienced expected behavior when multiple users update the same objects in a database.  Today one of the other programmers said to me "Didn't you write more tests than this?" and showed me the tests.  My multi-threaded tests were gone! I knew it all along, but now it is indesputible, AccuRev has been losing my work!

The Pragmatic Programmer

My copy of this book has just turned up. I am book hungry these days, can't wait to read it :-)

Connascence

I’ve just finished reading What every programmer should know about object oriented design . The first couple of sections are a bit useless really, but the 3rd section is very good. I particularly liked the section on the difference types of connascence in software. There’s some basic information about it here if you fancy a brief overview of what it is about. It’s a really good book, I recommend you read it! Should only take a day if you only read the 3rd section.

I've just ordered a Java book

Image
http://java.sun.com/blueprints/corej2eepatterns/index.html It was only $0.41 used in the USA, came to about £6 with posting to the UK. I don't write Java and at the moment have no interest in learning it, but I expect I will be able to read it without problems (never really looked at it). So why did I buy this book? Because it is about this... That's why :-)

Prism - Invariants, and pre/post conditions - update

Just found out that I can do this too public invariants   Overdraft >= 0 : ’OverdraftGreaterThanOrEqualToZero’;   Balance + Overdraft >= 0 : ’BalancePlusOverDraftGreaterThanOrEqualToZero’; end; Then in my handler routine I get that message! if not IsValid then   throw new Exception(ErrorMessage); Excellent :-)

Prism - Invariants, and pre/post conditions

I’ve been looking at Prism some more recently. I’m a bit annoyed with myself really because someone has been telling me to look at it for years but I wanted to concentrate on C#. Now that I am looking at it I see things in there which I really like. Recently I am looking at invariants, pre-conditions, and post-conditions. First let me show you the invariant support. An invariant is like a class constraint, it specifies a condition which must be true but when must it be true? type   BankAccount = public class   public     property Balance : Decimal read write;   public invariants     Balance >= 0;   end; The invariant is enforced each time a public method exits. Actually it is enforced after the post-conditions of a public method exits but we don’t have any post conditions yet. class method ConsoleApp.Main; begin   var account : BankAccount := new BankAccount();   //The next line throws an assertion error   account.Balance := -1; end; Property getters and setters are considered