OT (Was: Re: What's the proper way to use std.getopt?)

Jonathan M Davis newsgroup.d at jmdavisprog.com
Tue Dec 12 06:29:05 UTC 2017


On Monday, December 11, 2017 15:38:44 H. S. Teoh via Digitalmars-d-learn 
wrote:
> On Mon, Dec 11, 2017 at 11:35:53PM +0000, Seb via Digitalmars-d-learn
> wrote: [...]
>
> > D style would be to use sth. like this (instead of try/catch):
> >
> > ```
> > scope(failure) {
> >
> >   e.msg.writeln;
> >   1.exit;
> >
> > }
> > ```
>
> Frankly, much as I love UFCS syntax, I think this is taking it a little
> too far.  Maybe I'm just old-fashioned, but I still find `exit(1)` much
> more readable than `1.exit`. Ditto for the writeln.

Clearly, there's quite a range of what folks like or find acceptable.
Personally, I never drop the parens unless it makes sense to treat the
function like a property, so even if I were doing something like Seb here,
it would be

e.msg.writeln();
1.exit();

but like you, I wouldn't use UFCS here. I don't know exactly what the line
is for me though; some functions just don't feel right with UFCS, and others
are perfectly fine. I think that part of it is probably whether the function
returns. I'm unlikely to use UFCS if the function is void like these are.
For whatever reason, using UFCS with something like writeln or exit just
seems really wrong to me. But then again, I also think that it feels really
wrong to do something like 42.msecs or 42.msecs(), and that _does_ return a
value. Maybe it's because it feels like a constructor to me, and you don't
use UFCS with constructors. I don't know. I don't know how logical or
consistent my reasoning is with when to use UFCS, since I've never sat down
and studied it. Sometimes, it feels perfectly reasonable, and other times,
it just feels really wrong.

Either way, clearly, different folks have a different level of tolerance or
liking for UFCS in various circumstances.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list