- 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
Counter example in Objective C:
retain
can be viewed as such a property that returns the instance but also has a side effect of incrementing the reference count.Admin
It makes sense, though. We might be dealing with inheritance or interfaces that access the object. This property will provide the object cast as SuspectFileDataItem. It's actually pretty clever as now you don't need to cast the object everywhere in your code. :) It still looks weird, though. But it makes sense.
Admin
Self-reporting suspicious behaviour? Reminds me of RFC 3514 :D
Admin
This would be an upwards cast, then- which you don't even need to make explicit. Unless you're getting into shadowing, but that's it's own WTF.
Admin
What I always like:
So one (wo)man's logical choice is anothers one's WTF
Admin
I got nothing for that one :-)
Addendum 2024-05-07 10:01: Actually, think about it, I see one reason why this could be the leftovers by some incomplete refactoring.
Starting with:
Inheriting the class to avoid another heap object:
Fixing the downcasing warning:
And finally the missing refactoring step: Changing all property references to the object itself.
Admin
I'm on board with the theory that inheritance is involved somehow, either implementing an interface or allowing for subclassing, although I'd regard the latter as a code smell. I've actually done the former while using a heavily mixin-based framework.
Admin
A friend in college who was one of the best computer scientists I've ever met had this mantra: "Code high, debug sober, document drunk."
Admin
As always, if you actually have a good reason for doing something that looks like a WTF, then you should add a comment explaining what that is. (Especially so someone doesn't refactor it out of existence, and then discover the reason the hard way.)
Admin
Why only extract an object from itself once?
item.SuspectedItem.SuspectedItem.SuspectedItem.someProperty()
Admin
Actual computer scientists have no idea how to code.
Admin
Count me amongst those who think this is incomplete refactoring.
I'm picturing a piece of code of mine that in some cases simply returns itself. (Partition a tree into subtrees, but if it can't partition you're at the bottom, return itself.)
Admin
The only two reasons I can see that this would not be a WTF would be if it is implementing an interface, or the SuspectedItem property is called via reflection (possibly a different WTF.)
Admin
Maybe they are using the object somewhere that the "Component Model" binding infrastructure is used. So maybe WinForms, or other things like the build=t-in PropertyGrid component, which evolved out of the older COM (Component Object Model). It was a data-driven "make a quick and dirty UI" thing back in the old days, and incidentally the technology which made the "properties" grid in visual studio work for the WinForms and WPF Designer featers.
Basically, this thing would bind to members of a given object based on property by name, however there was no way to bind to the thing it's self. So if you needed a Grid with a column which contained the object itself, you could simply add a property like Self or This (I hated it when people used "This")
Now to run into this problem you've needed to make more than a few serious few design mistakes beforehand, but when you are faced with this situation and a deadline, this is what people do. Especially VB programmers.