Sesame street knew Google before it existed

June 24th, 2010 Chris No comments

While brows­ing the web I ran into a really creepy movie on youtube.
It seems sesame street’s cookie mon­ster knew about google 27 years ago, way before it was founded ;)

[sar­casm mode]
Maybe they were one of the fun­ders of google?? ;)
[/sarcasm mode]

Any­way, with­out fur­ther ado… the flick ;)

Categories: .this Tags:

SSIS Lookup com­po­nent is case sensitive

March 16th, 2010 Chris No comments

The other day, i was work­ing on a new SSIS (SQL Server Inte­gra­tion Ser­vices) pack­age to trans­form data from a pro­duc­tion data­base to an analy­sis data­base. It worked quite well, i thought, every­thing seemed to work as it was sup­posed to when test­ing with a sub­set of data. So next up, live usage. And that was the moment the shit hit the fan.

All of a sud­den the pack­age began rais­ing errors because a crit­i­cal lookup was fail­ing and hence it didn’t find records.
The lookup task had to query a table con­tain­ing string val­ues and com­pare them to given val­ues, and while SQL is (nor­mally) case-insensitive the lookup com­po­nent seems to be case sen­si­tive. Speak­ing about find­ing out the hard way.

After some more read­ing, it seems this case-sensitivity is only active when using the ‘full-cached’ oper­at­ing mode.

Categories: .this Tags:

default(T) vs null

March 5th, 2010 Chris No comments

When pro­gram­ming in C#, we often test if a vari­able is used in the fol­low­ing way:

if (var != null) {
  // do the right thing
}
else
{
  // fallback or raise exception
}

This works well if the vari­able is a nul­lable type or a ref­er­ence type, but when the vari­able is of a non nul­lable type it will raise an excep­tion. This also works the other way around, when you test a ref­er­ence typed by com­par­ing it to 0, chances are quite big the run­time will also raise an exception.

Now you’re prob­a­bly think­ing it’s impos­si­ble to do this, because the com­piler will warn you about this and it sim­ply won’t com­pile. True, except when we don’t know the type before­hand, which usu­ally is the case when using generics.

Take a look at this code:

public bool isValueSet<T>(T source)
{
  return source != null;
}

This piece of code works almost exactly as the first code frag­ment in this post, though here it has room for the afore­men­tioned caveat. We don’t know if the type T is a ref­er­ence type or a value-type. There are more ways to make it work exactly how it’s intended.

  1. Setup a con­trol flow which switches between value-types and other types (ref­er­ence types) using the GetType().IsValueType property
  2. Use the default(T) con­struc­tion, so the frame­work will auto­mat­i­cally assigns the default value accord­ing to the given type. I myself pre­fer this solution.

When using the default(T) fol­low­ing code should always work as expected:

public bool isValueSet<T>(T source)
{
  return source != default(T);
}

long live the frame­work :)

Categories: C# Tags:

Now I’ll use short­ened urls in my twit­ter feed

February 24th, 2010 Chris 1 comment

As of now, I’m gonna use short­ened urls in my tweets.
The longer urls had some issues when tweet­ing, so I now use bit.ly to pro­vide the short­ened urls.

I’m curi­ous if it helps… well that’s it for now :)

Categories: .this Tags:

The O of SEO

February 19th, 2010 Chris No comments

Let me first tell you I’m no expert in SEO ( for those who don’t know the abbre­vi­a­tion, it stands for ‘Search Engine Opti­miza­tion :) ) but as it’s not that dif­fi­cult to find a lot of infor­ma­tion about it, I think I’m allowed to tell you what I think about it.

In my hum­ble opin­ion, SEO is often explained as the whole of web­site opti­miza­tion, linkbuild­ing and con­tent opti­miza­tion.
I myself think dif­fer­ent, as I’m con­vinced the SEO ends with the O of opti­miza­tion. Sure, if you want to achieve a high rank in search engine results, you need good incom­ing links and really good qual­ity arti­cles, but when peo­ple say thats SEO, it gives me the shiv­ers. Where is the opti­miza­tion in this ;) ?

The best start­ing point of the opti­miza­tion are the google guide­lines. When you fol­low these guide­lines you’ve already tack­eled a big part of opti­miza­tion. The next thing to do, although it’s not pure SEO based, is to opti­mize the user expe­ri­ence. Com­press js / css files, decrease load­ing time, cre­ate cached copies to serve from dynamic pages ( blog like ) etc…

Well these are my 2 cents in a really over­sat­u­rated dis­cus­sion about SEO, I’m try­ing to do these things on the job, and I fare well thereby, so it seems to work.

Categories: .this, SEO Tags:

Essen­tial tools for .net development

December 15th, 2009 Chris No comments

Every devel­oper has the need to use good tools from time to time. It makes the developer’s job a lot easier.

In my expe­ri­ence as a .NET devel­oper these are the really essen­tial tools every (.NET) devel­oper should have ( and use of course ;) ).

Red-Gate’s .NET Reflec­tor ( http://www.red-gate.com/products/reflector/ ).
This tool is in my opin­ion the swiss army knife of a .NET devel­oper. It was cre­ated by Lutz Roeder and recently acquired by Red-Gate soft­ware. There still is a free com­mu­nity ver­sion avail­able.  With this tool you can tra­verse all objects and types in an assem­bly ( and the assem­blies ref­er­enced there­from ) and, for instance, dis­as­sem­ble the IL back into a CLS com­pli­ant lan­guage ( C# / VB ). This tool can do much more than this, and is propably the tool I myself use most.

NUnit / Microsoft Visual Stu­dio 2008 Unit Tests
Every devel­oper should cre­ate unit tests to ensure their code works as it should. Both NUnit and the Unit test option in VS2008 are in my expe­ri­ence quite good. Though it are 2 dif­fer­ent frame­works, they both share the ease of use when imple­ment­ing the unit tests. And both can work from within the IDE ( though if I’m not mis­taken, NUnit needs a third party add-on ). You can find the lat­est ver­sion of NUnit here. The biggest advan­tage of NUnit to VS2008 Unit test is the cost of NUnit, it’s free. ( You don’t even need Visual Stu­dio, as long as you can com­pile code it will work )

Microsoft FxCop
I don’t want to stick feath­ers up microsoft’s but­tocks, but this tool is quite nice. Though it’s not really nec­es­sary to use this tool, I’ve grown quite fond of it. This tool checks the com­piled assem­blies IL code for com­pli­ance with the Microsoft .NET Frame­work Design Guide­lines. Though at first it’s a bit awk­ward to get many dis­ap­prove­ments on your code, it seems com­ply­ing to these guide­lines makes your code bet­ter, both in design and ( this might be just my imag­i­na­tion ) performance.

Microsoft Style­cop
Where FxCop checks your code in a com­piled state, Style­cop walks over the code and gives you advice on how to alter your code to com­ply to the microsoft cod­ing guide­lines. At some times it’s a really anno­ing pain in the ass, espe­cially when it comes to doc­u­ment­ing all prop­er­ties, meth­ods, types and so on.. In the end it makes your code bet­ter under­standible and bet­ter read­able. Espe­cially when your code will be used by oth­ers or when you need to edit the code after a while you’ll be glad you doc­u­mented every item.

There will be many other tools that assist devel­op­ers, in doing a hell-of-a very good job, but at the moment these are the ones I use a lot. Maybe in time I’ll change this list :D

Categories: Architecture, C#, Tooling Tags: , ,

Copy prop­er­ties between classes using LCG

December 11th, 2009 Chris No comments

How often do we devel­op­ers have to cre­ate func­tions just to copy prop­er­ties from one object to another object, just bescause it’s a dif­fer­ent type? If the source and des­ti­na­tion type have prop­er­ties with the same name and are of the same type, you can use Light­weight Code Gen­er­a­tion to cre­ate a del­e­gate to do just that.

As with all pro­gram­ming logic there is a pro and a con to using LCG to do this. Pro, it’s fast because you use com­piled code after you’ve built the del­e­gate. Con, it takes a bit of time to cre­ate this del­e­gate. I’d use this approach when I will surely need to call this copy­ing func­tion a lot.

Any­way, with­out fur­ther ado.. This is the func­tion I’ve cooked up. (and I’m sorry but the com­ments are in dutch… :) )

public static CopyPublicPropertiesDelegate GenerateCopyDelegate()
{
Type typeIn = typeof(T);
Type typeOut = typeof(U);

DynamicMethod dm = new DynamicMethod(typeIn.Name, null, new Type[] { typeof(T), typeof(U) }, typeof(GenericCopyObject).Module);

ILGenerator il = dm.GetILGenerator();

PropertyInfo[] propsIn = typeIn.GetProperties(BindingFlags.Public | BindingFlags.Instance);
PropertyInfo[] propsOut = typeOut.GetProperties(BindingFlags.Public | BindingFlags.Instance);

List ps = new List();

foreach (PropertyInfo prop in propsIn) // voor alle properties op het In object
{
PropertyInfo propOut = propsOut.FirstOrDefault
(t => t.Name.Equals(prop.Name) && (t.PropertyType.Equals(prop.PropertyType));
if (propOut != default(PropertyInfo)) // er is een property op het out object met dezelfde naam en type
if (prop.CanRead && propOut.CanWrite) // als we op de bron kunnen lezen en op het doel kunnen schrijven kunnen we kopieren
{
// nu een stukje Assembler...
il.Emit(OpCodes.Ldarg_1);   // Plaats het doelobject op de stack
il.Emit(OpCodes.Ldarg_0);   // Plaats het bronobject op de stack
il.EmitCall(OpCodes.Callvirt, prop.GetGetMethod(), null); // Haal het eerste element (bronobject) van de stack af en lees de waarde uit van de property
il.EmitCall(OpCodes.Callvirt, propOut.GetSetMethod(), null);// Haal het eerste element (doelobject) van de stack af en schrijf de waarde naar de property
}
}
il.Emit(OpCodes.Ret); // we zijn klaar dus de methode mag dan eindigen
return (CopyPublicPropertiesDelegate)dm.CreateDelegate(typeof(CopyPublicPropertiesDelegate));
}

The code needs a small warn­ing though, it won’t work with prop­er­ties with the same name but a dif­fer­ent type and generic types are also quite tricky.

I’m still work­ing on a fix for it, and I’m open for sug­ges­tions ;)

Categories: C#, Development Tags: , ,

Hello world!

December 9th, 2009 Chris Comments off

Hello world!

It’s prob­a­bly the most used sen­tence ever, so please don’t mind me using it again :)

For the peo­ple who already knew the orig­i­nal blaten.nl blog, this might come as a shock, but much is changed at blaten. As the old blog was only catch­ing dust, I’ve decided to cre­ate this new blog, which will con­tain more tech­ni­cally ori­ented post­ings. ( And prob­a­bly some office-humor once in a while. ) Maybe the biggest change is that this blog will be in eng­lish most of the time.

I sure hope you’ll come to read my blog once in a while.

Cheers,

Chris

Categories: .this Tags: