A generic Dispenser class

Monday, 28 April 2008 09:22 by Yoav Sion

Feeling ashamed for keeping your clients waiting until your code finally constructs your heavy classes/forms?

This utility instantiates objects in a background thread and aspires to always be "full" to the capacity requested. Useful in cases the object being constructed uses many resources and is consumed frequently.

More...

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Give back to your testing framework

Tuesday, 22 April 2008 10:23 by Yoav Sion

Can there be code reuse in testing classes? Is code coverage the only measurement we have for test efficiency? Should our testing framework test design and meta-code as well as functionality?

More...

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

A fluent repeater

Thursday, 17 April 2008 04:22 by Adrian Aisemberg

We often need to repeat some method calls, until some condition is met.

For example:

- Try to save a file, if it fails, try again, until it succeeds, but no more than 10 times in total.

- Ping a server, 100 times, and pause two seconds between each ping.

- Try to open a file, in a low-priority background thread, and when it succeeds, call some callback method, if it fails opening the file, try again, but call another callback method every time it fails.

And so on...

More...

Currently rated 4.5 by 4 people

  • Currently 4.5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Searching for derived types in an assembly

Tuesday, 15 April 2008 11:36 by Yoav Sion

Sometimes we need to find all classes or interfaces that derive a certain Type. There are several possible scenarios for this kind of search - For instance, if we are trying to load a plug-in assembly at runtime and wish to initialize all the classes that implement the IPluginBase interface. Using the suggested DerivedHelper makes it a lot easier.

More...

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Debugging can screw things up

Monday, 14 April 2008 08:21 by Adrian Aisemberg

Here's a piece of code:

class BadCounter
{
    private int count;

    public int Inc
    {
        get { return ++count; }
    }
}

Lets leave the fact that this is the worst counter ever,

Can you spot the bug, without even knowing the requirements?

More...

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Enumerating the GAC using 'foreach'

Monday, 14 April 2008 07:56 by Adrian Aisemberg

I needed to create an "About" dialog for some application.

The dialog is required to display a list of all the application's assemblies, and their version numbers.

All the assemblies are signed using a single strong-name key (SNK file), and this is the only application that uses that key.

So I've decided to enumerate the GAC and search for all assemblies with the same key token as the running assembly's key token.

More...

Currently rated 5.0 by 2 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

[Flags] and you - Take 2

Sunday, 13 April 2008 09:50 by Yoav Sion

Comparing enum values can sometime leave your code a little messy and inaccessible if you (once again) did not document it properly.

A short piece of code such as this will never be accepted with joy by any developer, especially not during those long debug sessions a moment before the weekend:

[Flags]
public enum Status
{
    None = 0,
    New = 1,
    InProcess = 2,
    Open = 4,
    Frozen = 8,
    Rejected = 16,
    Irrelevant = 32,
}

public bool ValidateStatusBeforeSending(Status status)
{
    // Missing elaborate documentation right HERE.
    return (status == Status.New ||
            (int)status & (Status.Open | Status.Rejected) == Status.None);
}

More...

Currently rated 2.7 by 3 people

  • Currently 2.666667/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

C# singleton snippet

Saturday, 12 April 2008 20:27 by Yoav Sion

I've decided it's time to stop the copy-paste madness.

More...

Currently rated 4.3 by 3 people

  • Currently 4.333333/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

C# params quiz and issues

Friday, 11 April 2008 11:31 by Adrian Aisemberg

Params and arrays

Here's a C# quiz regarding params:

class Program
{
    static void Main()
    {
        // case 1
        Foo(1, 2);

        // case 2
        Foo(new int[] { 1, 2 });

        // case 3
        Foo(new object[] { 1, 2 });
    }

    static void Foo(params object[] args)
    {
        // args?
    }
}

Can you tell what is the value of 'args' in each case?

Answers below...

More...

Currently rated 5.0 by 2 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Fun with Continuous-Integration. Introducing: BILTONS

Thursday, 10 April 2008 05:57 by Adrian Aisemberg

"What happened to the build machine?"

"Who broke the build?"

"Who fixed it?"

 

All these questions, and more, can be answered using a fun and cool method: "Biltons".

Well, a bilton, like a rington, is actually a wav file that will be played whenever something happens to the build machine ("Build-Tone").

More...

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5