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
  • Cargo cult programming for thread safe variable access?

    question html discussion
    10
    0 Votes
    10 Posts
    0 Views
    E
    LOL, some people think randomly sprinkling locks into the code will make it thread safe ;)
  • top this

    35
    0 Votes
    35 Posts
    1 Views
    B
    if someone start to create a role play game like this: int enemyHP = 10; int playerStrength = 3; \_TakeDamage: switch (playerStrength) { case 1: if (enemyHP == 1) { goto \_EnemyDeath; } else { enemyHP = enemyHP - 1; } case 2: if (enemyHP == 2) { goto \_EnemyDeath; } else { enemyHP = enemyHP - 2; } case 3: if (enemyHP == 3) { goto \_EnemyDeath; } else { enemyHP = enemyHP - 3; } case 4: if (enemyHP == 4) { goto \_EnemyDeath; } else { enemyHP = enemyHP - 4; } case 5: if (enemyHP == 5) { goto \_EnemyDeath; } else { enemyHP = enemyHP - 5; } //case etc.: } \_EnemyDeath: Console.WriteLine("Enemy is death!"); Then there is no hope for the game... xD This is really untopable!
  • Opinions

    data-structures question discussion lounge learning
    24
    0 Votes
    24 Posts
    0 Views
    E
    I think you've got way too much time on your hands :laugh: There is only one satisfying way to boot a computer.
  • IE Invisible DIV Bug

    html css com architecture help
    7
    0 Votes
    7 Posts
    1 Views
    A
    Oh, do you mean change the color of the ORIGINAL image, rather than the image behind it? As I explained in the post you replied to, that would be extra work for the designers and, due to JPEG compression, would be troublesome. [Forum Guidelines]
  • Clustering... The hard way!

    8
    0 Votes
    8 Posts
    1 Views
    J
    My God. It looks like some of the old stuff lying around at my company.
  • Are you sure that it's not null?

    question
    7
    0 Votes
    7 Posts
    1 Views
    L
    "developer redundancy" :thumbsup: Greetings - Jacek
  • Superman if-clause

    question
    12
    0 Votes
    12 Posts
    1 Views
    K
    we cant know! we cant judge.its windows afterall :D d'Oh!
  • YAVH - Yet another VBA horror

    database help career
    8
    0 Votes
    8 Posts
    1 Views
    R
    Except that I have to maintain and enhance this code. Refactoring code for elegance is not wasted time - every future maintainer will appreciate your effort.
  • How to Use Member Variables

    tutorial
    23
    0 Votes
    23 Posts
    1 Views
    S
    I think the "Create New Method" refactoring tool provided by VS automatically makes a method static if the code you selected to be in the body of the method did not use any non-static member variables. I have occasionally used this "pattern" if IsFirst contains behavior that is generally useful. Regards Senthil _____________________________ My Home Page |My Blog | My Articles | My Flickr | WinMacro
  • JavaScript Conditional

    javascript question discussion
    13
    0 Votes
    13 Posts
    0 Views
    W
    I wanted to use the ternary operator there, too; then I thought of the future case of adding a third "accion" and decided to leave an obvious ability to add an "else if" condition at the top. Honestly Illustrated <Pretentious> Raid tha manyuhl. :E <Pretentious> Aw raid eh own mah meaxbile. :E
  • String.Format???

    ruby database help question learning
    54
    0 Votes
    54 Posts
    2 Views
    J
    A for(each) loop to create the parameters and another to load the values works pretty well. Assuming the list of values is in some form of collection.
  • try-catch code convention [modified]

    career
    30
    0 Votes
    30 Posts
    1 Views
    H
    They've implemented the most efficient source of Mystery Errors ever devised. Before .NET 4.0, object Universe = NULL;
  • Go to Hell

    csharp com sales tutorial question
    10
    0 Votes
    10 Posts
    1 Views
    I
    Afraid not, those numbers are correct. ....I'll bring the mop!:~ nothing
  • Logical genius!

    code-review
    12
    0 Votes
    12 Posts
    1 Views
    C
    I know this is an old thread, but being the pedant I am I can't resist. None of the examples of the 'right' way to do it are optimal. Remember that m_bUsed is already defined to be a bool. Also notice iHandle is an int, which could be negative. typedef struct { // Lot of stuffs.. bool m_bUsed; } CONFIG; #define MAX_CFG 10 static CONFIG g_vConfigurations[MAX_CFG]; ... bool IsUsed ( int iHandle ) { if (iHandle >= 0 && iHandle < MAX_CFG) return g_vConfigurations[iHandle ].m_bUsed; return false; }
  • But...wait, what?

    question
    11
    0 Votes
    11 Posts
    1 Views
    H
    I try to remember to do a Find All Usages in Resharper (now in VS2010) to make sure that code inside the class doesn't use the property, only the backing field. Keeps me from writing code like that. It goes without saying that any code outside the class shouldn't even have any idea what side-effects might be happening in a public setter. Before .NET 4.0, object Universe = NULL;
  • Size Matters Take Two

    performance
    10
    0 Votes
    10 Posts
    0 Views
    H
    In my day, we had to whistle into a modem! Before .NET 4.0, object Universe = NULL;
  • useless...

    8
    0 Votes
    8 Posts
    0 Views
    H
    J4amieC wrote: I can't tell you how many times ive seen ToString() called on a string type. Its a typical newbie mistake, the lack of understanding of data types. To true. Great for catching newbies when conducting job interviews. Luckily though, the framework protects them from themselves: // From mscorlib.dll public override string ToString() { return this; } Not perfect but at least there's not a whole redundant complex conversion of some kind taking place... Before .NET 4.0, object Universe = NULL;
  • Stupid Naming Consequences with LINQ

    csharp database visual-studio linq question
    8
    0 Votes
    8 Posts
    0 Views
    H
    _beauw_ wrote: but it is not the place of the Object/Relational Designer to enforce this. That's why you can disable it: Model IDE->Properties->Pluralize New Objects Please note that this is a pure religious issue: In my case, all my tables are singular names(Login, Person, Role, etc). So I would have had a table named "System" and without the pluralization on, I would have had to map them differently to avoid this collision. You can map the tables any way you like in EF4. Fact is, you'll always run the risk of name collisions with any code generation. Before .NET 4.0, object Universe = NULL;
  • A whole day wasted on one stored procedure

    help database sharepoint tutorial question
    5
    0 Votes
    5 Posts
    0 Views
    P
    ChrisC(@ncmail) wrote: will often peform worse Test it. ChrisC(@ncmail) wrote: the work involved to do the join is greater Though that work may be beneficial in some cases.
  • Tidying up

    10
    0 Votes
    10 Posts
    0 Views
    K
    He may be the best bugger of the world ;) Don't forget to Click on [Vote] and [Good Answer] on the posts that helped you. Regards - Kunal Chowdhury | Software Developer | Chennai | India | My Blog | My Tweets | Silverlight Tutorial