Feeds:
Posts
Comments

Archive for June, 2008

Top-10 stories do enjoy great popularity! Why could that be? Well, it all comes down to laziness :-) Someone scanned all the web and simply wrote down the best for me.

In fact those compilations – as also this one – usually are just a cross section within a small range of experience and sight. That is also the reason why you can find so many of them.

So I just searched for the most kicked top-10-stories on DotNetKicks.com, and listed them up here. Enjoy!

  1. Top 10 Best Practices for Production ASP.NET Applications kick it on DotNetKicks.com
    DNK: A short list of some things to pay attention to when dealing with production ASP.NET applications.
  2. 10 ASP.NET Performance and Scalability Secrets
    kick it on DotNetKicks.com
    ASP.NET 2.0 has many secrets, when revealed, can give you big performance and scalability boost. A must read. But take your time and read it slowly…
  3. Dead link! Sorry. Comment if you find a mirror!
    Retaining Good Developers – 10 Things To Keep Them Happy (53 kicks)
    DNK: This is a great article. I just wish some of my previous employers would have done just a few of these things. I probably would have stuck around longer.
  4. 10 Visual Studio Shortcuts You Must Know
    kick it on DotNetKicks.com
    Me: Well, I use ReSharper, so these don’t impress me that much :-)
  5. 10 reasons why SQL Server 2008 is going to rock
    kick it on DotNetKicks.com
  6. 10 reasons why I chose MySQL over MSSQL2005 Express
    kick it on DotNetKicks.com
  7. 10 Podcasts Every Developer Should Listen To
    kick it on DotNetKicks.com
    DNK: A list of 10 developer related podcasts, some popular and some rather obscure, ranging in topics from Agile tenets to Architecture best practices. A list I hope everyone will discover at least a few new gems to listen to.
  8. 10 Tips to improve your LINQ TO SQL Application Performance
    kick it on DotNetKicks.com
    DNK: Sidar gives performance tips on developing linq 2 SQL
  9. 10 Usability Nightmares You Should Be Aware Of
    kick it on DotNetKicks.com
    DNK: Usability mistakes that you will want to avoid.
  10. 10 awesome Windows Live Writer plugins for developer
    kick it on DotNetKicks.com
  11. 10 Tips for a happy upgrade to Visual Studio 2008 RTM
    kick it on DotNetKicks.com
    DNK: Jon Galloway puts together a nice summary for updating Visual Studio 2008 Beta 2 to Visual Studio 2008 RTM. This can save you a couple of headaches if you read it before upgrading!
  12. 10 Tools Which I Left After Using VSTS 2008
    kick it on DotNetKicks.com
  13. Top 10 .NET bloggers
    kick it on DotNetKicks.com
  14. Top 10 JavaScript String.prototype Extensions
    kick it on DotNetKicks.com
    DNK: List of top 10 JavaScript String.prototype Extensions
  15. Jacob Nielsen: Top-10 Application-Design Mistakes
    kick it on DotNetKicks.com
    DNK: Application usability is enhanced when users know how to operate the UI and it guides them through the workflow. Violating common guidelines prevents both.
  16. Ten SQL Server Functions That You Hardly Use But Should edit / delete
    kick it on DotNetKicks.com
  17. 10 Tools Which I Still Use, Even I Have VSTS 2008
    kick it on DotNetKicks.com
  18. 10 Great Free Tools for ASP.NET Developers
    kick it on DotNetKicks.com
    DNK: Ten of the most useful free tools for ASP.NET developers
  19. Dime Casts .Net – Short howto videos for .Net developers
    kick it on DotNetKicks.com 
    DNK: Check out this new cool site with screencasts around 10 minutes in length. Great resource for .Net developers.
  20. .Net Threads – 10 Best Practices
    kick it on DotNetKicks.com
    DNK: Back to basics series – Article talks about 10 best practices to adopt while writing multi-threaded applications

If you like them, kick ‘em, and kick me, please!

kick it on DotNetKicks.com

Read Full Post »

After reading the great article about the code-saving yield keyword “Give way to the yield keyword” by Shay Friedman I thought it could be interesting to know how the yield keyword works behind the scenes.

…it doesn’t really end the method’s execution. yield return pauses the method execution and the next time you call it (for the next enumeration value), the method will continue to execute from the last yield return call. It sounds a bit confusing I think… (ShayF)

By using yield return within a method that returns IEnumerable or IEnumerator the language feature is activated.

Note: IEnumerable is kind of a stateless factory for Enumerators. IEnumerable.GetEnumerator() is thread safe and can be called multiple times, while the returned stateful Enumerator is just a helper for enumerating contained values once. By contract IEnumerator offers a Reset() method, but many implementations just throw a NotSupportedException.

Lets create an enumerator method that yields some Fibonacci nubmers.

public class YieldingClass
{
    public IEnumerable<int> GetFibonachiSequence()
    {
        yield return 1;
        yield return 2;
        yield return 3;
        yield return 5;
    }
}

Note: Yield is not a feature of the .Net runtime. It is just a C# language feature which gets compiled into simple IL code by the C# compiler.

The compiler now generates a inner class with following signature (Reflector + some renaming):

[CompilerGenerated]
private sealed class YieldingEnumerator : 
   IEnumerable<object>, IEnumerator<object>
{
    // Fields
    private int state;
    private int current;
    public YieldingClass owner;
    private int initialThreadId;

    // Methods
    [DebuggerHidden]
    public YieldingEnumerator(int state);
    private bool MoveNext();
    [DebuggerHidden]
    IEnumerator<int> IEnumerable<int>.GetEnumerator();
    [DebuggerHidden]
    IEnumerator IEnumerable.GetEnumerator();
    [DebuggerHidden]
    void IEnumerator.Reset();
    void IDisposable.Dispose();

    // Properties
    object IEnumerator<object>.Current 
    { [DebuggerHidden] get; }

    object IEnumerator.Current 
    { [DebuggerHidden] get; }
}

The original method GetFibonachiSequence() only returns a new instance of the YieldingEnumerator, passing the initial state –2 as well as itself as the owner.

Each enumerator holds a state indicating:

  • -2: Initialized as Enumerable. (Not yet an Enumerator)
  • -1: Closed
  • 0: Initialized as Enumerator. 
    If a new Enumerator is requested on the same instance, GetEnumerator() returns another new instance of YieldingEnumerator.
  •  1-n: Index of the yield return in the original GetFibonachiSequence()method. In case of nested enumerators or other more complex scenarios one yield return consumes more than one index.

The content of GetFibonachiSequence() is translated into YieldingEnumerator.MoveNext().

In our very simple scenario the code looks like this:

bool MoveNext()
{
    switch (state)
    {
        case 0:
            state = -1;
            current = 1;
            state = 1;
            return true;

        case 1:
            state = -1;
            current = 2;
            state = 2;
            return true;

        case 2:
            state = -1;
            current = 3;
            state = 3;
            return true;

        case 3:
            state = -1;
            current = 5;
            state = 4;
            return true;

        case 4:
            state = -1;
            break;
    }
    return false;
}

Quite easy, isn’t it?

So far we easily could have created the classes and methods used to enable the yield keyword ourselves, too.

But in more complex scenarios Microsoft does some tricks, which won’t compile as C# – at least not how Reflector translates the resulting IL code.

Lets have a look at some code with a nested enumeration…

foreach(int i in new int[] {1, 2, 3, 5, 8})
{
    yield return i;
}

This compiles into:

private bool MoveNext()
{
    try
    {
        switch (state)
        {
            case 0:
                state = -1;
                state = 1;
                this.values = new int[] { 1, 2, 3, 5, 8 };
                this.currentPositionInValues = 0;
                while (this.currentPositionInValues < this.values.Length)
                {
                    current_i = this.values[this.currentPositionInValues];
                    current = current_i;
                    state = 2;
                    return true;
                Label_007F:
                    state = 1;
                    this.currentPositionInValues++;
                }
                this.Finally2();
                break;

            case 2:
                goto Label_007F;
        }
        return false;
    }
    fault
    {
        this.System.IDisposable.Dispose();
    }
}

Now the states 1 and 2 are used to indicate whether the enumerator actually is at some point (2), or wether it is trying to retrieve the next value (1).

Two things would not compile:

  • goto Label_007F is used to jump back into the iteration over int[] values. The C# goto statement is not able to jump into another statements context. But in IL this is totally valid as a while statement in MSIL is nothing but some gotos either.
  • The fault is proper MSIL, but not supported in C#. Basically it acts as a finally which just is executed in case of an error.

Attention: As in anonymous delegates, parameters as well as local and instance variables are passed to the YieldingEnumerator only once. Read this great post on this: Variable Scoping in Anonymous Delegates in C#

Thanks for your attention!

kick it on DotNetKicks.com

Read Full Post »

I would like R# to detect references to members, classes, parameters, generic parameters in the code documentation and either offer completion or quickfixes just to generate the necessary markup.

Just by typing "The parameter bar of type IBar..... " inside a code documentation tag R# could quickly fix it to be "The parameter <paramref name="bar"/> of type <see ref="IBar"/>...."

I would then use much more references in the documentation.

/// <summary>
/// The parameter <paramref name="bar"/> of 
/// type <see ref="IBar"/> ....
/// </summary>
void Foo(IBar bar);....

 

You like it? Vote for the feature request in JetBrains Jira!

Read Full Post »

Follow

Get every new post delivered to your Inbox.

Join 432 other followers