Click here to Skip to main content
15,903,388 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: Range Checking Pin
fjdiewornncalwe1-Nov-10 2:59
professionalfjdiewornncalwe1-Nov-10 2:59 
GeneralRe: Range Checking Pin
AspDotNetDev1-Nov-10 6:20
protectorAspDotNetDev1-Nov-10 6:20 
JokeRe: Range Checking Pin
fjdiewornncalwe2-Nov-10 1:34
professionalfjdiewornncalwe2-Nov-10 1:34 
GeneralRe: Range Checking Pin
richard_k5-Nov-10 19:24
richard_k5-Nov-10 19:24 
GeneralRe: Range Checking Pin
Chris Meech1-Nov-10 5:03
Chris Meech1-Nov-10 5:03 
GeneralRe: Range Checking Pin
AspDotNetDev1-Nov-10 6:22
protectorAspDotNetDev1-Nov-10 6:22 
GeneralRe: Range Checking Pin
fjdiewornncalwe2-Nov-10 1:35
professionalfjdiewornncalwe2-Nov-10 1:35 
GeneralUgly, ugly, ugly! Pin
jamie55031-Oct-10 12:24
jamie55031-Oct-10 12:24 
I was digging around some code I wrote three years ago, looking for the cause of a bug some reported, when I found this. And no wonder - the full code is so full of holes that I'm surprised it works as expected.

/// <summary>
/// 
/// </summary>
/// <param name="adjancies"></param>
/// <param name="regions"></param>
/// <returns>True if was a special case.</returns>
private static bool CheckSpecialCases(List<List<int>> adjancies, Dictionary<int, Region> regions)
{
	if (regions.Count < 2) return true;
	if (regions.Count == 2)
	{
		int key1 = 0, key2 = 0, inc = 0;
		foreach (KeyValuePair<int, Region> kvp in regions)
		{
			if (inc == 0)
			{
				inc++;
				key1 = kvp.Key;
			}
			else
				key2 = kvp.Key;
		}

		lock (listLock)
		{
			if (adjancies[key1].Contains(key2))
				return true;

			adjancies[key1].Add(key2);
			adjancies[key2].Add(key1);
			return true;
		}
	}
	return false;
}


Hmm, where to start. How about that comment "True if it was a special case". Yes, because it is obvious what a special case is. Then the whole looping over a collection of two items, with a flag to set two items to specific values (instead of say, asking for the keys of the Dictionary). Oh, and the whole reason for the reported bug is that the indices of key1 and key2 were not checked for being in bounds somewhere prior in the code, which would have saved user trouble from this. Plus, the redundancy of using lists to specify connections, while matching the underlying implementation of data that I was working with, makes things unnecessarily complicated.
GeneralRe: Ugly, ugly, ugly! Pin
AspDotNetDev31-Oct-10 12:29
protectorAspDotNetDev31-Oct-10 12:29 
GeneralRe: Ugly, ugly, ugly! Pin
Lutosław31-Oct-10 14:33
Lutosław31-Oct-10 14:33 
GeneralWhen the CEO becomes a developer I Pin
imagiro29-Oct-10 23:31
imagiro29-Oct-10 23:31 
GeneralRe: When the CEO becomes a developer I Pin
richard_k5-Nov-10 19:27
richard_k5-Nov-10 19:27 
GeneralWell it made me laugh anyway Pin
musefan29-Oct-10 6:33
musefan29-Oct-10 6:33 
GeneralRe: Well it made me laugh anyway Pin
Chris Meech29-Oct-10 6:51
Chris Meech29-Oct-10 6:51 
GeneralRe: Well it made me laugh anyway Pin
Jeroen De Dauw29-Oct-10 10:19
Jeroen De Dauw29-Oct-10 10:19 
GeneralRe: Well it made me laugh anyway PinPopular
Lutosław31-Oct-10 14:26
Lutosław31-Oct-10 14:26 
GeneralRe: Well it made me laugh anyway Pin
musefan2-Nov-10 23:45
musefan2-Nov-10 23:45 
GeneralIt's not the most horrible code but it is pointless Pin
Andy Brummer28-Oct-10 10:36
sitebuilderAndy Brummer28-Oct-10 10:36 
GeneralRe: It's not the most horrible code but it is pointless Pin
Pete O'Hanlon28-Oct-10 12:31
mvePete O'Hanlon28-Oct-10 12:31 
GeneralRe: It's not the most horrible code but it is pointless Pin
Andy Brummer29-Oct-10 1:38
sitebuilderAndy Brummer29-Oct-10 1:38 
GeneralRe: It's not the most horrible code but it is pointless Pin
fjdiewornncalwe28-Oct-10 13:29
professionalfjdiewornncalwe28-Oct-10 13:29 
GeneralRe: It's not the most horrible code but it is pointless Pin
Al_Brown29-Oct-10 0:49
Al_Brown29-Oct-10 0:49 
GeneralRe: It's not the most horrible code but it is pointless Pin
fjdiewornncalwe29-Oct-10 4:07
professionalfjdiewornncalwe29-Oct-10 4:07 
GeneralRe: It's not the most horrible code but it is pointless Pin
QuiJohn29-Oct-10 4:14
QuiJohn29-Oct-10 4:14 
GeneralRe: It's not the most horrible code but it is pointless Pin
richard_k5-Nov-10 19:31
richard_k5-Nov-10 19:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.