• Darren (unregistered)

    That's just an example of defensive programming, protecting about something changing in the time between those two lines executing...

    Or, it's the digital equivalent of triple checking that the door is locked when you leave the house.

  • (nodebb)

    When coding Java, you need to be extra sure that there's not a null pointer exception.

    Addendum 2024-10-10 06:58: In all seriousness, I think the code should have looked like this:

    if(this.idtoservice != null)
    {
      if(this.idtoservice.Common != null)
      {
        if(this.idtoservice.Common.Security != null)
        {
          sOwner = this.idtoservice.Common.Security.Owner;
        }
      }
    }
    

    Addendum 2024-10-10 07:06: For those interested how the code would like in C#:

    owner = _idtoService?.Common?.Security?.Owner;
    
  • (nodebb)

    For a moment I thought it wasn't IDTOservice but IDIOTservice.

  • Naomi (unregistered) in reply to MaxiTB

    This could be either Java or C#, but I think C# is more likely:

    • Java's naming conventions reserve UpperCamelCase for types, while C# also uses it for methods, properties, and namespaces; the names are conventional in C# but not in Java.
    • Java doesn't have C#'s properties (we use accessor methods, and I'd rather not get into an argument about the pros and cons until I'm a little more awake), so .Common, .Security, and .Owner would have to be direct field access, which is a bad idea in either language. In C#, they'd be properties.

    tl;dr if this were Java, I'd expect to see this.idtoservice.getCommon().getSecurity().getOwner(), but I'd expect to see it written as-is in C#, so I think it's C#.

    (Also, the stereotype that one must null-check every forking thing in Java is... only very slightly true, in my experience.)

  • Wtf Coward (unregistered)

    For a good WTF I like my property getters to have side-effects.

  • (nodebb) in reply to Naomi

    Yeah, there have been instances in the past where the editing of the code sometimes made it really hard to tell. It would be nice to actually know which language we are talking about because especially in Java there's a lot that would be considered an anti-pattern in C# or .net in general.

    But you are correct, if it were Java it SHOULD have been getters and it SHOULDN'T be PascalCased fields.

    So it's two SHOULDs against two SHOULDs... I guess we will never know the truth haha.

  • Dr, Pepper (unregistered)

    A good code review process would catch this. If the leadership are technical people, they should buy into this easily. I can't tell you how many stupid mistakes I've made that were caught by someone else just looking at my code; and how many more mistakes were caught because I did a once-over on the code because I knew someone else would do a review of it.

  • (nodebb)

    ID(10)T-oh-I-see...

  • Duke of New York (unregistered)

    Someone give the CEO a bump, he's stuck.

  • Michael R (unregistered) in reply to Dr, Pepper

    You must be new here.

  • (nodebb) in reply to Dr, Pepper

    Depending on the profile of the CEO, doing code reviews for them may not be such a blessing...

    I've seen some people get extremely defensive when their code was being reviewed, whilst ironically being absolutely insistent when they were doing others reviews.

    In my last company, we actually had a process were we could opt in to anonimize the reviewers and reviewees name. I quickly understood it wasn't that pointless.

  • PedanticRobot (unregistered)

    All lowercase member names? No space after "if", as if it were a function and not a keyword? Oh, there's the missing space after the parenthesis, and it brought a buddy to join it hanging out inside the parentheses where they shouldn't be. Yea, even without the redundant lines, this code would also drive me to drinking.

  • Neveranull (unregistered)

    You can tell it was a manager who checked in the code, because obviously there were no test cases where this.idtoservice.Common was null or this.idtoservice.Common.Security was null, otherwise such test cases would fail, since the code doesn’t handle them. Only managers are allowed to check in untested or poorly tested code. There’s no one to stop them.

  • Maia Everett (github)

    TRWTF is Hungarian notation in C#.

Leave a comment on “Idtoic Mistakes”

Log In or post as a guest

Replying to comment #:

« Return to Article