So why was typedef bad?

Dicebot via Digitalmars-d digitalmars-d at puremagic.com
Thu Sep 1 04:57:17 PDT 2016


On 08/31/2016 04:44 PM, Ethan Watson wrote:
> http://dlang.org/deprecate.html#typedef
> 
> "typedef is not flexible enough to cover all use cases. This is better
> done with a library solution."
> 
> [Citation needed]
> 
> What use cases is it not flexible enough for?

It has unadjustable semantics that were both more restrictive than alias
and at the same time not restrictive enough to introduce completely new
type. Wasn't supposed to be compatible with base type but sometimes did,
with no reasons other than "historical".

In my own experience creating dedicated struct type is always superior
to typedef if you want to go for type safety. It can start with simple
`alias this` struct to have permissive semantics similar to old typedef
and later changed to operator overloading for more fine tuned control.
It can also provide methods for verified conversion between base type
and new domain type.

And if type safety is not a goal, there isn't much point in all the
typedef restrictions and alias should do as well.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 455 bytes
Desc: OpenPGP digital signature
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20160901/08093f38/attachment.sig>


More information about the Digitalmars-d mailing list