MS 70-536 passed

January 27th, 2008

I have passed my first MS exam :) Although it covers many aspects of .NET, it is the most stupid exam I have ever taken (Econometrics which I passed on a 6th attempt does not count :D)
Questions are very confusing and when you do not memorize most of .NET classes and methods you will probably fail. Many possible answers differ only by method signatures and you need to know exactly when the parameter A must be on position 1 and the parameter B must be on position 2. I am a little bit disappointed because there were no questions about designing and solving problems. IMHO this kind of exam does not prove that a programmer has any useful skills.

Anyway, I’m glad I could make it :)

AirFramework - short video

January 8th, 2008

I would like to show you my simple, portable OpenGL framework in action. I work on it in my spare time. It’s nothing special but it is not developed to write a computer game. It mainly helps me learning how to create various 3D effects using shaders. I decided not to write an engine or something which is very trendy (I hate that word) - just a simple framework which is able to render models in my own format, render textures available in memory, change render states and write text. Also an interactive console which can change many internal options and print debug information.

Below there is a simple, diffuse lighting model computed per fragment.

Here are two screenshots presenting difference between vertex and fragment computations:

Interactive console and wireframed rendering:

Rendering text and textures from memory:

Sorry for the poor quality of the movie but it’s youtube only :D

No source code or binaries, I’m sorry. The code isn’t tested well and in fact shaders look lame (I created them in a hurry) - please, forgive me this time ;)

Practical use of mutable

January 3rd, 2008

I have finally found a practical use of mutable keyword in C++ :D

Suppose we have a class and we want to do some "lazy loading":

C++:
class Foo
{
    private:
        Bar *bar;
    public:
        const Bar& GetBar() const;
};

const Bar& Foo::GetBar() const
{
    // lazy loading
    if(bar == NULL)
    {
        bar = new Bar();
    }
}

Everything would be fine but the const keyword does not allow us to change a value of a bar pointer.
That's the place where mutable is useful :)

C++:
class Foo
{
    private:
        mutable Bar *bar;
    public:
        const Bar& GetBar() const;
};

const Bar& Foo::GetBar() const
{
    // lazy loading
    if(bar == NULL)
    {
        bar = new Bar();
    }
}

Happy coding :)

Sophisticated debugging in .NET

December 18th, 2007

Every programmer must sometimes use a debugger ;) In fact, most of our job is filled with debugging rather than writing code.
In the .NET framework there are many great features we can use to make us life easier. Today I am gonna present you a few very useful things from System.Diagnostics namespace.

Debugger class:
This is a class which allows us a communication with a attached debugger. It has multiple members but there are 3 of them I want you to notice.:

  • Break - It just sends a break signal to a debugger. Very useful when we want to conditionally stop the execution of our application
  • Launch - It can launch a debugger and attach it to a process
  • Log - It posts a message to the attached debugger

IMHO, the most useful of those three methods is Break. Priceless when we have an unexpected situation in a code. Thanks to this method we are able to break an execution of a program. Look at this snippet:

C#:
object foo = Bar.GetSomething();
if(foo == null)
{
    Debugger.Break();
}

Cool, isn't it? ;)

Debug class:
Another good class which provides us helper methods in debugging process. Noticeable are:

  • Assert - Evaluates a condition and displays a message if a condition is false. Well known for a "test driven" programmers.
  • Fail - Outputs a failure message. Quite similar to the previous one but it doesn't evaluate an expression.
  • Indent and Unident - useful for output formatting.
  • Write, WriteLine and Print - write information to the Debug / Trace listeners
  • WriteIf, WriteLineIf - The same as above but only when specified condition is met

Ok, those classes are in fact primitive but here is something that is very useful in debugging complex hierarchical objects.
Ladies and Gentleman - please welcome Debug attributes. Thanks to them a developer is able to declaratively specify how an application should behave during debugging process.
Let's say that you do not want a debugger step into a piece of code (because it's tested and works well) - no problem, there is DebuggerHiddenAttribute. Actually it stops a breakpoint from being set inside anything that it decorates.

C#:
class Foo
{
    [DebuggerHidden()]
    public void Bar()
    {
        // impossible to debug here :)
    }
}

Impossible to set a breakpoint

Let's say that we want to determine how a class or a property is displayed in a debugger window. There are two other attributes: DebuggerBrowsableAttribute and DebuggerDisplayAttribute. This code will do a trick with local variable / watch window in Visual Studio:

C#:
[DebuggerDisplay("Our Foo class")]
class Foo
{
    [DebuggerBrowsable(DebuggerBrowsableState.Never)]
    private int _bar = 10;

    [DebuggerDisplay("Value of Bar is: {_bar}")]
    public int Bar
    {
        get
        {
            return _bar;
        }
    }
}

and a debugger view:

Debugger attributes

Nice :) You can ofcourse set some parameters to those attributes. There are more attributes such as DebuggerStepThroughAttribute but I recommend further reading on MSDN.

Unexpected Error 0×8ffe2740 Occurred

November 26th, 2007

"Unexpected Error 0x8ffe2740 Occurred" - this message appeared today on my PC when I was trying to start IIS. A while of "googling" revealed that this is rather normal behavior of the server :)

According to http://support.microsoft.com/kb/816944 this error occurs when some other application uses port 80 (default for a web server).

Instead of expressive error message they create KB article with explanations :)

Designed by SirMike © All rights reserved

Valid XHTML 1.0! Valid CSS!