Skip to content

Transformers API issues when porting from Kolasu #12

@gabriele-tomassetti

Description

@gabriele-tomassetti

The original Kolasu API for transformers is well suited for Kotlin, but it is not a perfect fit for C#. The two languages have strong similarities, but there are some notable differences that impact this feature:

  • Kotlin allows to use wildcards in generics, such as NodeFactory<*,*>. This is not possible to do in C#
  • Kotlin has more in-depth support for reflection, for example you can restrict an argument to a type descriptor for a property. C# instead supports only a standard Type class. For instance you can a variable similar to this:
PropertyType<Node> property

where the variable property would contain information about a property of the class Node. Similarly, you can have type-safe references to properties, similar Node::children.type would be a reference to the metadata about the property children of Node. This is not possible in C#.

  • Generics constraints are also more usable in Kotlin. You can use them everywhere you use generics, while they are more restricted in C#. For example, you will rarely see RandomGeneric<out T>

The combinations of these limitations means that using the transformers feature in C# in a bit less usable (e.g., you need to define all generics arguments, while many can be automatically inferred in Kotlin) and less safe (we need to use methods like GetType().GetProperty("children") to get a reference to a property, and this is not type-safe, so we could easily mistype a property and have the code fail. To compare between using of the two versions, you can compare the different implementation of a test in Kolasu and C#.

This leaves us with the issue if we want to change the API to make it more C#-like (better for C#-exclusive project) or keep it more in sync with Kotlin (easier to learn and use in cross-platform project). This issue is open to allow discussion and gather feedback. So, at this point the Transformers API should be still considered in beta status.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions