baseName(path).startsWith(something)

monarch_dodra monarchdodra at gmail.com
Thu Jan 9 14:06:43 PST 2014


On Thursday, 9 January 2014 at 21:01:05 UTC, Martin Nowak wrote:
> On Thursday, 9 January 2014 at 19:06:19 UTC, monarch_dodra 
> wrote:
>>
>> ...is that a question?
>>
> I just watend to share the discovery.
> I always wondered what bothers me about some UFCS overuse and 
> it's the sentence part that matters.
>
>> I find the first is most readable. Well, (IMO) with added 
>> parens too:
>>
>> if (path.baseName().startsWith(something))
>>    doThis();
>>
> But how do speak that out in your head?
> The other one is, if the basename of path starts with something 
> do this.

I guess you have to have a "lingual" thinking pattern? 
*Personally*, that's not really my case. I grew up learning 3 
different languages, so that could have helped? If you think of 
it more in terms of "ideas" than "words", I find the first 
version makes more sense. You start with a "subject", and you 
apply a series of "verbs" to said subject.
-Start with "path".
-Take it's "baseName".
-Does that "start with something"?
I see that as "three atomic sentences".

I understand your version more like:
-start with the "basename of path" or start with "path's 
basename".
-Does that "start with something"?
Kind of the same think, but the subject is now a complex 
operation in itself.

I guess it depends on *what* you want to put the emphasis on, and 
how you relate to the objects you are operating on.

--------

At the end of the day though, I guess it's a matter of style. For 
me, UFCS is really about being able to chain operations left to 
right: subject=>verb=>verb.

If anything, I hate it when the first function takes several 
arguments, but the sum of all arguments are all "subjects" in 
their own right. For example "iota(low, high).array()". For me, 
the "subject" is the range "(low, high)". I really wish I could 
write that as:
(low, high).iota().array();

I find it makes sense that way...

Also, I think "UFCS abuse" (which is nothing but *style*) is 
nothing compared to some of the "functional" abuse I've seen when 
when users to write an entire program as a 1-liner.


More information about the Digitalmars-d mailing list