Passed Microsofts 70-536 exam.

In 2009 I made a commitment to myself en to my employer. I would become at least an MCTS on ASP.NET in 2010. I have raised the bar even higher by saying that if I would be an MCTS at the beginning of August I would go on and become an MCPD on ASP.NET before the end of 2010.
Last Tuesday I went to the examcenter in Leusden and I took the first exam needed to become an MCTS: 70-536 “Microsoft .Net Framework – Application Development Foundation. I passed the exam with a score of 930 out of 1000. A beautiful result, I should be happy. But am I?

Well, Yes… …I am happy with the result and me passing the test. But it left me with some mixed feelings. Let me explain.
I started learning for this exam at the beginning of  January. Studied the Self Paced Training Kit. Made the examples (well most of them) and took the test per chapter. Some subjects where difficult for me to understand (like Code Access Security CAS) and so I read several chapters in reference books. The Training Kit came with a CD with test exams and I took those as well.  I gave up a lot of free evenings in the past two months and was proud to have learned a lot more then I thought I would learn. Oh… and just two days before the exam I decided to download some TestKings and look at them as well.

So eventually I was taking the exam with some nervousness but in the back of my mind was confidence. I did my best and I should be able to pass the exam. I had to answer 40 questions. From this 40 there where at least 25 questions that where almost identical to the questions of the TestKings. I am convinced that if I only studied the TestKings and did nothing more than that, I would have passed the exam just as well. Probably not with 930 but that doesn’t matter does it? It matters that you pass the exam. No one looks at the grades when you show the certificate.

I think it is time for Microsoft to redefine their exams. At this moment anyone can pass their exams and it takes away the status of the certificate. I am proud of what I have achieved in the past months and will continue studying at the same way for the next exams.

But I did not passed the exam with 930… I did the Microsoft Trick and got 930 points out of it.

Optimizing your for-loop

I use for-loops on a daily basis. I use them when I write Javascript and in C#. The for-loop is very common and easy to use. Here is a typical example of a for-loop in C#:

for (int i = 0; i < arr.Length; i++)
     object arrayItem = arr[i];
     //do something with arrayItem

Even though this is a perfectly legal example of a for-loop there is room for improvement.
Each iteration of the for-loop the Length property of the array will be retrieved. The performance penalty on this is minimal but when your array consists of thousands of objects the performance penalty can be noticeable. The answer is:  ‘caching’.

The for-loop can be changed to cache the Length-value in a variable and then use that variable instead of the length property. Example:

for (int i = 0, len = arr.Length; i < len; i++)
     object arrayItem = arr[i];
     //do something with arrayItem

Caching the value of the Length-property is always a good thing to do even if you expect your array yo be minimal in length. There is no penalty for doing this on small arrays, only a benefit when used on large arrays. Therefore I recommend to always use caching in your array.

It works in C# as well as in Javascript and probably on a lot of more languages.

Happy coding.

Model View Presenter: Control Model

When you use the Model View Presenter (MVP) Pattern you design by contract. One of the contracts you specify is the contract which describes the graphical interface, called the view. Normally you will specify the contract with base types such as Strings and Booleans. I want to show you another way to define the view by using contracts specifying controls.

Martin Fowler called for the retirement of the MVP Pattern in July 2006 and suggested to separate the pattern into two new patterns, namely ‘Supervising Controller‘ and ‘Passive View‘. This blog-posting is not intended to explain the basics of the MVP-pattern. That being said, I even expect the reader to have a certain level of familiarity with the pattern.

The ‘Passive View’ is a pattern in which the User Interface has as less logic as possible. I prefer the ‘Passive View’ above the ‘Supervising Controller’ because lesser logic makes it easier to substitute the user interface with a new one. I use the Passive View as the pattern of choice and when I talk here about the MVP pattern I am referring to the Passive View approach.

As said above, classic MVP models the interface which describes the GUI (view) with Strings, Booleans and perhaps some domainobjects. When you want a grid in your GUI you will specify a List<object> in your view interface. Then in your implementation of the view you will have to write some logic to put the list of objects into the grid.
This approach has two major downfalls. The first is the amount of logic you have to put in your implementation. I am a big fan of the Passive View because the lack of logic in the implementation of the view makes the view easy to replace. The second downfall is that the logic you write in the implementation has to be written over and over again in the different forms and applications you create.
Read more

C# Conditional Operator versus Null-Coalescing Operator

In javascript I often use a phrase like this:

var text = tempText || “No Text Given”;

With this phrase we assign the value of tempText to the variable text. If tempText is null we assign “No Text Given” to the text variable.

To do the same trick in C# I was using the Conditional Operator:

string text = tempText != null ? tempText :  “No Text Given”;

In my opinion this isn’t very nice code. So I started searching and I found the nice Null-Coalescing Operator. It goes like this:

string text = tempText ?? “No Text Given”;

This looks much better.
For all you javascript-geeks. The javascript notation also checks for empty string. The Null-Coalescing Operator does not.

Happy coding!!

Runtime vs Compilation time

Not much code changes these days. But I have a good excuse. It is my holiday and tomorrow I’ll be heading towards Austria and Italy. But this doesn’t mean that I haven’t been thinking about ExtAppBuilder.

In my previous post I was thinking about some way to convert the C# code to JavaScript code. I figured out that the skeleton functions must remain and return null or 0. But my opinion has changed, because there is a difference between compilationtime and runtime.

When I write code to add a Panel only if the current user is in a certain role then this must be checked at runtime and not at compilation. To accomplish this the skeleton code still must return null or 0 but also must write a line of JavaScript code at the time they are called, runtime.

So what to do at compilation time. On compilation we must check the written code for functions which should be in a handler. We must create the handlers with two partial classes (just like your aspx.cs and aspx.designer.cs) and put the necessary code in it. This will ease the job of the developer because they don’t have to worry about writing handlers. This will be handled by ExtAppBuilder in a generic way

This might seem a bit cryptic and I write this down mostly as a reminder for myself. But in my next post, when I am back from holiday and when I understand the way of writing code blocks with WP (duh), I will explain my theory with code examples.