The Weekly Source Code 10 - Patterns Considered Harmful October 31, '07 Comments [15] Posted in ASP.NET | Microsoft | Source Code Sponsored By In my new ongoing quest to read source code to be a better developer, I now present the tenth in an infinite number of a weekly series called "The Weekly Source Code." Here's some source I'm reading this week that I enjoyed. Our theme this week is "Patterns Considered Harmful" with examples of source doing things we're "not supposed to do." ÜberUtils - Strings from Brad Vincent. Don't like System.String? Well, spot-weld a bunch of useful stuff onto it with C# 3.0 Extension Methods. Brad starts to talk about how his utils might be Considered Harmful: "Now I know some people might argue that this is extension method abuse, but look at how much more power my strings have...and anything that helps me code quicker and smarter is not abuse in my book - it's smart coding!" Here's just two of his many useful additions you can hardly consider harmful: public static string XOR(string input, string strKey) { if (IsEmpty(input)) return input; string strEncoded = string.Empty; int nKeyIndex = 0; for (int i = 0; i < input.Length; i++) { strEncoded += Convert.ToChar(input[i] ^ strKey[nKeyIndex]); nKeyIndex++; if (nKeyIndex == strKey.Length) nKeyIndex = 0; } return strEncoded; } public static string ToTitleCase(string Input) { return System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(Input); } This item isn't source, but rather a study topic. I saw that Jeff Atwood had a recent post on "Considered Harmful" docs and mentions the seminal GOTO considered harmful paper. Take a free moment and go read the interesting January 2003 thread of discussion between a number of programmers and Linus Torvalds, creator of Linux about Linus's use of GOTO in the Linux Kernel. Why? Here's a teaser from Linus: "No, you've been brainwashed by CS people who thought that Niklaus Wirth (Editor: Author of GOTOs Considered Harmful) actually knew what he was talking about. He didn't. He doesn't have a frigging clue." > I thought Edsger Dijkstra coined the "gotos are evil" bit in his > structured programming push? Yeah, he did, but he's dead, and we shouldn't talk ill of the dead. So these days I can only rant about Niklaus Wirth, who took the "structured programming" thing and enforced it in his languages (Pascal and Modula-2), and thus forced his evil on untold generations of poor CS students who had to learn langauges that weren't actually useful for real work. - Linus Putting everything all on one line. I'll do a separate post on this, but Lee Holmes (author of the Windows PowerShell Cookbook) and I were doing some PowerShell recently, parsing CSV files and did this. Lee doesn't recommend it, but I think it's pretty: Import-CSv File.csv | Select File,Hits | Group { $_.File -replace '/hanselminutes_(\d+).*','$1' } | Select Name,{ ($_.Group | Measure-Object -Sum Hits).Sum } Feel free to send me links to cool source that you find hasn't been given a good read. « November 8th - Seattle/Redmond/Bellevue ... | Blog Home | Parsing CSVs and Poor Man's Web Log Anal... » About Scott Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author. About Newsletter Sponsored By Hosting By