Tuesday, October 28, 2008

New Firefox feature - burnt screen?!

Late yesterday night I needed to needed to find information in MSDN so I opened my trusted web browser only to be greeted by this sight:


Like the software developer that I am I've tried to blame my hardware (screen) for my grief. unfortunately after opening a different web browser I couldn't avoid the conclusion that something really bad happened to my Firefox.


Any thoughts?

CodeRush Express Available as free download

It seems that DevExpress (along with Microsoft) are giving away an "express" version of their tool CodeRush.

You can read all about it here - CodeRush Xpress announced and available

From the download page:

Supported Features:

CodeRush Xpress includes the following features.

  • Duplicate Line
  • Highlight All References
  • Increase or Reduce Selection
  • Smart Clipboard Operations
  • Generate from Using (TDD)
  • Quick Navigation Window
  • Quick File Navigation

In addition, you receive the following refactorings:

  • Add Block Delimiters
  • Combine Conditionals
  • Compress to Lambda Expression
  • Compress to Ternary Expression
  • Convert to Auto-implemented Property
  • Convert to Initializer
  • Create Backing Store
  • Decompose Initializer
  • Decompose Parameter
  • Expand Lambda Expression
  • Expand Ternary Expression
  • Extract Method
  • Flatten Conditional
  • Inline Delegate
  • Inline Temp
  • Introduce Local
  • Make Explicit
  • Make Implicit
  • Move Type to File
  • Name Anonymous Method
  • Name Anonymous Type
  • Reverse Conditional
  • Split Conditional
  • Use String.Format
  • Use StringBuilder

If don't have licence for CodeRush or Resharper go and download this great VS addin.

Sunday, October 26, 2008

StackOverflow Notifier update

Due to a (stupid) bug I accidentally caused SO notifier to poll the StackOverflow site every half a second. The new version has a polling interval of once per hour.

In case you want to use StackOverflow Notifier use this newer version instead so your IP won't be banned.

If you're using StackOverflow Notifier - Read this!

This morning my client has stopped working on my computer. After checking the usual suspects (network connection, proxy server etc.) I discovered that only blocks my web requests.

After a quick search on the Internet I found the following post on StackOverflow blog:

We’ve noticed there are a number of users running a script that retrieves their uncompressed user page multiple times per second, producing an absurd amount of network traffic. Fortunately, we do cache the user page if the requests come in anonymously, so the database load was not significant.

However, this behavior is irresponsible and unacceptable, so we will permanently ban any IP we see doing this. We’ve already banned about a dozen IPs for this, and we will continue to do so. If you persist, your account will be permanently deleted. We might even lay down long term IP block bans if necessary.

We would prefer that you use our RSS feeds, or lobby us to improve our RSS feeds, rather than scrape Stack Overflow so aggressively.

Right now I'm trying to find what can I do so that SO NOtifier would work without violating the site's rules.  I have removed the SO Notifier download for the meantime and in case you're still using my application please stop until I'll sort it out with the site's administrators.


Hopefully this issue will be resolved quickly

Saturday, October 25, 2008

Find the difference – spot the bug


Every developer has been at a point when a defect is found in software he has been working on, in fact a major part of every software developer is fixing bugs.

A software bug (or just “bug”) is an error, flaw, mistake, failure, fault or “undocumented feature” in a computer program that prevents it from behaving as intended (e.g., producing an incorrect or unexpected result). Most bugs arise from mistakes and errors made by people in either a program's source code or its design, and a few are caused by compilers producing incorrect code. A program that contains a large number of bugs, and/or bugs that seriously interfere with its functionality, is said to be buggy. Reports detailing bugs in a program are commonly known as bug reports, fault reports, problem reports, trouble reports, change requests, and so forth.

From Wikipedia - Software bug

The first order of business is to find what caused it, for that we need to discover what piece of code needs to be rewritten in order for the software to work properly. And so if we want to find a software defect all we need to ask ourselves is:

What is the difference between the code that used to work and the code right now.



[From Paradesh Baata’s Blog]


Sometimes we can know the location of the bug by knowing our project very well but sometimes we have no clear idea of the exact code that could cause it.

Using simple practices and common tools can decrease the time spend on finding (and fixing) the bug.

Early discovery

In the ideal world when a new bug is entered into our code we would know about it - unfortunately for most of us we do not work in that place where each and every bug is discovered a few minuets after we’ve created it.

  • What we can do to improve our odds greatly is use unit tests as part of the software development process.
    If our project has a good coverage of unit tests all we need to do is run them and see which tests fails and by a process of elimination we might know the code that caused the defect.
  • The second most valuable tool to find bugs as soon as they enter our system is using a continues integration:
    1. Maintain a code repository
    2. Automate the build
    3. Make your build self-testing
    4. Everyone commits every day
    5. Every commit (to mainline) should be built
    6. Keep the build fast
    7. Test in a clone of the production environment
    8. Make it easy to get the latest deliverables
    9. Everyone can see the results of the latest build

And so by having a server that that runs all of our project’s unit tests we improve our chance of catching defects soon and isolate the problematic code.

Find when the bug was created – when the code stopped working

What if you project doesn’t have unit tests? what if the unit tests didn’t catch the bug and it was discovered by another developer, the QA department or even a customer – what can we do now?

Hopefully the bug report is detailed enough in that case we can try to reproduce it with previous versions of the code. When a version that don’t reproduce the bug is found – we know that the version after it has the code that caused that defect. Now we need to do some thinking and try to figure what is the difference between that version and the versions after it.

  • The number one tool that can helps us here is a proper source control that would help us retrieve previous versions of the application. It still amazes me that some software companies do not have a proper source control set up but in that case it is up to the developer to keep previous versions of his code in some secure location.


Even after we have an idea of where the defect is and what caused it most of the time we’ll still need to debug that code to verify our thesis. but by eliminating the places the bug isn’t we can reduce the time spent on finding it. There are some times when nothing helps and all we can do is debug our code line by line hoping to find the problem but by properly understanding our code and using simple elimination we can make it easier.

Wednesday, October 22, 2008

StackOverflow Notifier

Update: New version has been released in case you're using the last version (V1.0.0.0) please use this version instead.

In case you don't know what StackOverflow is all about you can read about it At the site's About Page:

Stack Overflow is a programming Q & A site that's free. Free to ask questions, free to answer questions, free to read, free to index, built with plain old HTML, no fake rot13 text on the home page, no scammy google-cloaking tactics, no salespeople, no JavaScript windows dropping down in front of the answer asking for $12.95 to go away. You can register if you want to collect karma and win valuable flair that will appear next to your name, but otherwise, it's just free. And fast. Very, very fast.

Or Read The review at everything2.

StackOverflow has a reputation system. Your questions and answers can be votes up (or down) by other users of the site. Each of those votes adds or subtract points from your reputation. More reputation enables the user to do additional actions other then posting questions and answering. You can read about it that here.

At the high end of this reputation spectrum there is little difference between users with high reputation and moderators. That is very much intentional. We don't run Stack Overflow. The community does.

Gaining reputation is very addictive and I found myself constantly refreshing my user web page to see if anyone has voted one of my answers or if anyone answered one of my questions. After a while I've decided to write a simple application that would notify me when my StackOverflow user have been updated.


How does it work?

The first time you run the application you'll need to give it your user URL.


The user url is the complete address of your user page


After your details have been loaded press OK to minimize to the tray and That's it - From now on whenever the notifier detects a change in your user you would be notified via a balloon tooltip at the task bar.


Future Plans

Right now only reputation changes are shown. I plan to add several more notifications in the very near future such as:

  • Question Answered.
  • Answer/Question Voted.
  • Answer has been chosen as the question answer.


You can download it from StackOverflow Notifier Codeplex Site. Have a look at it and let me know what you think.

Friday, October 10, 2008

Why should I use List and not ArrayList

I came upon a questing at StackOverflow:

The system I work on here was written before .net 2.0 and didn't have the benefit of generics. It was eventually updated to 2.0, but none of the code was refactored due to time constraints. There are a number of places where the code uses ArraysLists etc. that store things as objects.

From performance perspective, how important change the code to using generics? I know from a perfomance perspective, boxing and unboxing etc., it is inefficient, but how much of a performance gain will there really be from changing it? Are generics something to use on a go forward basis, or it there enough of a performance change that a conscience effort should be made to update old code?

Other then the obvious benefit of using strongly typed collection there is a performance increase as well.

Performance benchmarking

Checking the difference between using List & ArrayList is easy to check by writing a simple C# code:

class Program
static Stopwatch stopper = new Stopwatch();
const int ITEM_NUM = 100000;
const int NUM_OF_ITERATIONS = 1000;

static void Main(string[] args)
ArrayList arrayList = new ArrayList();
List<int> listOfInt = new List<int>();

Console.WriteLine("Inserting to ArrayList took: {0}ms", InsertItemsToArrayList(arrayList));
Console.WriteLine("Inserting to List<T> took: {0}ms", InsertItemsToList(listOfInt));
Console.WriteLine("Enumerating ArrayList took: {0}ms", IterateArrayList(arrayList));
Console.WriteLine("Enumerating List<T> took: {0}ms", IterateList(listOfInt));

private static double InsertItemsToArrayList(ArrayList arrayList)

for (int i = 0; i < NUM_OF_ITERATIONS; i++)

for (int j = 0; j < ITEM_NUM; j++)


return (double)stopper.ElapsedMilliseconds / (double)NUM_OF_ITERATIONS;

private static double InsertItemsToList(List<int> listOfInt)

for (int i = 0; i < NUM_OF_ITERATIONS; i++)
for (int j = 0; j < ITEM_NUM; j++)


return (double)stopper.ElapsedMilliseconds / (double)NUM_OF_ITERATIONS;

private static double IterateArrayList(ArrayList arrayList)
for (int i = 0; i < ITEM_NUM; i++)

for (int i = 0; i < NUM_OF_ITERATIONS; i++)
for (int j = 0; j < arrayList.Count; j++)
int item = (int)arrayList[i];


return (double)stopper.ElapsedMilliseconds / (double)NUM_OF_ITERATIONS;

private static double IterateList(List<int> listOfInt)

for (int i = 0; i < ITEM_NUM; i++)

for (int i = 0; i < NUM_OF_ITERATIONS; i++)

for (int j = 0; j < listOfInt.Count ; j++)
int item = listOfInt[i];

return (double)stopper.ElapsedMilliseconds / (double)NUM_OF_ITERATIONS;

The results


There is a performance hit when using ArrayList but we could not attribute it entirely to boxing/unboxing.

Boxing And Unboxing Impact

In a blog post “Why boxing doesn't keep me awake at nights” Jon Skeet shows that although boxing an integer causes performance decrease it is relatively minor. You can see in his benchmark that using object instead of int in various function calls doesn’t cause 4-100% decrease in performance like we saw in our tests. So the big performance hit in the ArrayList vs. List<int> tests must be due to some other factor.

Other reasons

Searching the net I found another post - Performance Guideline: Use Generics To Eliminate the Cost Of Boxing, Casting and Virtual calls.

In this post J.D. Meier shows that there is a performance difference even between ArrayList and List<object>:

List<Object> class gives better performance over ArrayList.  An example benchmark of a quick-sort of an array of one million integers may show the generic method is 3 times faster than the non-generic equivalent. This is because boxing of the values is avoided completely. In another example, the quick-sort of an array of one million string references with the generic method was 20 percent faster due to the absence of a need to perform type checking at run time.   You results will depend on your scenario.

And the last reason I can think of is Memory Caching:

From Wikipedia:

A CPU cache is a cache used by the central processing unit of a computer to reduce the average time to access memory. The cache is a smaller, faster memory which stores copies of the data from the most frequently used main memory locations. As long as most memory accesses are to cached memory locations, the average latency of memory accesses will be closer to the cache latency than to the latency of main memory.

The CPU Cache is of limited size, when a collection is being read some of it copied into the cache but due to the limited size of the cache when we iterate past the elements in the cache there is a need of another copy.

The size of int is 4 byte while the size of an object is four times that size this means that only a quarter of the elements would be copied to the cache memory when the collection is enumerated or read (in order to insert objects into it). When enumerating the entire collection the cache is re-written less times when using ints then when using objects.


Object based collections are a relic from .NET 1.x times before we had Generics. But since version 2 of .NET got out and we can use strongly typed collections it seems that we do not need to using ArrayList and such - Other then the performance benefits that were shown in here we gain type-safety and make our code much more readable.

Tuesday, October 07, 2008

MSDN Magazine October 2008 - Features Parallelism

In case you haven't noticed yet the new issue of MSDN magazine is available online. This issue focuses on multi-threading and parallel programming and has very interesting articles on that topic.

The content is great - especially for developers that are interested in learning how to make the switch from sequential to parallel (multi threaded) programming.

Editor's Note: new Thread(ReadEditorsNote).Start(); yourAttention.WaitOne();

Paradigm Shift: Design Considerations For Parallel Programming

Coding Tools: Improved Support For Parallelism In The Next Version Of Visual Studio

Concurrency Hazards: Solving 11 Likely Problems In Your Multithreaded Code

Easy Async: Build Concurrent Apps From Simple F# Expressions

Windows With C++: Exploring High-Performance Algorithms

I believe that those articles are a must due to the fact that today every low end home PC has multiple cores.

So go and learn how to think in parallel - as always the articles are well written and easy to understand.

Related Posts Plugin for WordPress, Blogger...