Click here to Skip to main content

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, embarrasing 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.

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page  Show 
GeneralRe: Why String.Format?memberjhunley15 Jun '12 - 17:38 
I've been maintaining a C++ codebase for several years now that has this type of thing all through it:   if (someErrorCondition) { char *msg = "Error 404\n"; char s[100]; sprintf(s, "%s", msg); PrintErrorMessage(s); }   as opposed to just:   if...
GeneralRe: Why String.Format?memberJackDingler19 Jun '12 - 9:53 
I know the guy who wrote those... Gotta be the same guy....
GeneralRe: Why String.Format?memberRobCroll17 Jun '12 - 5:25 
Was the code ported from C++? I haven't seen this one before but definitely seen stuff like this when using a tool to convert from one language to another. "You get that on the big jobs."
GeneralRe: Why String.Format?memberFireDog3126218 Jun '12 - 3:20 
This was newly written code under an existing ASP.NET C# code base. It was written by a "supposedly" senior developer. No matter where you go, there you are...~?~
JokeRe: Why String.Format?memberRahul Rajat Singh26 Jun '12 - 1:01 
Tell the original developer to use this   StringBuilder sb = new StringBuilder(); sb.Append(string.empty); sb.Append(funcThatReturnsAString()); sb.Append(string.empty);   value = sb.ToString();   Tell him this is the standard way of doing this kind of stuff Every now and...
GeneralTry Fail...memberVallarasuS15 Jun '12 - 2:22 
Guess Microsoft failed to mention in XML documentation TryPare != CanParse...   string[] rgb = values.Split(','); if (rgb.Length == 3) { byte r, g, b; // <- Why is this here anyway?! if (byte.TryParse(rgb[0], out r)...
GeneralRe: Try Fail...memberCDP180215 Jun '12 - 2:40 
r, g and b are declared because you can't call TryParse() without providing an out parameter for the result. Still, a CanParse() method would not be very much faster or more efficient than misusing TryParse() for that purpose. Anyway, I have seen much code where some rookie tried to put everything into strings (instead of proper types) and then was trying to parse (no pun intended) all over the code.
At least artificial intelligence already is superior to natural stupidity


GeneralRe: Try Fail...memberBobJanova15 Jun '12 - 4:53 
You're missing the point, I think: after calling TryParse, you already have the values in the r, g and b variables, so TRWTF is why the author then calls Parse again inside the if.
GeneralRe: Try Fail...memberCDP180215 Jun '12 - 5:08 
True, but that has also become a common mistake. Many people are not used to having to use the CPU sparingly. They (edit: the CPUs, not the people ) are now powerful enough to forgive a certain amount of wastefulness. Depending on how often this code here is executed, an optimization may make...
GeneralRe: Try Fail...memberJulien Villers15 Jun '12 - 3:33 
Is it really trying to parse three times rgb[0]?   Then, it's an even greater WTF... 'As programmers go, I'm fairly social. Which still means I'm a borderline sociopath by normal standards.' Jeff Atwood   'I'm French! Why do you think I've got this outrrrrageous accent?' Monty...
GeneralRe: Try Fail...memberVallarasuS15 Jun '12 - 5:15 
Good Spot Julien, To be honest, All I felt wrong about this piece of code is   #1. This can be done with ColorConverter.ConvertFromString(string)or With TypeDescriptor.GetConverter... #2. The author invokes try parse twice, first in the predicate then within the if block   I...
GeneralRe: Try Fail...memberJulien Villers15 Jun '12 - 5:18 
Of course you are right, if the String is a standard format, ie from serialization or sanitized user input, you should use the standard parser. If not, a TryParse done right would be the way to go. 'As programmers go, I'm fairly social. Which still means I'm a borderline sociopath by normal...
GeneralRe: Try Fail...memberRichard Deeming18 Jun '12 - 10:18 
VallarasuS wrote:This can be done with ColorConverter.ConvertFromString   Or it could, if that class didn't have a nasty bug in it: var converter = new ColorConverter(); Color color = converter.ConvertFromString("#XXXa"); Console.WriteLine(color);   Given this code, you might...
GeneralRe: Try Fail...memberKP Lee18 Jun '12 - 21:55 
That's cute, set up values, don't use them and then blow up when the if test passes and rgb[1] == "G"   Well, if it does return true, you know you "CanParse" rgb[0] There are a lot of things I see in code that don't make sense.   Interesting, "int i = 350; byte b = (byte)i;"...
GeneralWhy use String.Concat() ?memberCoperNick13 Jun '12 - 3:04 
value = String.Concat(value, intValue.ToString(), ".");   logBuilder = String.Concat("some long text", "some long text. ");   String errorMessage = String.Concat("Long text, exception: ", ex.ToString()); Find all "String.Concat", Subfolders, Find Results...
GeneralRe: Why use String.Concat() ?memberCoperNick13 Jun '12 - 3:08 
And this is the best: String errorMessage = String.Concat(".... packet is fail, exception: ", ex.ToString()); SomeClass.someMember.Error(String.Concat(errorMessage));
GeneralRe: Why use String.Concat() ?members_mon13 Jun '12 - 5:59 
String.Concat("Someone has fallen in love with", "String.Concat"); (yes|no|maybe)*
GeneralRe: Why use String.Concat() ?memberleppie14 Jun '12 - 1:55 
I think I have spotted this coder in the wild!   http://stackoverflow.com/questions/11032394/substring-not-working-as-expected-if-length-greater-than-length-of-string[^] IronScheme ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x)))
GeneralRe: Why use String.Concat() ?memberZac Greve14 Jun '12 - 2:12 
That has to be him! public class SysAdmin : Employee {   public override void DoWork(IWorkItem workItem) { if (workItem.User.Type == UserType.NoLearn){ throw new NoIWillNotFixYourComputerException(new Luser(workItem.User)); }else{ ...
GeneralRe: Why use String.Concat() ?memberFireDog3126218 Jun '12 - 3:26 
This is just as bad as my example of String.Format. No matter where you go, there you are...~?~
GeneralRe: Why use String.Concat() ?memberKP Lee18 Jun '12 - 22:59 
If you've read anything about strings, you must have read that you should use StringBuilder instead. "some text" + "some more" + " text" is expensive. I would guess Concat gives you a performance boost similar to StringBuilder, but limited to strings. I have to admit that appending each value...
GeneralWhy on earth? [modified]memberleppie13 Jun '12 - 0:07 
Would someone do this:   public IEnumerable<TrackingTagSpan<T>> GetTaggedSpans(SnapshotSpan span) { IList<TrackingTagSpan<T>> source = new List<TrackingTagSpan<T>>(this._trackingTagSpans); // this lock (this.mutex) { source = new...
GeneralRe: Why on earth?memberSentenryu13 Jun '12 - 0:25 
This guy had his head full of coffee (or other drugs, can't say exactly)   Maybe the code where longer before and was shortened to this I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p)
GeneralRe: Why on earth?memberVitaly Tomilov14 Jun '12 - 1:30 
Would a simple error be a ground-breaking concept for you?
QuestionRe: Why on earth?memberleppie14 Jun '12 - 1:33 
Vitaly Tomilov wrote:Would a simple error be a ground-breaking concept for you? What is that suppose to mean? IronScheme ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x)))

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


Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 18 May 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid