.NET Framework 3.5

Posted on July 30, 2007

static int DoBinOp(Func<int,int,int> op, int a, int b)
{
return op(a, b);
}

Assert.Equal(3, DoBinOp((a,b) => a + b, 1, 2));

Filed Under Uncategorized | Leave a Comment

C# is actually pretty good

Posted on July 29, 2007

C# 3.0 has some really good good featurs, with liberal use of generics, language integrated queries (LINQ), lamda expressions and closures, we can make it look like Ruby or some functional language:

 

public static class CommonExtensions
{
    public static Action<Action<int>> LoopTo(this int start, int end)
    {
        return new Action<Action<int>>(action => To(start, end).ForEach(i => action(i)));
    }

    public static IEnumerable<int> To(this int start, int end)
    {
        if (end < start)
            for (int i = start; i > end - 1; i–)
                yield return i;
        else
            for (int i = start; i < end + 1; i++)
                yield return i;
    }

    public static void ForEach<T>(this IEnumerable<T> sequence, Action<T> action)
    {
        foreach (T item in sequence) action(item);
    }

    public static void PrintLine(this object o)
    {
        Console.WriteLine(o);
    }
}

So now we could try and do this….

 

// ruby
(10..20).each { |i| puts i }
// C#
10.LoopTo(20) ( i => i.PrintLine() );

(example from BitterCoder blog)

C# 3.0
customers.Where(c => c.IsActive == true).Each(c => c.OutputToConsole());

C# 3.0
customers.Where(c => c.IsActive == true).Each(c => c.OutputToConsole());
C# 2.0
foreach(Customer c in customers)
{
if(c.IsActive)
System.Console.WriteLine(c.ToString());
}

Functional programming is dead right? ;-)

Filed Under Uncategorized | 1 Comment

Junctions

Posted on July 25, 2007

Sometime ago I had a problem with maximum file path on Windows XP implementation of NTFS. Well, NTFS has a little known feature called junction points which can be used like symlinks on Unix. Windows comes with console program that allows to create them, but I found this really great program that integrates into explorer shell. And now a can have all projects reside in one directory.

BTW from the wikipedia page I found that Vista now has real symlinks. Finally one reason to upgrade! ;-)

Filed Under Uncategorized | Leave a Comment

Amazing!

Posted on July 25, 2007

I watched TV yesterday. It’s amazing! In one TV commercial about computers the fact that anti-virus software is included was one of the key points.

Imagine if in travel ads the key point was included anti-diarrhea pills!

(Well I understand that we live in imperfect world and we need such stuff, still I found it funny)

Filed Under Uncategorized | Leave a Comment

Poor man’s dependency injection

Posted on July 25, 2007

class Demo
{
constructor() {
this.constructor(new Dependency1, new Dependency2)
}

constructor(IDependency1 dep1, IDependecy2 dep2) {
// b;ah
}
}

Interface IDependency1…
Interface IDependency2…

Filed Under Uncategorized | Leave a Comment

Math programming language

Posted on July 15, 2007

math.png

Trigonometry is major part of the my current project.

Just few years ago I thought that math was interesting, but useless, now I know how important it really is.

Filed Under Uncategorized | Leave a Comment

Ohh, too much code.

Posted on July 14, 2007

I decided to practice and wrote a simple GUI application. It is a simple contact list manager with persistent contact list. With test driven development to design the application, Presenter First pattern as a variant of MVP pattern, and Mocks for testing.

files.png

I like the result: program structure is elegant, classes are small and cohesive, and easily tested. However I had to write 9 classes, 7 test fixtures and 7 interfaces just for a simple contact list manager.

I can modify view and it wouldn’t require a lot of changed in the other classes. Because application is developed on top of interfaces and events I can replace GUI view with Web or command-line interface and it would still work. I can change storage from file to database and it will not affect any other parts of the application.

The design of the view and presenter classes is simple but design and testing of object interactions take a lot of time.

I did not have to do any problem solving for my models, they are simple and I did not spend a lot of time on them. However on a realistic project that will be different.

What I don’t like is the amount of code I had to write, there must be a better way! With less code and with same confidence in the behaviour.
I also think that if I increase the complexity 10 times, I would have difficuly keeping the whole program design in my head. The must be a way to document the design without spending too much time on writing and drawing stuff.

Filed Under Uncategorized | Leave a Comment

Global Shortcuts in Windows

Posted on July 13, 2007

I was coding, then I pressed Ctrl+Alt+J, one of resharper commands, and all of a sudden Nero Showcase lunched and nothing happend in VS.

To fix the problem I had to disable global shortcut in Nero ShowTime properties:

nero.png

Filed Under Uncategorized | Leave a Comment

Life never cease to amaze me

Posted on July 6, 2007

camera.JPG

Concordia Gym.

Filed Under Uncategorized | Leave a Comment

I’m offended!

Posted on July 5, 2007

windows-media-player-help.png

Fuck you Microsoft, I don’t have disabilities! I am a Keyboard Jedi! ;0)

Filed Under Uncategorized | Leave a Comment

Next Page »

© Copyright 0xDEADBEEFCAFE • Powered by Wordpress • Design by Sebastin.

free web hit counter