Trivial (but not bikeshed please) question of style…
Jonathan M Davis via Digitalmars-d
digitalmars-d at puremagic.com
Tue Oct 28 02:22:37 PDT 2014
On Tuesday, October 28, 2014 08:15:44 Russel Winder via
Digitalmars-d wrote:
> I need to know the community view on D idiom regarding UFCS in
> one
> particular case (mostly because I am doing a presentation and
> need to
> know which one to put on the slides).
>
> Given:
>
> import std.concurrency: Tid, send
>
> and some code that spawns, then in a spawned task should I
> write:
>
> parent.send(result)
>
> or:
>
> send(parent, result)
>
> as being idiomatic D code?
>
> This has all the appearance of a potential troll, but that is
> not my
> intention, I really do need to know which the community feels is
> idiomatic D.
I don't see how it matters much. Both are perfectly valid. Plenty
of folks
like UFCS, but it doesn't get used everywhere. The primary,
technical benefit
of UFCS (aside from pure personal preference) is that in generic
code, it
allows for member functions to override the more generic free
functions and
specialize their behavior. Code that wants that should use UFCS.
Code that
doesn't want that, should avoid UFCS. Also, code that needs to
disambiguate
between free functions (due to conflicting imports) needs to
either avoid UFCS
or use aliases to get around the conflict. For all other code,
it's a matter
of personal preference. I'd say that the only thing that makes
UFCS more
D-like beyond that is simply the fact that most other languages
can't do it
(especially D's primary competitors), but that isn't really a
technical
benefit so much as something that's simply different about D.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list