[ 
https://issues.apache.org/jira/browse/THRIFT-4496?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16528671#comment-16528671
 ] 

ASF GitHub Bot commented on THRIFT-4496:
----------------------------------------

Jens-G commented on issue #1567: THRIFT-4496: python specific list of keywords 
for python generator
URL: https://github.com/apache/thrift/pull/1567#issuecomment-401536272
 
 
   I finally had the time to have a closer look at it.
   
   1. general approach is not bad. I still would strive to reduce that global 
list to the minimum, but maybe we have to do that in a second step.
   
   2. what I find less helpful is the fact that the names are causing a 
failure(). In certain cases, reserved names can still be used but require a bit 
of treamtment. For example, in C# it is done by prefixing such a name with `@` 
to make *any* identifier a valid one, such as `@return` instead of `return`. 
The generator can do this alone and therefore there is no need to throw at all. 
In other languages we often added an underscore at the end of the name, which 
requireds a bit of tracking but otherwise works quite well. 
   
   4. Last not least, the reserved identifiers may also be context dependent. 
There are keywords, there are reserved words and there are special built-in 
method and property names used by the runtime that should not be used either, 
even if the are not a keyword in the strict sense. Context dependent now means, 
that expecially the latter ones differ between regular structs/classes and 
exceptions, to name just one possible case.
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Dealing with language keywords in Thrift (e.g. service method names)
> --------------------------------------------------------------------
>
>                 Key: THRIFT-4496
>                 URL: https://issues.apache.org/jira/browse/THRIFT-4496
>             Project: Thrift
>          Issue Type: New Feature
>          Components: Compiler (General)
>            Reporter: Vera Filippova
>            Priority: Minor
>
> Apache Thrift compiler doesn't allow to use keywords in any of supported 
> languages as field names. However, there are other compilers, like Scrooge, 
> which do allow using some keywords as field identifiers, which leads to 
> incompatibility.
> Assume we had a service with 'delete' method, with Java code generated by 
> Scrooge. Now we'd like to generate Python code with Apache Thrift, but 
> encounter an error because of the 'delete' keyword.
> I understand that using only Apache Thrift compiler, a user will never 
> encounter this problem, but I think enabling keywords by request seems 
> feasible.
> h1. Proposal
> It's possible to tweak keywords on code generation stage, e.g. use 'delete_' 
> as a name of a generated function instead of 'delete', then use the original 
> method name for a protocol message: writeMethodBegin('delete').
> This feature could be enabled with an additional flag, e.g. --screen-keywords.
> I have a draft for python generator here [https://github.com/nsrtvwls/thrift]
> The questions are, is this functionality welcome? If yes, would it require to 
> have it supported for all languages?



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to