Go Back   ZeroC Forums > Comments

Reply
 
LinkBack Thread Tools Rate Thread Display Modes
  #1 (permalink)  
Old 01-24-2004
shaver 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
Reply With Quote
  #2 (permalink)  
Old 01-24-2004
marc's Avatar
marc marc is offline
ZeroC Staff
 
Name: Marc Laukien
Organization: ZeroC, Inc.
Project: The Internet Communications Engine
 
Join Date: Feb 2003
Location: Florida
Posts: 1,771
Sorry, I'm afraid I don't understand what you mean. What boilerplate code are you referring to?
Reply With Quote
  #3 (permalink)  
Old 01-26-2004
vukicevic vukicevic is offline
Registered User
 
 
Join Date: May 2003
Location: San Francisco
Posts: 34
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
Reply With Quote
  #4 (permalink)  
Old 01-26-2004
michi's Avatar
michi michi is offline
ZeroC Staff
 
Name: Michi Henning
Organization: ZeroC
Project: Ice
 
Join Date: Feb 2003
Location: Brisbane, Australia
Posts: 889
Quote:
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.
Reply With Quote
  #5 (permalink)  
Old 01-26-2004
shaver shaver is offline
Registered User
 
 
Join Date: May 2003
Posts: 35
Quote:
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
Reply With Quote
  #6 (permalink)  
Old 01-26-2004
michi's Avatar
michi michi is offline
ZeroC Staff
 
Name: Michi Henning
Organization: ZeroC
Project: Ice
 
Join Date: Feb 2003
Location: Brisbane, Australia
Posts: 889
Quote:
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.
Reply With Quote
  #7 (permalink)  
Old 01-26-2004
michi's Avatar
michi michi is offline
ZeroC Staff
 
Name: Michi Henning
Organization: ZeroC
Project: Ice
 
Join Date: Feb 2003
Location: Brisbane, Australia
Posts: 889
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.
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Question about proxy's factory methods. rc_hz Help Center 7 09-05-2006 07:58 AM
Add methods to a Java sample ???? surfer Help Center 8 01-18-2006 07:23 PM
C# code generated for comparison methods kwaclaw Comments 3 10-11-2005 01:54 PM
Local or server private methods dashie Help Center 6 12-22-2004 02:31 AM
macro to resolve ambiguous-base Ice::Object methods shaver Comments 2 01-24-2004 09:36 PM


All times are GMT -4. The time now is 07:12 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0
(c) 2008 ZeroC, Inc.