Software development, .Net, SQL Server, TDD, Agile, Community and other Odds and Sods
Mitch Wheat has been working as a professional programmer since 1984, graduating with a honours degree in Mathematics from Warwick University, UK in 1986. He moved to Perth in 1995, having worked in software houses in London and Rotterdam. He has worked in the areas of mining, electronics, research, defence, financial, GIS, telecommunications, engineering, and information management. Mitch has worked mainly with Microsoft technologies (since Windows version 3.0) but has also used UNIX. He holds the following Microsoft certifications: MCPD (Web and Windows) using C# and SQL Server MCITP (Admin and Developer). His preferred development environment is C#, .Net Framework and SQL Server. Mitch has worked as an independent consultant for the last 10 years, and is currently involved with helping teams improve their Software Development Life Cycle. His areas of special interest lie in performance tuning
Monday, March 28, 2011
Useful Codeplex Libraries
I recently came across two useful codeplex libraries. The first enables you to create advanced Excel 2007/2010 spreadsheets without Office installed, EppPlus:
The second is a .NET wrapper of the ImageMagick image manipulation API, ImageMagick.NET
Sunday, March 27, 2011
Quotes: When there is no…
When there is no wind ... ROW! - Latin Proverb
When there is no peril in the fight there is no glory in the triumph. - Pierre Corneille
When there is no enemy within, the enemies outside cannot hurt you. - African Proverb (often attributed to Winston Churchill)
Real love is a pilgrimage. It happens when there is no strategy, but it is very rare because most people are strategists. – Anita Brookner
Perfection is finally attained not when there is no longer anything to add, but when there is no longer anything to take away - Antoine de Saint Exupéry
Laws and principles are not for the times when there is no temptation: they are for such moments as this, when body and soul rise in mutiny against their rigour; stringent are they; inviolate they shall be. - Jane Eyre in Charlotte Bronte.
When there is no vision the people perish. - Franklin Delano Roosevelt (from his first inaugural address)
It is hard to apply oneself to study when there is no money to pay for food and lodging. - Zora Neale Hurston
Saturday, March 26, 2011
Microsoft Virtual Academy
Microsoft (and just about everyone else) has a cloud focus these days, so it's no surprise that Microsoft Learning has also ventured there. Last week saw the official debut of the Microsoft Virtual Academy.
The Microsoft Virtual Academy is targeted at the cloud, with self-paced courses for learning more about private and public clouds, to more specific coverage of Windows Azure and SQL Azure.
Wednesday, March 09, 2011
Visual Studio 2010 Service Pack 1 Released
Visual Studio 2010 SP1 RTM has been released for MSDN subscribers! Get it here
It will be made generally available over the next day or so.
Monday, March 07, 2011
Binary Search: A Cautionary Tale!
Practically every developer knows what binary search is: a simple (indeed fundamental) searching algorithm which is an example of a natural divide-and-conquer strategy. Basically: starting with an already sorted array, compare the middle element of the array with the value we want to find. If the values are the same we are done, else if the array element is larger, repeat in the remaining lower half of the array, else if the array element is smaller, repeat in the remaining upper half of the array.
Unsurprisingly, binary search is an often used interview question (although perhaps less so, due to increasing complexity and the proliferation of programming frameworks; I must admit I’ve never personally been asked about it in an interview). It is a basic technique that you can reasonably expect every reasonable candidate to know and can be implemented in just a few lines of code.
Despite binary search’s simplicity, it is easy to implement it incorrectly!
Jon Bentley, in his book Programming Pearls (a programming classic), wrote that in a course he ran for professional programmers, he asked the participants to code binary search and found that 90% failed to implement it correctly. If you asked 100 programmers to write an implementation of binary search a large number of them would be incorrect and many of those those that apparently worked would actually contain subtle flaws. Indeed, many published implementations of binary search are wrong:
Indeed, Jon Bentley’s own implementation of binary search, published in the ‘Writing Correct Programs’ chapter of Programming Pearls, contained a subtle bug that remained undetected for over twenty years. Here is an iterative C# implementation, adapted from Bentley’s pseudocode, that contains the bug (can you spot it?):
public static int BinarySearch(int sortedArray, int valueToFind)
int lower = 0;
int upper = sortedArray.Length - 1;
while (lower <= upper)
m = (lower + upper) / 2;
if (sortedArray[m] < valueToFind)
lower = m + 1;
else if (sortedArray[m] == valueToFind)
upper = m - 1;
The bug is in the mid-point assignment
m = (lower + upper)/2
which performed as a direct sum could lead to an integer overflow. It should be replaced by the identically equivalent safe expression
m = lower + (upper – lower)/2
This bug was highlighted in Chapter 1 of Algorithms for Interviews, IMO, a slightly misnamed book which could perhaps be better described as ‘Algorithms to make programmers think’, where the emphasis is on describing problems and getting the reader to attempt to solve them.
[Side Note: A quick check with Reflector shows that this is implemented correctly without the possible overflow flaw in .NET 4, in fact the developers have gone put of their way to make sure someone doesn’t introduce this bug by encapsulating the mid-point division in its own Method GetMedian()]
Thursday, March 03, 2011
SQL Server: Optimizing tempdb Performance : Moving tempDB to a New Location
The size of tempdb can affect the performance of a system. For example, if the tempdb size is too small, the system processing could be too occupied with autogrowing the database to support your workload requirement every time that you start SQL Server. You can avoid this overhead by pre-sizing tempdb. For more information, see Optimizing tempdb Performance and Capacity Planning for tempdb.
Optimizing tempdb Performance
If you're seeing PAGELATCH (not PAGEIOLATCH) waits on tempdb, then you can mitigate these using trace flag 1118 and creating multiple tempdb data files. Paul Randal wrote a blog post debunking some myths around this trace flag and why it's still potentially required in SQL 2005 and 2008 - Misconceptions around TF 1118.
-- 1.Determine the logical file names of the tempdb database and current location on disk.
Wednesday, March 02, 2011
How to Write Without Writing
I’ve long admired (perhaps even envied) Jeff Atwood’s ability to craft interesting, informative and thought provoking articles on his ‘Coding Horror’ blog. His recent post How to Write Without Writing is a great example why.
The ability to inform, entertain and present connected ideas is a wonderful skill.
Personally, I’ve always found writing difficult (though perhaps less so in the last 5 years).The main reason I started blogging was to improve my writing (and also to record things I find useful and tend to misplace!). If you set yourself a goal of writing a short blog post once a week, you are forcing yourself to write something. The more often you write, the more likely your writing skills will improve.
Some time ago I answered a question on StackOverflow: Should programmers be able to write clearly? I firmly believe the answer to that question is “Yes”. If you can’t communicate and express yourself clearly, how can you write correct code?
MSN, Email: mitch døt wheat at gmail.com