I didn’t know that.

January 8th, 2008

But now as I do, it makes me feel stupid.

Today I learned that I don’t need a 3. party utility or a feature-rich graphical application to make a snapshot of my active Windows window. I can simply press Alt + Prt Scrn.

- petter


Mimic the C# yield instruction in VC++

November 29th, 2007

Recently mickey0 posted a question on the CodeGuru forum, asking whether VC++ had any syntax similar to the C# yield instruction. Although I knew the answer was ‘no’, I was still intrigued to figure out if it was possible to implement something similar.

I started with a web search and found a couple of existing implementations, all of which were using Win32 Fibers, so I realized that fibers was the way to go. Even though the examples I found was good tutorials on fibers, they did not meet my requirements on a proper yield implementation. So I had to get dirty. Read the rest of this entry »

Safe to remove hardware

November 25th, 2007

This message keeps popping up on my laptop:

Safe To Remove Hardware

As far as I know my laptops network card is a part of the motherboard, and trying to remove it would probably involve a hammer and a chisel. And that’s safe?!

- petter


Static predicates, delegate inference and performance

November 24th, 2007

C# 2.0 introduced a feature called delegate inference. Delegate inference is an simplification of how you initialize delegates.

Where you prior to C# 2.0 would have to write:

MyDelegate d = new MyDelegate(MyFunction);

You can now simply write:

MyDelegate d = MyFunction;

The two lines of code behaves exactly the same. They construct a new instance of MyDelegate passing MyFunction as argument to the constructor, and then assign the instance to the variable d.

As the name ‘delegate inference’ suggests, the compiler fills in the ‘missing parts’ using inference, leaving the developer with less keystrokes and more readable code. Which is a good thing. Read the rest of this entry »

Guestbook

November 15th, 2007

You’ve managed to get this far, so you might as well leave some ‘comments’ in my guestbook…

The bad thing about String.IsNullOrEmpty…

November 8th, 2007

…is that it makes me wonder why they didn’t throw in Array.IsNullOrEmpty as well.

-petter

’Almost real’ functor objects in C#

October 27th, 2007

In these days of delegates, anonymous methods and lambda expressions, I’ve found it necessary to talk about good old functor objects. A functor is an object, that in some fashion you can treat as a function. Put another way, a functor is an object that you can call. Read the rest of this entry »

Lazy programming…

October 13th, 2007

I’ve been working alot with web services lately, querying for information and recordsets, applying business logics and then finally displaying it all on a web page. A problem that I need to deal with (it feels like) all the time is empty responses from the service layer.

Sometime the response is null, sometimes not. Sometimes inner collections of a response are empty, null… anyway, it end up with alot of theese:

if (products != null)
{
    foreach (Product product in products)
    {
        // do something with product
    }
}

Doing these if-nulls over and over again made me realize that I needed an NeverNullEnum wrapper, Read the rest of this entry »

Multi-threading the wrong way.

October 12th, 2007

Some time back I had an experience down at a local supermarket, a strange experience that reminded me of a neglected topic in software development. The topic of efficient multi-threading.

Everybody knows multi-threading as a difficult thing. Multi-threaded applications are inherently difficult to develop, debug and maintain and has potentially evil pitfalls in form of race-conditions and deadlocks and what not. You need your thoughts clear and your tongue straight and remember to put locks, monitors and synchronization objects all over your code… but in the end it will make your application run at leaping speeds while utilizing the smallest of transistors in your top-notch multi-core CPU. Read the rest of this entry »

Powered by WordPress. Entries (RSS) and Comments (RSS).