You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Fredrik Hedberg (JIRA)" <ji...@apache.org> on 2008/12/02 23:36:46 UTC
[jira] Created: (THRIFT-219) Inject user-created templates into
generated code
Inject user-created templates into generated code
-------------------------------------------------
Key: THRIFT-219
URL: https://issues.apache.org/jira/browse/THRIFT-219
Project: Thrift
Issue Type: New Feature
Components: Compiler (Java)
Reporter: Fredrik Hedberg
Priority: Minor
Since Java lack the equivalent of C#'s fancy 'partial' class modifier, extending the logic of a Thrift-generated class means you have to do it quite literally. This patch allows the developer to write code templates that are injected into the generated classes by the compiler, allowing him to extend the generated classes in any way he wants.
The code templates are presumed to be found in /tmpl-java/$packagename/$typename.tmpl, and are injected into structs and services (.Iface and .Client).
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
Re: [jira] Updated: (THRIFT-219) Inject user-created templates into generated code
Posted by Rush Manbert <ru...@manbert.com>.
On Dec 3, 2008, at 10:52 AM, Eric Anderson wrote:
> Rush Manbert writes:
>> I guess that I would say (looking ahead to Eric Anderson's reply to
>> your reply) that if you submit a patch that implements something like
>> cpp_verbatim in the idl, it should also implement java_verbatim,
>> python_verbatim, etc. because that comes essentially for free and you
>> don't need to know anything about the different languages. But if you
>> submit a patch that lets you do something cool in Erlang I wouldn't
>> hold it hostage to the c++ version.
>
> Actually you still have to know about the other languages since you
> have to update the generator to do something, and you have to be able
> to test it. Just parsing and attaching it to the tree (which would be
> easy and I could do) isn't very useful.
> -Eric
Yeah, after writing the post I went and looked at the patch that
Fredrik submitted. I see that the code generation requires more
language-specific code than I thought it would. And I didn't think
about the testing part.
So sorry, you're correct. Not for free at all.
- Rush
Re: [jira] Updated: (THRIFT-219) Inject user-created templates into
generated code
Posted by Eric Anderson <an...@hpl.hp.com>.
Rush Manbert writes:
> I guess that I would say (looking ahead to Eric Anderson's reply to
> your reply) that if you submit a patch that implements something like
> cpp_verbatim in the idl, it should also implement java_verbatim,
> python_verbatim, etc. because that comes essentially for free and you
> don't need to know anything about the different languages. But if you
> submit a patch that lets you do something cool in Erlang I wouldn't
> hold it hostage to the c++ version.
Actually you still have to know about the other languages since you
have to update the generator to do something, and you have to be able
to test it. Just parsing and attaching it to the tree (which would be
easy and I could do) isn't very useful.
-Eric
Re: [jira] Updated: (THRIFT-219) Inject user-created templates into generated code
Posted by Rush Manbert <ru...@manbert.com>.
Hi Fredrik,
Thank you for your response. Please don't think that I was
complaining. It was more the case that I had been building up this
impression that features were drifting and this particular JIRA
incident prompted me to ask whether that was really the case.
I don't know what policy I would set if I was in charge. Do you make
all implementations adhere to the lowest common denominator that all
languages support, or do you let languages that can do more do it? The
latter seems more productive by far.
I guess that I would say (looking ahead to Eric Anderson's reply to
your reply) that if you submit a patch that implements something like
cpp_verbatim in the idl, it should also implement java_verbatim,
python_verbatim, etc. because that comes essentially for free and you
don't need to know anything about the different languages. But if you
submit a patch that lets you do something cool in Erlang I wouldn't
hold it hostage to the c++ version.
But I haven't contributed any code, so I can't expect to get a vote. :-)
- Rush
On Dec 3, 2008, at 5:41 AM, Fredrik Hedberg wrote:
> Hi,
>
> Well, although I don't really think this is a major problem
> (especially in this case, as this addresses a feature that is
> already provided by C#'s native support for partial classes), I see
> your point.
>
> However, I'm not sure what the best solution is - some developers
> are only fluent in a few languages, and others don't really have the
> time, nor the incentive (guilty as charged), to implement a feature
> across all the supported languages - the addition of a new meta-
> component in JIRA where new features are discussed in a language
> agnostic way perhaps?
>
> As a side note; the patch in question is probably easily adaptable
> for any other language generator in a matter of minutes, if it makes
> sense for your language of choice.
>
> - Fredrik
>
> On Dec 3, 2008, at 1:52 AM, Rush Manbert wrote:
>
>> Just a small question.
>>
>> This change is one of a number of changes that seem to be aimed at
>> only one language version of the Thrift-generated classes.
>>
>> Have I gotten the wrong impression, or is the feature set starting
>> to diverge on a per-implementation-language basis? For instance,
>> someone wanted to derive Thrift classes from base classes in either
>> Java or C#, someone else says that deep copies are needed, but they
>> only seem to be concerned with Java. Now this change wants to be
>> able to extend Thrift classes in Java, maybe because that
>> capability has already been added for C#.
>>
>> Am I wrong about this?
>>
>> - Rush
>>
>> On Dec 2, 2008, at 2:52 PM, Fredrik Hedberg (JIRA) wrote:
>>
>>>
>>> [ https://issues.apache.org/jira/browse/THRIFT-219?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
>>> ]
>>>
>>> Fredrik Hedberg updated THRIFT-219:
>>> -----------------------------------
>>>
>>> Description:
>>> Since Java lack the equivalent of C#'s fancy 'partial' class
>>> modifier, extending the logic of a Thrift-generated class means
>>> you have to do it quite literally. This patch allows the developer
>>> to write code templates that are injected into the generated
>>> classes by the compiler, allowing him to extend the generated
>>> classes in any way he wants.
>>>
>>> The code templates are presumed to be found in something like /
>>> tmpl-java/com/example/Document.tmpl, and are injected into structs
>>> and services (.Iface and .Client).
>>>
>>> was:
>>> Since Java lack the equivalent of C#'s fancy 'partial' class
>>> modifier, extending the logic of a Thrift-generated class means
>>> you have to do it quite literally. This patch allows the developer
>>> to write code templates that are injected into the generated
>>> classes by the compiler, allowing him to extend the generated
>>> classes in any way he wants.
>>>
>>> The code templates are presumed to be found in /tmpl-java/
>>> $packagename/$typename.tmpl, and are injected into structs and
>>> services (.Iface and .Client).
>>>
>>>
>>>> Inject user-created templates into generated code
>>>> -------------------------------------------------
>>>>
>>>> Key: THRIFT-219
>>>> URL: https://issues.apache.org/jira/browse/THRIFT-219
>>>> Project: Thrift
>>>> Issue Type: New Feature
>>>> Components: Compiler (Java)
>>>> Reporter: Fredrik Hedberg
>>>> Priority: Minor
>>>> Attachments: thrift-templates-1.diff
>>>>
>> <snip>
Re: [jira] Updated: (THRIFT-219) Inject user-created templates into
generated code
Posted by Eric Anderson <an...@hpl.hp.com>.
Fredrik Hedberg writes:
> [ code injection for Java, not other languages ]
We have added this for c++, we extended the idl to allow us to say
struct NodeID {
1: i32 id;
cpp_verbatim
uint32_t hash() const {
return static_cast<uint32_t>(id);
}
std::string toStr() const;
end_verbatim
}
I can send in a patch that does this, but it seems like a decision
would have to be made on which way to do this (in the idl explicitly
vs in extra files)
-Eric
Re: [jira] Updated: (THRIFT-219) Inject user-created templates into generated code
Posted by Fredrik Hedberg <fr...@gmail.com>.
Hi,
Well, although I don't really think this is a major problem
(especially in this case, as this addresses a feature that is already
provided by C#'s native support for partial classes), I see your point.
However, I'm not sure what the best solution is - some developers are
only fluent in a few languages, and others don't really have the time,
nor the incentive (guilty as charged), to implement a feature across
all the supported languages - the addition of a new meta-component in
JIRA where new features are discussed in a language agnostic way
perhaps?
As a side note; the patch in question is probably easily adaptable for
any other language generator in a matter of minutes, if it makes sense
for your language of choice.
- Fredrik
On Dec 3, 2008, at 1:52 AM, Rush Manbert wrote:
> Just a small question.
>
> This change is one of a number of changes that seem to be aimed at
> only one language version of the Thrift-generated classes.
>
> Have I gotten the wrong impression, or is the feature set starting
> to diverge on a per-implementation-language basis? For instance,
> someone wanted to derive Thrift classes from base classes in either
> Java or C#, someone else says that deep copies are needed, but they
> only seem to be concerned with Java. Now this change wants to be
> able to extend Thrift classes in Java, maybe because that capability
> has already been added for C#.
>
> Am I wrong about this?
>
> - Rush
>
> On Dec 2, 2008, at 2:52 PM, Fredrik Hedberg (JIRA) wrote:
>
>>
>> [ https://issues.apache.org/jira/browse/THRIFT-219?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
>> ]
>>
>> Fredrik Hedberg updated THRIFT-219:
>> -----------------------------------
>>
>> Description:
>> Since Java lack the equivalent of C#'s fancy 'partial' class
>> modifier, extending the logic of a Thrift-generated class means you
>> have to do it quite literally. This patch allows the developer to
>> write code templates that are injected into the generated classes
>> by the compiler, allowing him to extend the generated classes in
>> any way he wants.
>>
>> The code templates are presumed to be found in something like /tmpl-
>> java/com/example/Document.tmpl, and are injected into structs and
>> services (.Iface and .Client).
>>
>> was:
>> Since Java lack the equivalent of C#'s fancy 'partial' class
>> modifier, extending the logic of a Thrift-generated class means you
>> have to do it quite literally. This patch allows the developer to
>> write code templates that are injected into the generated classes
>> by the compiler, allowing him to extend the generated classes in
>> any way he wants.
>>
>> The code templates are presumed to be found in /tmpl-java/
>> $packagename/$typename.tmpl, and are injected into structs and
>> services (.Iface and .Client).
>>
>>
>>> Inject user-created templates into generated code
>>> -------------------------------------------------
>>>
>>> Key: THRIFT-219
>>> URL: https://issues.apache.org/jira/browse/THRIFT-219
>>> Project: Thrift
>>> Issue Type: New Feature
>>> Components: Compiler (Java)
>>> Reporter: Fredrik Hedberg
>>> Priority: Minor
>>> Attachments: thrift-templates-1.diff
>>>
> <snip>
Re: [jira] Updated: (THRIFT-219) Inject user-created templates into generated code
Posted by Rush Manbert <ru...@manbert.com>.
Just a small question.
This change is one of a number of changes that seem to be aimed at
only one language version of the Thrift-generated classes.
Have I gotten the wrong impression, or is the feature set starting to
diverge on a per-implementation-language basis? For instance, someone
wanted to derive Thrift classes from base classes in either Java or
C#, someone else says that deep copies are needed, but they only seem
to be concerned with Java. Now this change wants to be able to extend
Thrift classes in Java, maybe because that capability has already been
added for C#.
Am I wrong about this?
- Rush
On Dec 2, 2008, at 2:52 PM, Fredrik Hedberg (JIRA) wrote:
>
> [ https://issues.apache.org/jira/browse/THRIFT-219?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
> ]
>
> Fredrik Hedberg updated THRIFT-219:
> -----------------------------------
>
> Description:
> Since Java lack the equivalent of C#'s fancy 'partial' class
> modifier, extending the logic of a Thrift-generated class means you
> have to do it quite literally. This patch allows the developer to
> write code templates that are injected into the generated classes by
> the compiler, allowing him to extend the generated classes in any
> way he wants.
>
> The code templates are presumed to be found in something like /tmpl-
> java/com/example/Document.tmpl, and are injected into structs and
> services (.Iface and .Client).
>
> was:
> Since Java lack the equivalent of C#'s fancy 'partial' class
> modifier, extending the logic of a Thrift-generated class means you
> have to do it quite literally. This patch allows the developer to
> write code templates that are injected into the generated classes by
> the compiler, allowing him to extend the generated classes in any
> way he wants.
>
> The code templates are presumed to be found in /tmpl-java/
> $packagename/$typename.tmpl, and are injected into structs and
> services (.Iface and .Client).
>
>
>> Inject user-created templates into generated code
>> -------------------------------------------------
>>
>> Key: THRIFT-219
>> URL: https://issues.apache.org/jira/browse/THRIFT-219
>> Project: Thrift
>> Issue Type: New Feature
>> Components: Compiler (Java)
>> Reporter: Fredrik Hedberg
>> Priority: Minor
>> Attachments: thrift-templates-1.diff
>>
<snip>
[jira] Updated: (THRIFT-219) Inject user-created templates into
generated code
Posted by "Fredrik Hedberg (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/THRIFT-219?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Fredrik Hedberg updated THRIFT-219:
-----------------------------------
Description:
Since Java lack the equivalent of C#'s fancy 'partial' class modifier, extending the logic of a Thrift-generated class means you have to do it quite literally. This patch allows the developer to write code templates that are injected into the generated classes by the compiler, allowing him to extend the generated classes in any way he wants.
The code templates are presumed to be found in something like /tmpl-java/com/example/Document.tmpl, and are injected into structs and services (.Iface and .Client).
was:
Since Java lack the equivalent of C#'s fancy 'partial' class modifier, extending the logic of a Thrift-generated class means you have to do it quite literally. This patch allows the developer to write code templates that are injected into the generated classes by the compiler, allowing him to extend the generated classes in any way he wants.
The code templates are presumed to be found in /tmpl-java/$packagename/$typename.tmpl, and are injected into structs and services (.Iface and .Client).
> Inject user-created templates into generated code
> -------------------------------------------------
>
> Key: THRIFT-219
> URL: https://issues.apache.org/jira/browse/THRIFT-219
> Project: Thrift
> Issue Type: New Feature
> Components: Compiler (Java)
> Reporter: Fredrik Hedberg
> Priority: Minor
> Attachments: thrift-templates-1.diff
>
>
> Since Java lack the equivalent of C#'s fancy 'partial' class modifier, extending the logic of a Thrift-generated class means you have to do it quite literally. This patch allows the developer to write code templates that are injected into the generated classes by the compiler, allowing him to extend the generated classes in any way he wants.
> The code templates are presumed to be found in something like /tmpl-java/com/example/Document.tmpl, and are injected into structs and services (.Iface and .Client).
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (THRIFT-219) Inject user-created templates into
generated code
Posted by "Alexander Shigin (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/THRIFT-219?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12652857#action_12652857 ]
Alexander Shigin commented on THRIFT-219:
-----------------------------------------
I don't know Java well, but what's wrong with inheritance?
> Inject user-created templates into generated code
> -------------------------------------------------
>
> Key: THRIFT-219
> URL: https://issues.apache.org/jira/browse/THRIFT-219
> Project: Thrift
> Issue Type: New Feature
> Components: Compiler (Java)
> Reporter: Fredrik Hedberg
> Priority: Minor
> Attachments: thrift-templates-1.diff
>
>
> Since Java lack the equivalent of C#'s fancy 'partial' class modifier, extending the logic of a Thrift-generated class means you have to do it quite literally. This patch allows the developer to write code templates that are injected into the generated classes by the compiler, allowing him to extend the generated classes in any way he wants.
> The code templates are presumed to be found in something like /tmpl-java/com/example/Document.tmpl, and are injected into structs and services (.Iface and .Client).
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (THRIFT-219) Inject user-created templates into
generated code
Posted by "Fredrik Hedberg (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/THRIFT-219?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Fredrik Hedberg updated THRIFT-219:
-----------------------------------
Attachment: thrift-templates-1.diff
> Inject user-created templates into generated code
> -------------------------------------------------
>
> Key: THRIFT-219
> URL: https://issues.apache.org/jira/browse/THRIFT-219
> Project: Thrift
> Issue Type: New Feature
> Components: Compiler (Java)
> Reporter: Fredrik Hedberg
> Priority: Minor
> Attachments: thrift-templates-1.diff
>
>
> Since Java lack the equivalent of C#'s fancy 'partial' class modifier, extending the logic of a Thrift-generated class means you have to do it quite literally. This patch allows the developer to write code templates that are injected into the generated classes by the compiler, allowing him to extend the generated classes in any way he wants.
> The code templates are presumed to be found in /tmpl-java/$packagename/$typename.tmpl, and are injected into structs and services (.Iface and .Client).
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (THRIFT-219) Inject user-created templates into
generated code
Posted by "Bryan Duxbury (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/THRIFT-219?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12669499#action_12669499 ]
Bryan Duxbury commented on THRIFT-219:
--------------------------------------
I tend to agree that inheritance is the more appropriate way to get "extended" Thrift objects. Are there any big downsides to this that I'm missing?
> Inject user-created templates into generated code
> -------------------------------------------------
>
> Key: THRIFT-219
> URL: https://issues.apache.org/jira/browse/THRIFT-219
> Project: Thrift
> Issue Type: New Feature
> Components: Compiler (Java)
> Reporter: Fredrik Hedberg
> Priority: Minor
> Attachments: thrift-templates-1.diff
>
>
> Since Java lack the equivalent of C#'s fancy 'partial' class modifier, extending the logic of a Thrift-generated class means you have to do it quite literally. This patch allows the developer to write code templates that are injected into the generated classes by the compiler, allowing him to extend the generated classes in any way he wants.
> The code templates are presumed to be found in something like /tmpl-java/com/example/Document.tmpl, and are injected into structs and services (.Iface and .Client).
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Closed: (THRIFT-219) Inject user-created templates into
generated code
Posted by "Bryan Duxbury (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/THRIFT-219?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Bryan Duxbury closed THRIFT-219.
--------------------------------
Resolution: Won't Fix
> Inject user-created templates into generated code
> -------------------------------------------------
>
> Key: THRIFT-219
> URL: https://issues.apache.org/jira/browse/THRIFT-219
> Project: Thrift
> Issue Type: New Feature
> Components: Java - Compiler
> Reporter: Fredrik Hedberg
> Priority: Minor
> Attachments: thrift-templates-1.diff
>
>
> Since Java lack the equivalent of C#'s fancy 'partial' class modifier, extending the logic of a Thrift-generated class means you have to do it quite literally. This patch allows the developer to write code templates that are injected into the generated classes by the compiler, allowing him to extend the generated classes in any way he wants.
> The code templates are presumed to be found in something like /tmpl-java/com/example/Document.tmpl, and are injected into structs and services (.Iface and .Client).
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.