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
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
We solved this problem in XPCOM/xpidl by generating helper macros for each interface, such that you would put in
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
0
Comments
Foo.ice:
Would generate as part of Foo.h
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.
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.
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 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.