35

Actual code

if (dict.ContainsKey(key))
{
//do nothing
}
else
{
dict.Add(key, value);
}

I'm speechless

Comments
  • 6
    Some people do that style of empty if to make later refactoring obvious. I don't agree, but I've seen it before.
  • 4
    That is the worst example of speechless making code I have ever seen.

    It's clean and obvious what it does. Yes it could be better but it could be a whole lit worse. And it even has comments. Bonus.
  • 6
    I find it hard to classify the above as "clean" when the following would have done the same thing:

    if (!dict.ContainsKey(key)
    {
    dict.Add(key, value);
    }

    The comment is useless, the if statmeent is renundant and it uses twice as many lines.
  • 4
    @codedoge if you can't get a simple if-else statement right, what should I excpect for problems requiring more complex solutions?
  • 8
    Biggest no no for me is the curly braces on new lines.
  • 0
    @okkimus I prefer to use different styles depending on the popular conventions of the language
  • 0
    @codedoge well if that leaves you speechless you obviously don't get out much
  • 0
    @okkimus I find C# code with opening bracket on the same line just as ugly as I would find curlies on new lines when I read JS
  • 0
    @Jonnyforgotten Meh, It's just the last thing in a long line of ridiculous code snippets I've been stumbling upon in the project.
  • 0
    @Jonnyforgotten What irritates it's me is that the cleaner solution is even easier and more compact to write
  • 2
    I don't think code like that gets written, it has probably evolved into its current state. It possibly started off with "oh no my key exists, throw an exception", then they realised an exception was over kill, so the replaced it with a comment rather than changing it to the code you suggested.
  • 2
    Of course the comment should be
    // NOP
    https://en.wikipedia.org/wiki/NOP

    seen it often enough in my career, some companies refuse the not-operator in if clauses because it can be "overseen" that quickly
  • 2
    I have seen this a few times as well haha
  • 0
  • 0
    🎵🎶🎵
    And i know is time to go home
    @stevemk14ebr
Add Comment