Skip to content

The Weird and The Wonderful

It was the best of code, it was the worst of code. Coding Horrors, Worst Practices, and flashes of brilliance

This category can be followed from the open social web via the handle the-weird-and-the-wonderful@forum.codeproject.com

1.8k Topics 20.7k Posts
  • If Indexing Then Loop

    com question
    4
    0 Votes
    4 Posts
    0 Views
    G
    Boss said to the newby, "take this code and make it run faster." :) Gary
  • Worst security flaws

    security beta-testing question workspace
    18
    0 Votes
    18 Posts
    2 Views
    R
    Camilo Sanchez wrote: we had this ftp in our company that one day appeared full of porn apparently anonymous access to the ftp was enabled Anonymous access to the ftp was enabled? There's an excuse I need to remember. -Richard Hit any user to continue.
  • I just got greeted by this

    php visual-studio com question
    10
    0 Votes
    10 Posts
    0 Views
    L
    You clearly forgot to litter the methods with Debug.Assert statements. Eg: result = true; Debug.Assert(result == true); You have to remember being very wary of the compiler, it has a mind of its own. xacc.ide IronScheme - 1.0 RC 1 - out now! ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition
  • Return of an old friend

    tutorial announcement
    7
    0 Votes
    7 Posts
    0 Views
    R
    Rob Grainger wrote: but as he retired a while ago... Let that not be an obstacle. A banana in a tailpipe can give a guy many days of debugging fun. Childish? perhaps, but you'll feel better. -Rd Hit any user to continue.
  • False selection...

    java game-dev regex learning
    62
    0 Votes
    62 Posts
    8 Views
    _
    The 2 vote was another mistake of mine, sorry for that. I wanted to go to page 2 to see the original post, clicked the vote 2 instead, and forgot to make the correct vote to your post. I've just corrected it with the vote it really deserves, a 5. I know my final logic does the same as the original but is slower. It is obvious. And it is much clearer, and this is also obvious. The sample I give just before does the same also, and is faster. Both of them improve the original in readability, and the first one also improves it in speed. If you had to manage a team of developers, some of them newcomers with very little experience, tell me, having the original code and the two samples I am giving, which one would you choose? I would choose the last one, though I know it is slower, but I also know that the overhead is just negligible in this case, becouse this operation will not be used over and over again within de context of a long and complex batch process. I don't mind to have several "return" in the same method... if it improves readability and/or performance. In the case presented here, it does not improve readablity neither performance, so that is the reason why I consider it a horror. Nobody is obligated to agree, I am just sharing my point of view. Edit Sorry again, I was forgetting the las part. The implementation for bitdepth and refreshrate is given just before, but like you wonder how they should be, I will give some extra clues: return mode1.getWidth() == mode2.getWidth() && mode1.getHeight() == mode2.getHeight() && // This checks sizes (mode1.getBitDepth() == mode2.getBitDepth() || // These three lines mode1.getBitDepth() == DisplayMode.BIT_DEPTH_MULTI || // are checking if mode2.getBitDepth() == DisplayMode.BIT_DEPTH_MULTI) // bit depths match && (mode1.getRefreshRate() == mode2.getRefreshRate() || // These three lines mode1.getRefreshRate() == DisplayMode.REFRESH_RATE_UNKNOWN || // are checking if mode2.getRefreshRate() == DisplayMode.REFRESH_RATE_UNKNOWN); // refresh rates match Thank you modified on Tuesday, October 19, 2010 9:28 AM
  • Dating

    19
    0 Votes
    19 Posts
    0 Views
    P
    DateTime dt = new DateTime(year, month, day); return (dt <= dtEnd & dt >= dtStart); How about this one? Enclosing it in try catch will cop with invalid dates too.
  • Unhandled exception message

    data-structures debugging help
    6
    0 Votes
    6 Posts
    0 Views
    P
    That's awesome. I should have tried those messages in my college projects... :laugh:
  • Some more pain (the non-local local)

    php visual-studio com regex question
    4
    0 Votes
    4 Posts
    0 Views
    B
    I don't know who their teacher was, but I have worked with several folk who must have and the same teacher! :laugh: Just because the code works, it doesn't mean that it is good code.
  • vb 6, ep. 3

    help question career
    8
    0 Votes
    8 Posts
    1 Views
    _
    looooooooooooooooooooooooooooool Oh my god!!! Two questions come to my mind: How many times did you come and go from designer view to code view and vice versa? How many mouses did you wreck?
  • Obj-C string construction

    learning swift data-structures
    4
    0 Votes
    4 Posts
    0 Views
    L
    The real horror here is that you don't check for the possibility of buffer overrun.
  • Something's out of round here

    c++
    3
    0 Votes
    3 Posts
    0 Views
    B
    The C++ version is easier to understand at the first view :P But yes, both are the same horror :D Horror code is one of the most amusing things in the world if you see it, but the biggest hell if you have to work with it.
  • Clever Convert. Really?

    help question
    6
    0 Votes
    6 Posts
    0 Views
    J
    Coming from a C++ background, I constantly have to remind myself about the ?? operator. One of these days, I will type it before ReSharper reminds me that my ?: expression can be converted into an equivalent ?? expression. :) -- Kein Mitleid Für Die Mehrheit
  • Beware while using Japanese language

    23
    0 Votes
    23 Posts
    0 Views
    M
    dawmail333 wrote: I wonder what proportion of successful programmers are self-taught? Moi. ;) Marc
  • ModusOperandi

    6
    0 Votes
    6 Posts
    0 Views
    G
    Richard A. Dalton wrote: So, in an interview for a programming job when asked what languages he knows, the correct answer would be..."I've used Latin, but I'm no expert". And if I were the interviewer, I would extend my hand to the prospect and say with a smile: Noli me vocare. Ego te vocabo.
  • Take a Nap

    ruby data-structures
    10
    0 Votes
    10 Posts
    0 Views
    P
    [Showing my age!] I remember back when the PC AT came out, with a (WOW!) 80286 clocked at 6 Mhz. You had to write two NOPs after every OUT instruction, I think it was. Otherwise the I/O bus got its tits in a tangle. Software rusts. Simon Stephenson, ca 1994.
  • Whew

    debugging
    9
    0 Votes
    9 Posts
    0 Views
    R
    Gary Wheeler wrote: At which point, you take the vendor outside the building, put two bullets in his head, and leave his body mounted on a pike outside the castle walls as a warning to others. Actually that particular project I had no problem with the Vendor. I was young Naive, what did I know? I'll say this. Compared to experiences I've had and am still having with vendors, that project was a cakewalk. When you've debugged a vendor's Javascript files you start to understand that a dodgy error message is no biggie. There's nothing quite like javascript files which seem to have had all whitespace sucked out of them, presumably to stop people stealing some of the most horrible code ever written (why would anyone want to). -Rd
  • Which one is better [modified]

    11
    0 Votes
    11 Posts
    0 Views
    E
    Maybe the coding horror is premature optimisation? Unless the programmer has determined that this is a bottleneck, the better one is the one that expresses the logic most clearly (the one without the extra test, for my money), not the one with the lowest "cost". And if the programmer has determined that this is a bottleneck, they can use the same tools to find out which is faster.
  • Redundant Coding: The new paradigm!

    question learning
    22
    0 Votes
    22 Posts
    3 Views
    B
    One place I worked had five (count'em...5!) different memory management routines because "Microsoft's doesn't work." Really? Could it be you just don't know how to use it? Because that's going to be a big surprise to the millions of other programmers using it. But hey, when management wanted my opinion they told it to me. Psychosis at 10 Film at 11
  • Old time horror

    performance
    19
    0 Votes
    19 Posts
    2 Views
    B
    I don't mind longish names if they are actually descriptive and useful. I really don't like names (short or long) that serve to obfuscate the code. Just because the code works, it doesn't mean that it is good code.
  • How to read a file completely?

    ruby debugging help tutorial question
    18
    0 Votes
    18 Posts
    0 Views
    L
    I can't tell from what is shown. Is file a string, and BDTline opening said file? or is file some kind of object (say a StreamReader), that has the file opened earlier on, and parses/returns a single line? :) Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.