35

Actual code

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

I'm speechless

Comments
  • 5
    Some people do that style of empty if to make later refactoring obvious. I don't agree, but I've seen it before.
  • 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?
  • 7
    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
    @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
  • 1
    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