- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
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.
Admin
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:
Addendum 2024-10-10 07:06: For those interested how the code would like in C#:
Admin
For a moment I thought it wasn't IDTOservice but IDIOTservice.
Admin
This could be either Java or C#, but I think C# is more likely:
UpperCamelCase
for types, while C# also uses it for methods, properties, and namespaces; the names are conventional in C# but not in Java..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.)
Admin
For a good WTF I like my property getters to have side-effects.
Admin
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.
Admin
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.
Admin
ID(10)T-oh-I-see...
Admin
Someone give the CEO a bump, he's stuck.
Admin
You must be new here.
Admin
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.
Admin
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.
Admin
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.
Admin
TRWTF is Hungarian notation in C#.