On Tue, Apr 19, 2016 at 2:13 PM, Stanislav Malyshev <smalys...@gmail.com>
wrote:

> Hi!
>
> > namespace Application;
> > function log(Eloquent\Collection | Haldayne\Map $entity) {
> >     $logger->log($entity->toArray());
> > }
>
> This is bad design. It assumes that two completely unrelated classes
> have the same function and it means the same.


Both of these exist in the wild, and both have identical function wrt
toArray: reducing a set of collection-like things to an array of arrays.


> If it's indeed true, we
> have a way to express it. It's called "interface".


Except these two are in separate libraries that cannot share an interface.


> > "Ugh, this is much easier in multi-catch. If only functions took
>
> multiple types, this would be much simpler to write."
>
> And it would be completely wrong, abuse of typing. If you mean to say
> "anything that has [toArray] method", you should either have interface or
> just get rid of the strictness and duck-type it and rely on PHP to throw
> exception if anything happens. Otherwise it is just a sloppy design.
>

An interface is not possible: separate libraries. Duck-typing is not
appropriate: only these two specific classes are supported.

Union types solve certain problems better than equivalent run-time checks.
Multi-catch solves certain *other* problems better than equivalent
many-catch. They are orthogonal, but the syntax is similar: *"into this
block, accept this type or this type or ...."*

I contend that this apparent similarity must be consistent, lest we earn
another sadness.

Reply via email to