A nice D coding pattern
Ali Çehreli via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Nov 25 11:32:59 PST 2014
On 11/25/2014 10:58 AM, Tobias Pankrath wrote:
>> void main() {
>> // Created at compile-time.
>> enum something = "........".Foo;
>>
>
> I don't think we should encourage UFCS with typenames or uppercase
> names. If anything, it does not provide any benefit in this case and
> Foo(".....") is much more clearer without any syntactical overhead.
Agreed.
A guideline that makes sense to me is "UFCS is for when the function can
be thought of as a special operation on its first parameter."
After seeing bearophile's code, I thought that even the following was
better than UFCS:
"hello".to!Foo
It only then feels like a special operation on "hello". (I haven't tried
the code but I think it works.)
However, I would still use the Foo("hello").
Ali
More information about the Digitalmars-d-learn
mailing list