Mutable Structs are Evil. Yes. Really.

Of course, you know the rule, don’t you. If you want to define your own value types in .NET, make sure they are immutable. Don’t create mutable value types!

Unfortunately, today, I forgot that rule. And I paid the price in a couple of hours needless debugging. Continue reading “Mutable Structs are Evil. Yes. Really.”


Big-Endian vs Little-Endian: How Do You Remember Which is Which?

If you need to read binary files or binary streams, you need to know whether the file you’re reading is big-endian or little-endian.

It’s about the order that the bytes are stored in the file. For example the number 1, stored as a 32 bit integer, is 00000001, occupying 4 bytes. That means you need a sequence of four bytes in the file to store the number. If you put the byte that holds the most significant bits first, then the bytes look like this: Continue reading “Big-Endian vs Little-Endian: How Do You Remember Which is Which?”

IEquatable and All That: The Nine Comparisons Interfaces

In my last article I pointed out that Microsoft has given us no less than nine different general-purpose interfaces to perform the simple task of comparing objects to see if they are equal, or if one is greater than the other.

And I ended with a quick quiz. Could you identify those nine interfaces?

Continue reading “IEquatable and All That: The Nine Comparisons Interfaces”

C# Equality and Comparisons Published

My new Pluralsight course, C# Equality and Comparisons, has been published this week, bringing my total to 3 courses  with the two existing courses. Math for Programmers and C# Collections Fundamentals.

C# Equality and Comparisons was largely spawned out of the earlier C# Collections course:  Back in February this year, I was writing samples for that course to demonstrate making dictionaries case-insensitive. The easiest way to do that is to supply a case-insensitive equality comparer to the dictionary constructor, like this: Continue reading “C# Equality and Comparisons Published”

Dear computer: I INSPIRE YOU.

Since my career is moving from straight programming towards teaching programmers (Yes, the Pluralsight C# Collections Fundamentals Course is coming soon…), I’ve realized I occasionally need to communicate with people by some means other than email. So I recently enrolled on a class aimed at improving your voice for public speaking. (Yeah, I know, I felt that merely putting people to sleep in technical talks wasn’t enough. But if I had enough voice skills to put people into a coma….). Continue reading “Dear computer: I INSPIRE YOU.”

Happy Not-Your-Birthday

So you’re reading this. That means you’re probably an IT person. So you don’t need any reminding that that you should give as little information about yourself as possible to strange organizations. The fewer databases there are that hold all your personal details, the fewer opportunities there are for the bad guys to hack in and steal those personal details.

And even aside from the security considerations, isn’t it just annoying when you register on a website and the website demands that you spend time typing in information about yourself that the website clearly does not need to know.

But of course there is an obvious defence against this: Continue reading “Happy Not-Your-Birthday”

AutoProperties, Structs and Constructors (C# Wishes Part 3)

I’m sure most of us have been there. You have some small data type to declare, which only really contains a couple of primitives and is clearly most appropriate to exist as a struct. You put a couple of values in it, and because you’re doing this quickly and you want your code to be simple, you use auto properties. For this kind of struct there’s (hopefully) no reason not to.

And in the best traditions of those cookery programmes you see on tv, here’s one that I prepared earlier: Continue reading “AutoProperties, Structs and Constructors (C# Wishes Part 3)”