Skip to content

Proposal: Data classes #161

@MichaelRFairhurst

Description

@MichaelRFairhurst

So neither PHP nor java support properties on an interface.

This means I will have to generate getters/setters in java (hurting performance) and _get/_set methods in PHP (hurting performance more) and maybe most importantly just making interop more compilcated.

I realized that I will have the same problem in C++, as interfaces will mean multiple inheritance, and multiple inheritance + members = diamond problem.

So I got to thinking, I don't like public members anyway, but I want to have them for their performance. But what if I made data classes?

Data classes would

  • not be able to have methods
  • not be able to be implemented by other classes, only extended, and only by other data classes
  • be able to be instantiated without a provider (!)
  • be able to have very testable methods via service provided methods (!)
  • have no private members

Other classes would

  • have no public members

Basically

every Point:
    needs public Num x, public Num y;
    with scale = 1;

would be

data Point:
    needs Num x, Num y;
    with scale = 1;

And you could do make them any time

var Point(1, 2);

instead of

var Point(1,2) from PointProvider

and you'd be able to still call methods on them, as long as they are on a service provider...

every PointService:
    on Point
    allows getDistance() {
        return Point.x * Point.y * Point.scale;
    }

every MyClass:
    needs PointService then {
        new Point(1, 2).getDistance();

Its an intriguing pairing of ideas. I don't like that its "more." But otherwise I like it a decent amount.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions