On 02/02/2014 12:40 AM, Anton Lavrik wrote:
> Your question doesn't seem to specific to Erlang. While trying to
> figure out how to reproduce this clash, I realized that this should
> be invalid in Piqi and should have been caught by "piqi compile" in
> the first place. So, there was a bug that I have just fixed.
Ah, indeed, nice fix!
> Implicitly generated types for function parameters are very useful
> when it comes to integrating with piqi. That includes piqi compiler
> backends. For instance, piqic-erlang doesn't know anything about
> functions, yet it is able to generate correct type definitions for
> its function parameters and correct stubs for multi-format
> serializers. In piqic-erlang-rpc, it helps to simplify stubs
> generation as well. For example, knowing that the function accepts
> input, it can easily derive the name of the input type from the
> function name.
Sure, I am not saying they should not exist and completely understand
the need for a uniform treatment of all types. However, the possible
ways to fix this I proposed would not at all break this -- you would
simply only reference generated types in the generated code (such as in
piqi-erlang-rpc ), and separately expose the explicitly defined types to
the user, which would themselves reference the implicit generated types.
> Sometimes this may result in clashes like in your case. Not sure how
> to avoid them without sacrificing clarity. However, it is possible
> to minimize them by following some naming conventions such as using
> verbs for function names and nouns for type names.
I see. Well, in my case of one unqualified module importing types from
another unqualified module, no verb/noun convention can work, because
the clash is due to function I/O typenames between the two modules (e.g.
if both module1 and module2 define an `insert` function), not just due
to function and data typename clashes.
Anyway, thanks for the answer, I guess what you're saying makes sense,
it's probably easier to just treat everything simply and equally.
To work around this I now do a horrible hack, where I explicitly
introduce module-qualified type aliases for function input/output/errors
and then perform a nasty regex to remove the unqualified versions from
the generated Erlang code. Another possible option is to split up the
modules into those defining only data types and others also defining
functions.
--
Ignas