Skip to content

Conversation

bcheidemann
Copy link

@bcheidemann bcheidemann commented Mar 17, 2025

The contributing docs suggest to open an RFC issue "in order to discuss the broader impacts of the proposed change with the other maintainers". I think this is an excellent suggestion, but I felt that since this RFC touches on quite a few important aspects of the Typeshare implementation, it may be sensible to track it as a PR, so maintainers can leave comments on specific aspects. If an issue is preferred though, I will happily open one instead 🙂

Looking forward to feedback! ❤️


View the latest iteration of the RFC here and a POC pull request here.

@bcheidemann bcheidemann marked this pull request as draft March 17, 2025 19:05
) { }
```

## Single File per Class & File Naming
Copy link
Author

@bcheidemann bcheidemann Mar 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having had some time to think about this, a simpler solution could be to use a sort of namespace class to group classes/records. For example, if generating types for the crate "lib_shared_types", this could look something like:

class LibSharedTypes {
    public static record Person(
        String name,
        int age
    ) {}
}

Which can be used like this:

new LibSharedTypes.Person("...", 42);

Classes can reference each other as normal within the same "namespace":

class LibSharedTypes {
    public static record Person(
        String name,
        short age
    ) {}

    public static record Couple(
        Person person1,
        Person person2
    ) {}
}

Which can then be used like this:

var bill = new LibSharedTypes.Person("Bill", 73);
var ben = new LibSharedTypes.Person("Ben", 73);
var flowerPotMen = new LibSharedTypes.Couple(bill, ben);

Limitations

This doesn't help with file naming.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant