Click here to Skip to main content
15,892,298 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: I understand that we shouldn't duplicate code, but... Pin
Johann Gerell17-Apr-12 21:35
Johann Gerell17-Apr-12 21:35 
GeneralRe: I understand that we shouldn't duplicate code, but... Pin
Bruce Patin18-Apr-12 4:20
Bruce Patin18-Apr-12 4:20 
GeneralRe: I understand that we shouldn't duplicate code, but... Pin
ClockMeister18-Apr-12 2:17
professionalClockMeister18-Apr-12 2:17 
GeneralRe: I understand that we shouldn't duplicate code, but... Pin
alcexhim18-Apr-12 5:50
alcexhim18-Apr-12 5:50 
GeneralRe: I understand that we shouldn't duplicate code, but... Pin
ClockMeister18-Apr-12 6:27
professionalClockMeister18-Apr-12 6:27 
GeneralRe: I understand that we shouldn't duplicate code, but... Pin
Robert Rohde18-Apr-12 11:04
Robert Rohde18-Apr-12 11:04 
GeneralRe: I understand that we shouldn't duplicate code, but... Pin
ClockMeister18-Apr-12 11:27
professionalClockMeister18-Apr-12 11:27 
GeneralRe: I understand that we shouldn't duplicate code, but... Pin
Richard Deeming18-Apr-12 9:02
mveRichard Deeming18-Apr-12 9:02 
Nope - the original code from the framework reference source is:

C#
// From System.Web.Util.HashCodeCombiner 
internal static int CombineHashCodes(int h1, int h2) { 
    return (((h1 << 5) + h1) ^ h2);
} 

internal static int CombineHashCodes(int h1, int h2, int h3) {
    return CombineHashCodes(CombineHashCodes(h1, h2), h3);
} 

internal static int CombineHashCodes(int h1, int h2, int h3, int h4) { 
    return CombineHashCodes(CombineHashCodes(h1, h2), CombineHashCodes(h3, h4)); 
}

internal static int CombineHashCodes(int h1, int h2, int h3, int h4, int h5) {
    return CombineHashCodes(CombineHashCodes(h1, h2, h3, h4), h5);
}

internal static int CombineHashCodes(int h1, int h2, int h3, int h4, int h5, int h6) {
    return CombineHashCodes(CombineHashCodes(h1, h2, h3, h4), CombineHashCodes(h5, h6)); 
} 

internal static int CombineHashCodes(int h1, int h2, int h3, int h4, int h5, int h6, int h7) { 
    return CombineHashCodes(CombineHashCodes(h1, h2, h3, h4), CombineHashCodes(h5, h6, h7));
}

internal static int CombineHashCodes(int h1, int h2, int h3, int h4, int h5, int h6, int h7, int h8) { 
    return CombineHashCodes(CombineHashCodes(h1, h2, h3, h4), CombineHashCodes(h5, h6, h7, h8));
}


The original code from System.Web.Util.HashCodeCombiner is:
C#
internal static int CombineHashCodes(int h1, int h2) { 
    return ((h1 << 5) + h1) ^ h2;
} 

internal static int CombineHashCodes(int h1, int h2, int h3) {
    return CombineHashCodes(CombineHashCodes(h1, h2), h3);
} 

internal static int CombineHashCodes(int h1, int h2, int h3, int h4) { 
    return CombineHashCodes(CombineHashCodes(h1, h2), CombineHashCodes(h3, h4)); 
}

internal static int CombineHashCodes(int h1, int h2, int h3, int h4, int h5) {
    return CombineHashCodes(CombineHashCodes(h1, h2, h3, h4), h5);
}


Good job they put all those helpful comments in to explain their choice! Poke tongue | ;-P



"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


GeneralRe: I understand that we shouldn't duplicate code, but... Pin
ClockMeister18-Apr-12 9:50
professionalClockMeister18-Apr-12 9:50 
GeneralRe: I understand that we shouldn't duplicate code, but... Pin
TRK318-Apr-12 6:50
TRK318-Apr-12 6:50 
GeneralYou know you've been staring at code for too long when you write this test. Pin
Pete O'Hanlon16-Apr-12 0:38
mvePete O'Hanlon16-Apr-12 0:38 
GeneralRe: You know you've been staring at code for too long when you write this test. Pin
Brisingr Aerowing16-Apr-12 1:40
professionalBrisingr Aerowing16-Apr-12 1:40 
GeneralRe: You know you've been staring at code for too long when you write this test. Pin
CDP180216-Apr-12 2:02
CDP180216-Apr-12 2:02 
GeneralRe: You know you've been staring at code for too long when you write this test. Pin
Brisingr Aerowing16-Apr-12 4:53
professionalBrisingr Aerowing16-Apr-12 4:53 
GeneralRe: You know you've been staring at code for too long when you write this test. Pin
Pete O'Hanlon16-Apr-12 5:02
mvePete O'Hanlon16-Apr-12 5:02 
GeneralRe: You know you've been staring at code for too long when you write this test. Pin
Brisingr Aerowing16-Apr-12 5:18
professionalBrisingr Aerowing16-Apr-12 5:18 
GeneralSQL Server Management Studio's ordered view Pin
Bernhard Hiller11-Apr-12 4:39
Bernhard Hiller11-Apr-12 4:39 
GeneralRe: SQL Server Management Studio's ordered view PinPopular
PIEBALDconsult11-Apr-12 5:44
mvePIEBALDconsult11-Apr-12 5:44 
GeneralRe: SQL Server Management Studio's ordered view Pin
Chris Meech11-Apr-12 5:53
Chris Meech11-Apr-12 5:53 
GeneralRe: SQL Server Management Studio's ordered view Pin
robocodeboy13-Apr-12 4:43
robocodeboy13-Apr-12 4:43 
GeneralFormat Date PinPopular
Bernhard Hiller1-Apr-12 23:41
Bernhard Hiller1-Apr-12 23:41 
GeneralRe: Format Date Pin
PIEBALDconsult2-Apr-12 9:23
mvePIEBALDconsult2-Apr-12 9:23 
AnswerRe: Format Date Pin
Luc Pattyn2-Apr-12 9:55
sitebuilderLuc Pattyn2-Apr-12 9:55 
GeneralRe: Format Date PinPopular
ekolis2-Apr-12 11:34
ekolis2-Apr-12 11:34 
GeneralRe: Format Date Pin
Bernhard Hiller2-Apr-12 21:10
Bernhard Hiller2-Apr-12 21:10 

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.