Results 1 to 7 of 7

Thread: request: macro declaring slice interface's methods

  1. #1
    shaver is offline Registered User
    Join Date
    May 2003
    Posts
    35

    Lightbulb request: macro declaring slice interface's methods

    If I have a number of implementations of a given interface, modifying the interface requires changing a lot of boilerplate code, which is both tedious and error-prone.

    We solved this problem in XPCOM/xpidl by generating helper macros for each interface, such that you would put in

    Code:
    class mySample : public nsISample
    {
    public:
        mySample();
    
        // nsISample interface
        NS_DECL_NSISAMPLE;
    private:
        int _sampleInt;
    };
    rather than hand-typing all of the nsISample method signatures by hand. Would you take a patch that added such a macro to slice2cpp-generated headers? No code bloat for people who don't use it, this time I promise!

    Mike

  2. #2
    marc's Avatar
    marc is offline ZeroC Staff
    Name: Marc Laukien
    Organization: ZeroC, Inc.
    Project: The Internet Communications Engine
    Join Date
    Feb 2003
    Location
    Florida
    Posts
    1,860
    Sorry, I'm afraid I don't understand what you mean. What boilerplate code are you referring to?

  3. #3
    vukicevic is offline Registered User
    Name: Vladimir Vukicevic
    Organization: DUG
    Project: DUG Insight
    Join Date
    May 2003
    Location
    San Francisco
    Posts
    35
    I think the suggestion is for slice2cpp to generate a #define for each interface/class that would contain declarations for the methods defined in that interface. For example, the following slice:

    Foo.ice:
    Code:
    module Bar {
      interface Foo {
        void opA (int arg);
        int opB (string s);
      };
    };
    Would generate as part of Foo.h

    Code:
    #define ICE_DECLARE__BAR_FOO \
        virtual void opA (::Ice::Int, const ::Ice::Context&); \
        virtual int opB (const ::std::string&, const ::Ice::Context&)
    so that any FooI implementation would just use ICE_DECLARE_BAR_FOO as part of the class declaration, instead of duplicating the signatures by hand. The only places where the method signature would then need to be written would be the slice source and the method definition (where any mistakes can be caught by the compiler, leading to a "no such method declared in class" error).
    vladimir@pobox.com

  4. #4
    michi's Avatar
    michi is offline Registered User
    Name: Michi Henning
    Organization: Triodia Technologies
    Project: I have a passing interest in Ice :-)
    Join Date
    Feb 2003
    Location
    Brisbane, Australia
    Posts
    1,055
    Originally posted by vukicevic


    Code:
    #define ICE_DECLARE__BAR_FOO \
        virtual void opA (::Ice::Int, const ::Ice::Context&); \
        virtual int opB (const ::std::string&, const ::Ice::Context&)
    so that any FooI implementation would just use ICE_DECLARE_BAR_FOO as part of the class declaration, instead of duplicating the signatures by hand. The only places where the method signature would then need to be written would be the slice source and the method definition (where any mistakes can be caught by the compiler, leading to a "no such method declared in class" error).
    You can use the --impl switch to slice2cpp to generate implementation stubs (.h and .cpp) file that you can edit. That way, you don't have to write the implementation class definition yourself. Would that meet your requirements?

    Cheers,

    Michi.

  5. #5
    shaver is offline Registered User
    Join Date
    May 2003
    Posts
    35
    Originally posted by michi
    You can use the --impl switch to slice2cpp to generate implementation stubs (.h and .cpp) file that you can edit. That way, you don't have to write the implementation class definition yourself. Would that meet your requirements?
    Not exactly: I do use --impl sometimes to generate implementation stubs, but I'm more concerned about having to go and manually add/remove/change a method declaration in each of my interface implementations' class declarations (in some cases I have quite a few), when I change the slice interface. I still have to change the method definitions, but that's not something avoidable. This was a tremendously popular feature when we added it to xpidl, and I'm remembering why now.

    I'm happy to whip up a slice2cpp patch in a bit, if I get some time for it.

    Mike

  6. #6
    michi's Avatar
    michi is offline Registered User
    Name: Michi Henning
    Organization: Triodia Technologies
    Project: I have a passing interest in Ice :-)
    Join Date
    Feb 2003
    Location
    Brisbane, Australia
    Posts
    1,055
    Originally posted by shaver
    Not exactly: I do use --impl sometimes to generate implementation stubs, but I'm more concerned about having to go and manually add/remove/change a method declaration in each of my interface implementations' class declarations (in some cases I have quite a few), when I change the slice interface. I still have to change the method definitions, but that's not something avoidable. This was a tremendously popular feature when we added it to xpidl, and I'm remembering why now.

    I'm happy to whip up a slice2cpp patch in a bit, if I get some time for it.

    Mike
    I see your point. This seems like a sensible idea, thanks!. The penalty in terms of code size is zero anyway, seeing that only #define is involved. I'll add this to the code generator. Stay tuned...

    Cheers,

    Michi.

  7. #7
    michi's Avatar
    michi is offline Registered User
    Name: Michi Henning
    Organization: Triodia Technologies
    Project: I have a passing interest in Ice :-)
    Join Date
    Feb 2003
    Location
    Brisbane, Australia
    Posts
    1,055
    OK, after consulting with Marc, I have to take back what I said, sorry

    The complexity isn't worth the minor gain in convenience, we believe. It's easy enough to copy and paste the signature from the generated header file, or to generate an implementation stub with --impl and to copy and paste from that. Besides, if I see something like
    Code:
    class FooI : public virtual Foo {
    public:
        OP_DECL_Foo
        // Other declarations here...
    };
    I end up having to know and decipher what OP_DECL_Foo does. The obfuscation that creates is likely to outweigh the minor inconvenience of not having to update the implementation class declaration.

    In general, it's a fine line between convenience and complexity. One example that springs to mind is TAO. It's so full of "convenient" macros that, in the end, the code looks totally unreadable (at least to me, it does, because I'm not intimately familiar with TAO). One person's convenience feature is another person's obfuscation...

    Cheers,

    Michi.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 0
    Last Post: 04-20-2007, 01:36 PM
  2. Replies: 12
    Last Post: 03-24-2006, 10:38 AM
  3. Replies: 4
    Last Post: 03-21-2006, 07:45 PM
  4. Replies: 8
    Last Post: 12-02-2005, 08:46 AM
  5. Replies: 2
    Last Post: 01-24-2004, 09:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •