Re: [RFC][Draft] Sealed Classes

From: Date: Mon, 26 Apr 2021 07:54:04 +0000
Subject: Re: [RFC][Draft] Sealed Classes
References: 1 2 3 4 5 6 7 8  Groups: php.internals 
Request: Send a blank email to internals+get-114182@lists.php.net to get a copy of this message
Am 25.04.2021 um 05:47 schrieb Larry Garfield <larry@garfieldtech.com>:
> In practice, I think all of the use cases for sealed classes are ADT-esque.  As I noted before,
> combining sealed classes with Nikita's new-in-expressions RFC would allow for this (also using
> my short-functions RFC for this example, although that's a nice-to-have):
> 
> sealed class Maybe permits Some, None {

...

> }
> 
> final class None extends Maybe {}



This is exactly the thing I'm worried about.

Say I want to add something like logging to the None type.
Now your sealed and final classes prevent me from defining MyNone extending None even though it
would be 100% compatible with None. Just because *you* deemed that useless or wrong.

I've encountered situations like this and came to the conclusion that while this makes sense
for languages like Haskell - where the whole idea is to be able to reason about a complex type
system - it is an anti-pattern for other languages like PHP.

Referring to another post, not yours: People, please don't use Java as a reason to add
something to PHP, Java is the king of anti-patterns ;-)

- Chris



Thread (76 messages)

« previous php.internals (#114182) next »