The Daily WTF: Curious Perversions in Information Technology
Welcome to TDWTF Forums Sign in | Join | Help
in Search

IDoNothing

Last post 02-05-2013 6:18 PM by jasmine2501. 26 replies.
Page 1 of 1 (27 items)
Sort Posts: Previous Next
  • 02-04-2013 9:04 AM

    IDoNothing

    Presented without comment, because I honestly don't know enough about our software to tell what this does.
    using System;
    using System.Text;
    
    namespace OurProgramInterfaces
    {
        public interface IBaseInput:IBaseParams
        {
    
    
    
    
        }
    
    
    
    
    
    }
    
    and of course, its sister class:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace OurProgramInterfaces
    {
        public interface IBaseOutput:IBaseParams
        {
        }
    }
    
  • 02-04-2013 9:25 AM In reply to

    Re: IDoNothing

    Marker interfaces?
  • 02-04-2013 9:28 AM In reply to

    Re: IDoNothing

    There are valid reasons to use something like this; it's a common software idiom called "Marker Interfaces".  You have an empty interface that exists so you can test if a derived class should have a certain behavior (because C# doesn't support multiple inheritance).  For instance, let's say I have some domain entity, and I need to determine if it should have update timestamps applied to it.  I can create an interface called say ITrackable that doesn't do anything itself, implement it in my class, and then check later if my class implements it.

    Given the above example I'd guess it's something like that.  There's probably some conditional logic that checks if x is IBaseInput or IBaseOutput and does something if it is.  May or may not be a WTF depending on usage.

    The Daily WTF Forums. You will never find a more wretched hive of scum and villainy.
  • 02-04-2013 9:42 AM In reply to

    • PJH
    • Top 10 Contributor
    • Joined on 02-14-2007
    • Newcastle, UK
    • Posts 3,197

    Re: IDoNothing

    lscharen:
    Marker interfaces?
    Google?
    3 logicians go into a bar.; the barman says ‘Would you all like a drink?’.
    The first says 'I’m not sure', the second says 'I’m not sure', and the third says 'Yes'.
  • 02-04-2013 9:48 AM In reply to

    • toon
    • Top 200 Contributor
    • Joined on 01-07-2012
    • Posts 281

    Re: IDoNothing

    PJH:
    lscharen:
    Marker interfaces?
    Google?

    What's PJH supposed to Google, pray? "IBaseInput:IBaseParams" or what?

  • 02-04-2013 9:54 AM In reply to

    • TGV
    • Top 75 Contributor
    • Joined on 10-09-2005
    • Posts 563

    Re: IDoNothing

    Actually, that does not make a lot of sense to me. If you want to check if a class supports certain behavior, check the name of the bloody class that actually defines that behavior! And checking that kind of stuff by naming is, well, asking for trouble.

    "Look, guv', the log files are growin'. And every bleedin' line says sumfin' bout an eye track ball."

  • 02-04-2013 10:00 AM In reply to

    • PJH
    • Top 10 Contributor
    • Joined on 02-14-2007
    • Newcastle, UK
    • Posts 3,197

    Re: IDoNothing

    toon:
    What's PJH supposed to Google, pray?
    Nothing. I was expecting Ischaren to Google "Marker interfaces."
    3 logicians go into a bar.; the barman says ‘Would you all like a drink?’.
    The first says 'I’m not sure', the second says 'I’m not sure', and the third says 'Yes'.
  • 02-04-2013 10:09 AM In reply to

    Re: IDoNothing

    TGV:
    Actually, that does not make a lot of sense to me. If you want to check if a class supports certain behavior, check the name of the bloody class that actually defines that behavior! And checking that kind of stuff by naming is, well, asking for trouble.
    I'm not sure whether I don't understand the point you're trying to make, or whether you don't understand marker interfaces.

     

  • 02-04-2013 10:25 AM In reply to

    • toon
    • Top 200 Contributor
    • Joined on 01-07-2012
    • Posts 281

    Re: IDoNothing

    PJH:
    toon:
    What's PJH supposed to Google, pray?
    Nothing. I was expecting Ischaren to Google "Marker interfaces."

    Sorry; it seems I'm not the brightest knife in the chandelier drawer today.

    My point was meant to be, that I don't understand why you'd have Ischaren google something he/she obviously already knows about.

  • 02-04-2013 10:35 AM In reply to

    • PJH
    • Top 10 Contributor
    • Joined on 02-14-2007
    • Newcastle, UK
    • Posts 3,197

    Re: IDoNothing

    toon:
    My point was meant to be, that I don't understand why you'd have Ischaren google something he/she obviously already knows about.
    It wasn't obvious. Indeed, the opposite appears to be the case.
    3 logicians go into a bar.; the barman says ‘Would you all like a drink?’.
    The first says 'I’m not sure', the second says 'I’m not sure', and the third says 'Yes'.
  • 02-04-2013 10:45 AM In reply to

    Re: IDoNothing

    everyone:
    Marker interfaces?
    After further inspection, it seems that these interfaces are used to create the class hierarchy - a certain operation has input parameters (an IBaseInput) and output parameters (an IBaseOutput). Both are always implementation of sub-interfaces - ISomeInput, etc.. Less of a WTF than I thought, but still quite strange.
  • 02-04-2013 12:05 PM In reply to

    • emurphy
    • Top 75 Contributor
    • Joined on 01-14-2005
    • Granada Hills, CA
    • Posts 568

    Re: IDoNothing

    Even so, they should contain some comments along the lines of "deliberately empty because <reasons>".


  • 02-04-2013 12:12 PM In reply to

    • GMMan
    • Not Ranked
    • Joined on 08-23-2012
    • Posts 32

    Re: IDoNothing

    TGV:

    Actually, that does not make a lot of sense to me. If you want to check if a class supports certain behavior, check the name of the bloody class that actually defines that behavior! And checking that kind of stuff by naming is, well, asking for trouble.

    "Look, guv', the log files are growin'. And every bleedin' line says sumfin' bout an eye track ball."


    Are you suggesting I should
    object.GetType().Name.Contains("PartOfClassName")
    ? Good luck with that.
  • 02-04-2013 12:28 PM In reply to

    Re: IDoNothing

    PJH:
    toon:
    My point was meant to be, that I don't understand why you'd have Ischaren google something he/she obviously already knows about.
    It wasn't obvious. Indeed, the opposite appears to be the case.
    Given the fact that Marker Interfaces were not mentioned in the OP, it seems quite obvious to me that Ischaren was suggesting Marker Interfaces was the answer. "Marker Interfaces?" as in "Could it be the case that these are used as Marker Interfaces?"
  • 02-04-2013 1:23 PM In reply to

    Re: IDoNothing

    I'm actually using marker interfaces in some code of mine. It looks kind of like

    public interface IAutoFrob {
    }
    
    public interface IAutoFrobInASpecificWay : IAutoFrob {
        int FrobRate { get; set; }
        FrobPreperationStatus GetFrobPreperationStatus(int foo, string bar);
    }
    

    The first class says the class can do a certain procedure automatically, the second says it will use a lot of features from the automatic system but it has a property and method to control it more fine-grained.


    [Sanity Not Available until further notice. The trolls have won.]

  • 02-04-2013 1:34 PM In reply to

    • mihi
    • Top 500 Contributor
    • Joined on 05-10-2008
    • Posts 94

    Re: IDoNothing

    This is C#, not Java 1.1. Therefore you should use Attributes instead of Marker interfaces :)
  • 02-04-2013 10:17 PM In reply to

    • chooks
    • Not Ranked
    • Joined on 11-15-2006
    • Posts 6

    Re: IDoNothing

    Is there a particular scenario where Attributes would be useful (other than brand new shiny feature)?  Not being a dick here -- it just seems like 

    if (instanceof Foo) { doSomethingConcrete() }
    

    Is fairly straightforward. Attributes could give you a richer set of things to inspect, but maybe at the cost of a level of indirection that could cause more problems in the long run. Is there a particular area where this would be useful? Just curious, as my imagination has hit the wall after 14 hours at work...

  • 02-04-2013 10:36 PM In reply to

    • Cat
    • Top 500 Contributor
    • Joined on 07-24-2010
    • Posts 121

    Re: IDoNothing

    TGV:

    Actually, that does not make a lot of sense to me. If you want to check if a class supports certain behavior, check the name of the bloody class that actually defines that behavior! And checking that kind of stuff by naming is, well, asking for trouble.

     

    The whole point of a marker interface is that the classes that you're looking for don't even exist at this time.  For example, in Java the Serializable marker interface tells Java that you can serialize the class to a file.  Clearly the people who wrote serialization didn't know about every custom class anyone would ever want to serialize.

    In C#, there are attributes which are generally preferred, but there can be cases where a marker interface is more appropriate..  For example, a marker interface can be used as a constraint for generics, allowing for some additional compile-time type checking; you can't do a compile-time generic constraint on an attribute.

  • 02-04-2013 10:39 PM In reply to

    • Cat
    • Top 500 Contributor
    • Joined on 07-24-2010
    • Posts 121

    Re: IDoNothing

    chooks:

    Is there a particular scenario where Attributes would be useful (other than brand new shiny feature)?  Not being a dick here -- it just seems like 

    if (instanceof Foo) { doSomethingConcrete() }
    

    Is fairly straightforward. Attributes could give you a richer set of things to inspect, but maybe at the cost of a level of indirection that could cause more problems in the long run. Is there a particular area where this would be useful? Just curious, as my imagination has hit the wall after 14 hours at work...

     

    Attributes have a few advantages over marker interfaces.  One big one is inheritance - an interface is always inherited, but an attribute may or may not be inherited.  Plus, you can tag individual methods and properties with attributes, but not with marker interfaces.

  • 02-05-2013 12:31 AM In reply to

    Re: IDoNothing

    Cat:

    chooks:

    Is there a particular scenario where Attributes would be useful (other than brand new shiny feature)?  Not being a dick here -- it just seems like 

    if (instanceof Foo) { doSomethingConcrete() }
    

    Is fairly straightforward. Attributes could give you a richer set of things to inspect, but maybe at the cost of a level of indirection that could cause more problems in the long run. Is there a particular area where this would be useful? Just curious, as my imagination has hit the wall after 14 hours at work...

     

    Attributes have a few advantages over marker interfaces.  One big one is inheritance - an interface is always inherited, but an attribute may or may not be inherited.  Plus, you can tag individual methods and properties with attributes, but not with marker interfaces.

    Attributes may also be passed parameters.
    I spend most of my life pressing buttons to make the pattern of lights change however I want.
  • 02-05-2013 5:06 AM In reply to

    Re: IDoNothing

    Cat:

    Attributes have a few advantages over marker interfaces.

     

    Attributes are accessed via reflection, which is much slower than a simple instanceof check. Sometimes you need efficiency, not features.

    A good example for a marker interface is Java's RandomAccess, btw.

     

  • 02-05-2013 5:10 AM In reply to

    Re: IDoNothing

    PJH:
    toon:
    My point was meant to be, that I don't understand why you'd have Ischaren google something he/she obviously already knows about.
    It wasn't obvious. Indeed, the opposite appears to be the case.
    Seemed pretty obvious he was saying "[perhaps they're] marker interface?"
  • 02-05-2013 5:37 AM In reply to

    Re: IDoNothing

    derari:

    Attributes are accessed via reflection, which is much slower than a simple instanceof check. Sometimes you need efficiency, not features.

    A good example for a marker interface is Java's RandomAccess, btw.

     

    One shouldn't be performing instanceof checks- or attribute checks, for that matter- in a tight loop to begin with, though. 

     

  • 02-05-2013 6:17 AM In reply to

    Re: IDoNothing

     I agree with Mihi. Java has annotations now, which are far more powerful, and I would hope and assume the C# has a similar feature.

  • 02-05-2013 3:47 PM In reply to

    • mihi
    • Top 500 Contributor
    • Joined on 05-10-2008
    • Posts 94

    Re: IDoNothing

    In fact, Java annotations were more or less based of C#'s attributes. :)

    And if you think RandomAccess as an interface is a good idea, have a look at implementation of Collections.synchronizedList method (or some other examples) - it makes it really hard to implement wrapper implementations for lists. Having an isRandomAccess() method inside the List interface would have made it so much easier (having the additional benefit that everyone who implements a List himself is forced to think about this decision, and cannot forget to implement RandomAccess).

  • 02-05-2013 4:14 PM In reply to

    Re: IDoNothing

    derari:

    Cat:

    Attributes have a few advantages over marker interfaces.

     

    Attributes are accessed via reflection, which is much slower than a simple instanceof check. Sometimes you need efficiency, not features.

    A good example for a marker interface is Java's RandomAccess, btw.

     

    If the relative efficiency between an instanceof and an attribute check actually matters, your design is stupid.
  • 02-05-2013 6:18 PM In reply to

    Re: IDoNothing

    This is the Interface Orgy design pattern. I am convinced there is a guy over in India teaching that this design pattern solves all problems if you make it deep enough. If I ever meet that guy I'm going to slit his throat right in front of his family. Or yeah, they're markers :)
Page 1 of 1 (27 items)
Powered by Community Server (Non-Commercial Edition), by Telligent Systems