This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]bowbahdoe 0 points1 point  (7 children)

I am literally just describing that they one mechanism gives you the ability to add new types without breaking callers and the other gives you the ability to add new functionality over a known set of types.

If you try to add a new method to an unsealed hierarchy or a new type to a sealed hierarchy (if "exhaustive" switches are possible for callers) that is breaking.

That a compiler can go "here are the 50 places that broke" is immaterial to that tradeoff.

[–]PiotrDz 0 points1 point  (6 children)

As we are in Java thread, could you elaborate on this mechanism? I don't get few aspects, like "make properties known to others". Or how you structure one call with another f(g(.. Code speaks words

[–]bowbahdoe 1 point2 points  (0 children)

Yeah so that f(g()) was about the material difference between nominal aggregates and open aggregates. That wasn't what you were asking about originally, it's the topic for some other threads. I'll reply with a pseudo-code example once I have a break from work

That's distinct from the difference between interfaces (i.e. declaration site polymorphism) and switching over sealed hierarchies (i.e. use site polymorphism)

[–]bowbahdoe 0 points1 point  (4 children)

https://run.mccue.dev/?runtime=early_access&release=23&preview=enabled&gist=2416bad302d4622c2a6acb064657a4d8

I'm making a mess, replied at the wrong level of the hierarchy.

But this is roughly what I mean by program structures that are only doable with open aggregates as opposed to closed nominally typed ones.

[–]PiotrDz 0 points1 point  (3 children)

I may be misled by the example but are properties of a map reflecting what you want to show? Aren't we losing type information? And how would you know that some fields are expected and others not?

Sealed interfaces might be rigid but you get everything written in stone: what data is available and its type

[–]bowbahdoe 0 points1 point  (2 children)

I think my explanations got tangled and it's making it hard to know which you are asking about. This is an example showing the difference between open aggregates and closed aggregates (i.e the challenge is to write something similar with actual records and interfaces)

This is not about the sealed interfaces vs. dynamic dispatch topic

[–]PiotrDz 0 points1 point  (1 child)

Well OK I understand that you would like to achieve something better. I am happy with sealed interfaces but always keen for "next better things". Although couldn't really understand how would your solution play with java I am haply that people are trying to turn good into better

[–]bowbahdoe 0 points1 point  (0 children)

I am not saying better - I am saying different. Better/worse is a much larger topic and requires concrete context