why is "hello".writeln considered bad?
Mike Parker
aldacron at gmail.com
Fri Nov 20 07:50:45 UTC 2020
On Friday, 20 November 2020 at 07:39:10 UTC, norm wrote:
> I was reading some posts and this was presented as a snippet of
> code and was immediately flagged as bad practice.
>
Eh, I wouldn't quite put it that way. If we're thinking of the
same thread, one person said he thought it was a bad idea. That
doesn't make it bad practice. It's just his opinion. I think UFCS
is an awesome feature. And it's widely used in D code.
> I get some people don't like it but occasionally I prefer this
> syntax. It feels more declarative and fluent in style. Is there
> a good technical reason why it is bad practice, e.g. does it
> make it easier to write bugs? Or is it just what people are
> used to?
I think everyone has their own criteria for when to use UFCS. For
example, I don't generally write "foo".writeln myself, because I
don't think of writeln as being a property of strings. And that's
the lens through which I view UFCS: this operation is akin to a
property of this type. Other people might not see it that way,
and one (not me) could make an argument that this specific usage
is bad practice, but the feature itself rocks.
More information about the Digitalmars-d-learn
mailing list