• (nodebb)

    But a property returning its own instance, well… that doesn't make sense at all

    Counter example in Objective C:

    foo = [frist retain];
    

    retain can be viewed as such a property that returns the instance but also has a side effect of incrementing the reference count.

  • Wim ten Brink (github)

    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.

  • Sauron (unregistered)

    Self-reporting suspicious behaviour? Reminds me of RFC 3514 :D

  • (author) in reply to Wim ten Brink

    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.

  • DQ (unregistered)

    What I always like:

    1. Somebody sees some code, thinks "WTF" and sends it to TDWTF
    2. Remy sees it and thinks: WTF and writes an article
    3. Some random reader sees it and thinks: But this makes sense

    So one (wo)man's logical choice is anothers one's WTF

  • (nodebb)

    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:

    public sealed class EntityInfo { }
    
    public sealed class Entity { public EntityInfo Info { get; } }
    

    Inheriting the class to avoid another heap object:

    public class EntityInfo { internal protected EntityInfo() {} }
    
    public sealed class Entity : EntityInfo { public EntityInfo Info => this; }
    

    Fixing the downcasing warning:

    public class EntityInfo { internal protected EntityInfo() {} }
    
    public sealed class Entity : EntityInfo { public Entity Info => this; }
    
    

    And finally the missing refactoring step: Changing all property references to the object itself.

  • Naomi (unregistered)

    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.

  • ricecake (unregistered)

    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."

  • (nodebb)

    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.)

  • JBanana (unregistered)

    Why only extract an object from itself once?

    item.SuspectedItem.SuspectedItem.SuspectedItem.someProperty()

  • (nodebb) in reply to ricecake

    Actual computer scientists have no idea how to code.

  • (nodebb)

    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.)

  • Tinkle (unregistered)

    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.)

  • William Markus (unregistered)
    Comment held for moderation.
  • Charles (unregistered)
    Comment held for moderation.
  • Elijah (unregistered)
    Comment held for moderation.
  • (nodebb)

    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.

  • Glenn (unregistered)
    Comment held for moderation.
  • Glenn (unregistered)
    Comment held for moderation.
  • Robert Markus (unregistered)
    Comment held for moderation.
  • Jacob (unregistered)
    Comment held for moderation.

Leave a comment on “Suspicious Contents”

Log In or post as a guest

Replying to comment #:

« Return to Article