[
https://issues.apache.org/jira/browse/THRIFT-1977?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13667959#comment-13667959
]
Jens Geyer commented on THRIFT-1977:
------------------------------------
{quote}
1. When you have const list or map, two static constructors will be generated
and they will collide in partial Constants class.
{quote}
Agree. I re-applied the "static" and the file name to the Constants class with
v3, but left the additional dot before "Constants.cs".
{quote}
2. When constants from different thrift files have same name, they will collide
too.
{quote}
Of course they do, because they share the same namespace. I would not recommend
to share one namespace between two IDL files. Doing so cries for problems,
IMHO. For example, it's easy to produce a collision just by inserting two
structs with the same name into both IDLs.
For Thrift, these are different things. They reside in different IDL files and
you have to prefix types from the one if you plan to use it in the other. But
because files and folders in C# and Java are named after classes and
namespaces, the same file is consequently written twice into the same folder -
unfortunately with different content, so one overwriting the other.
Ok, we could add the prefix to all generated files and classes, and of course
double the prefix for constants to avoid additional problems there. Altought
slightly thrifting away (no pun intended) from
[POLA|http://en.wikipedia.org/wiki/Principle_of_least_astonishment], this could
work, unless someone starts putting the included IDL files into a different
folder. A few days later, one of the included IDL files shares the file name
and namespace with another file in first folder - and we get another collision
when the outer one is generated with -r.
Bottom line: There are not that many ways left to get the whole thing 100%
collision proof (if any at all). The issue is rooted in two things: First, both
the constants file and class names which are predefined and within the same
name space. Next, the different meanings of file names and namespaces in
Thrift. Even with an added ".constants" to the namespace it still would be
possible to produce collisions. So the only two solutions that come to my mind
for now would involve either disallowing certain names as reserved and/or
keeping track of the generated files and applying an additional number.
What do you think?
> C# compiler should generate constant files prefixed with thrift file name
> -------------------------------------------------------------------------
>
> Key: THRIFT-1977
> URL: https://issues.apache.org/jira/browse/THRIFT-1977
> Project: Thrift
> Issue Type: Improvement
> Components: C# - Compiler
> Affects Versions: 0.9, 1.0
> Reporter: Deniss Afonin
> Priority: Minor
> Attachments: t_csharp_generator.patch, testcases_v2_fixed.zip,
> Testcases.zip,
> THRIFT-1977-Csharp_generate_constant_files_prefixed_with_thrift_file_name-v2.patch,
>
> THRIFT-1977-Csharp_generate_constant_files_prefixed_with_thrift_file_name-v3.patch
>
>
> When you compile (recursively) thrift file that contains constants and
> includes another thrift file with constants, then only one Constants.cs file
> will be produced and it won't contain constants from the included file.
> Compiler should behave like a java version, for each thrift file with
> constants, generate a prefixed constants file.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira