baseName(path).startsWith(something)

H. S. Teoh hsteoh at quickfur.ath.cx
Thu Jan 9 15:58:10 PST 2014


On Thu, Jan 09, 2014 at 10:06:43PM +0000, monarch_dodra wrote:
> 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".

FWIW, I grew up learning 4 languages (and now I'm on my 5th), and I
still prefer baseName(path).startsWith(something). :-)


[...]
> 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.

<shameful confession>
I wrote a (winning!) IOCCC entry once, where the entire program consists
of a single *boolean* expression returned from main(). The ?: operator
was not used; branching was achieved by exploiting short-circuit
evaluation of && and ||, and looping was achieved by recursively calling
main().

That was only the tip of the iceberg of its abusiveness, though, because
there are absolutely no variables whatsoever in the program except for
the two arguments to main(), and malloc is never called (directly or
indirectly), yet the program manipulates arrays and other non-existent
variables without crashing. This is done by smashing its own stack upon
startup to "allocate" memory, using argv to point to the "allocated"
memory, and argc to keep track of what it's supposed to be doing since
main() recursively calls itself. :-P

Of course, the code itself has the usual IOCCC icing: y'know, the usual
abusive #define's, overuse of typecasts, and what-not, that causes the C
pretty printer to choke and crash when the would-be decipherer tries to
understand the code. But those are small feats compared with the boolean
expression stack-smashing memory allocator. :-P
</shameful confession>


T

-- 
There is no gravity. The earth sucks.


More information about the Digitalmars-d mailing list