Struct-typing in Phobos

Jesse Phillips Jesse.K.Phillips+D at gmail.com
Tue Feb 4 22:31:01 PST 2014


On Tuesday, 4 February 2014 at 20:11:05 UTC, Chris Williams wrote:
> A person who is using Phobos has no option to switch to classes 
> when they find that they need polymorphic behavior, except by 
> copy-pasting into a new source file and revising the Phobos 
> code outside of Phobos.

I think this touches on why Manu is interested in final by 
default.

A type should be designed to be polymorphic. So if these were 
classes they'd be final anyway.

I don't have a good opinion on my own if that is the correct 
thing, but I certainly don't go around extending random classes.

You paint a fairly bad picture for using structs, but you haven't 
said anything that wasn't true. It seems to me that the reality 
is, most of the time you don't need those benefits. With the 
template constraints one doesn't need to inherit from your base 
class, they just need to implement the same behaviors.

As for the new programming not being familiar with template 
constraints. They are heavily used in D, both Phobos and third 
party libraries, they won't be able to avoid them. I'd say that 
even if using classes it is still better to write functions using 
template constraints (but I don't have any examples to back that 
up).


More information about the Digitalmars-d mailing list