# Omer van Kloeten's .NET Zen

Programming is life, the rest is mere details

### News

Note: This blog has moved to omervk.wordpress.com.

Omer has been professionally developing applications over the past 8 years, both at the IDF’s IT corps and later at the Sela Technology Center, but has had the programming bug ever since he can remember himself.
As a senior developer at NuConomy, a leading web analytics and advertising startup, he leads a wide range of technologies for its flagship products.

## October 2004 - Posts

I think I get it now: foreach is ok for static arrays, but bad for everything else (look at #5 on the list).

Oh. :)

They say it would be fixed in vnext, though.

On a side note, remember to never ever take for over foreach if you can use the enumerator to enumerate on your list at O(1), like in a linked list, where index-based enumeration would be a large perf hit.
Pretty simple, but keep it in mind. :)

I had a conversation with Aviad several days ago as to how a logical xor operation could be described in a sentence. Just yesterday, I had the same conversation with a co-worker.

First, we looked at what each logical operation performs:

• a and b - only true both operands are true.
• a or b - true when either one of the operands is true.
• a xor b - true when only one of the operands is true.
• not a - true when the operand is false.

Then we looked at how we can describe the xor operation with other logical operations:

`a xor b = (a and not b) or (b and not a)`
And then we looked at how we can describe the or operation with other logical operations:
`a or b = (a xor b) xor (a and b)`

Now, let's think verbally for a minute. We can agree that the logical and and not operations are what they mean.
But what does the word 'or' mean? What if I asked you for 'apples or oranges'? Am I asking you to give me apples, oranges or both?
The answer is that it means I want either one, but not both.

So a verbal 'or' is really a logical xor? Yes! They mean exactly the same - a xor b means  'a or b'.

Up until now, we've seen that the following translations can be made:

1. a and b => 'a and b'.
2. a xor b => 'a or b'.
3. not a => 'not a' (= 'the opposite of a').
All that's left is translating the logical or.

Let's go back to the original formula:

`a or b = (a xor b) xor (a and b)`
What we see here is that a logical or can be comprised of a logical xor and logical and expressions. Let's take the verbal expressions and place them instead of the logical ones:
`a or b = " 'a or b' or 'a and b' "`
Let's compact it a bit:
`a or b = 'a and/or b'`
And there you have it.

I, as a programmer, was used to using 'or' in my verbal algorithm descriptions, but only now am I aware of the duplicity.
I hope you too can take something away from this :)

I sent Junfeng the following question:

"I was wondering why the assemblies in the service packs released by Microsoft for the 1.x versions of the runtime have the same version numbers as do the unpatched assemblies. Why were publisher policy assemblies not used instead? Is this a recommended practice?"

Now he replies with an answer I didn't even consider.

Just a quickie that's been bothering me:

The types MyType and MyType<T> are not the same type, as you might already know. Also, MyType<int> and MyType<string> are not of the same type. So, how do I find out if MyType<int> and MyType<string> are from the same MyType<T>?

I will use the Type.GetGenericTypeDefinition() method like so:

`MyType<int> i, MyType<string> s;bool b = s.GetType().GetGenericTypeDefinition() == i.GetType().GetGenericTypeDefinition();`

Cool.