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
  • Subclassing

    com question
    10
    0 Votes
    10 Posts
    0 Views
    L
    All calls to reflection are slow in general. In such case, I prefer adding an additional, "constant", enumerated property "type". It is much faster to do a single integer comparison than using the reflection to determine an object's type (which is done in both "is" and "as" operators). enum MessageTypes { Command, Reply, Subscription } class Message { public abstract MessageTypes MessageType { get; }; (...) } if (msg.MessageType == MessageTypes.Command) { } else if (...) Greetings - Jacek
  • Class with comments that say "Do not use"

    visual-studio
    16
    0 Votes
    16 Posts
    0 Views
    G
    Don't stuff beans up your nose[^]
  • SQL Zoolander Trimming

    database com
    4
    0 Votes
    4 Posts
    0 Views
    D
    Almost certainly. If you are doing a search, then LTRIM(my_col) LIKE 'A%' may be much slower than RTRIM(my_col) LIKE 'A%'. That's because the second query can use an index on my_col, whereas the first one can't. So, from there someone might wrongly conclude that the LTRIM operation itself is slower than RTRIM, and avoid using LTRIM in all cases. It's not the LTRIM operation per se that's a problem, it's the fact that it precludes the use of indexes during searches.
  • VC 2003 & 2005 compilo bug...

    c++ debugging help question
    3
    0 Votes
    3 Posts
    0 Views
    K
    really it is the good old trigraphs ;) i dont know if they abandoned them in C++0X, but at THAT time, they WERE useful nowadays, they are annoying :< look at this[^] for example =D
  • VB and an SqlDataSource

    question
    6
    0 Votes
    6 Posts
    0 Views
    T
    You can use GEL to hold your hairs :)
  • Beginners "luck"

    c++ data-structures oop performance learning
    7
    0 Votes
    7 Posts
    0 Views
    N
    I almost read it as "Beginners Suck" ;) Two heads are better than one.
  • The Illusion of a Choice

    csharp ruby
    13
    0 Votes
    13 Posts
    0 Views
    S
    dojohansen wrote: And I thought the compiler optimization would have caught that one I have no idea what the instruction timings would be like on mega-pipelined processors, but certainly on older machines one could test whether a value was less than zero (i.e. had the high bit set) more quickly than one could test for its being in a particular range. The two-part test could be faster for the case where the value is positive, even if it would be slower for the case where it is negative. If the positive case will occur much more often, eliminating the split test will make the code smaller but could cause it to run more slowly.
  • Encoding IP addresses

    sysadmin
    5
    0 Votes
    5 Posts
    0 Views
    S
    Is there any requirement that any particular octet of an IP address always be non-zero? I would think that if e.g. using a subnet mask of 255.255.254.0, an IP address of 192.168.1.0 or 192.168.0.3 would be perfectly valid.
  • That's an useless class

    6
    0 Votes
    6 Posts
    1 Views
    D
    This is the best part of the class doud wrote: public static string GetGuid() { return Guid.NewGuid().ToString(); } Maybe rename the class to DateTimeExtendedGetNewGuidAsString 10 PRINT "Software is hard. - D. Knuth" 20 GOTO 10
  • 0 Votes
    9 Posts
    0 Views
    N
    looks like VB reverse engineered code or generated using some tool
  • 0 Votes
    8 Posts
    2 Views
    J
    Please tell which banks these were for so I can bank elsewhere! :cool:
  • The next big paradigm shift in database design

    database mysql com design
    18
    0 Votes
    18 Posts
    0 Views
    D
    I can second that. I am using IE7 and it's a grey background, black text. Very hard to read. The code snippets show up OK, with a white background. EDIT: Just tried it in FF3 and it's a white background. In IE7 there is a background image showing which is sort of a dark greyish colour. In FF3 that image is not displayed, so you only see the default browser back colour (i.e. a plain white background). It looks like some problem with the CSS file that defines the class for the box where you are showing your text. IE likes it, FF doesn't. Welcome to the world of cross-browser support.
  • Get the length of the path (not the filename)

    6
    0 Votes
    6 Posts
    1 Views
    M
    Ohhhh, I've known many developers that write code harder because they think it looks cool. Unfortunately I've known WAY too many especially this fat pig that preached about how website development is very difficult; he then went on to develop a very difficult website. Mike's code was soooooooo bad that they have to run to instances of the website on the same machine to properly test it....according to him. He was also complaining about how hard it was to test his code after his iterative code went more than 30 levels deep.
  • How to convert minutes into milliseconds...

    csharp ai-coding tutorial question
    8
    0 Votes
    8 Posts
    0 Views
    A
    Nice little collection of useful DateTime snippets. I added that to my bookmarks. Thanks. :)
  • Ever heard of casting?

    question
    33
    0 Votes
    33 Posts
    2 Views
    A
    Yes! I'm sorry I could only give you one five. When the problem domain calls for decimal calculations rather than floating point, casting from a floating point type would be a greater horror. Please do not read this signature.
  • Browser Support Check

    javascript ruby html business help
    3
    0 Votes
    3 Posts
    0 Views
    C
    Wow, talk about how times change. I bet I could dig up a curses lib file that does the same thing for DEC VT-xxx terminals. :) Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
  • How to split a string the hard way (VB6)

    data-structures tutorial
    6
    0 Votes
    6 Posts
    0 Views
    P
    Development team answer: This is not a bug. All key values must be uppercase. We are simplifying the application so services and Services are no more supported, avoiding further errors. In fact, the check is now: If len(vkeys[lval, 0]) = 8 and Mid(lvkeys[lval, 0], 0, 1) = "S" and Mid(lvkeys[lval, 0], 1, 1) = "E" ... and so on. :laugh: (Note, I started to write this at the same time of the last post... I think our development team is having problems of communication... who the hell tought we must support other keywords?? :doh: ).
  • Date sting formatting, the easy way.

    ruby question career
    10
    0 Votes
    10 Posts
    0 Views
    T
    Epic! Especially the sb.Append('_');
  • Put your right paren in, take your right paren out...

    database
    6
    0 Votes
    6 Posts
    1 Views
    J
    The other users got this right of course...bad and incorrect use of parens but jeez dont you just hate this style of ASP coding! I havent done ASP is years now but isnt this so much easier to look at that than trash: <table width="1000" cellspacing="0" cellpadding="0" class="style1"> <tr> <td width="40"><% = rsSearch("WKCTR") %></td> <td width="40"><% = rsSearch("START") %></td> <td width="40"><% = rsSearch("FINISH") %></td> <td width="40"><% = rsSearch("JOBNO") %></td> </tr> </table>
  • Now that's a first [modified]

    8
    0 Votes
    8 Posts
    0 Views
    A
    You just don't understand. If the variable was named count you would have a point. Here, the programmer was helping the poor computer with its communications skill. Hence naming the variable that the computer uses to count from its own perspective - "I Count" Please do not read this signature.