Re: Boolean operators without commutators vs. ALL/ANY

From: Florian Pflug <fgp(at)phlo(dot)org>
To: Greg Stark <stark(at)mit(dot)edu>
Cc: Alvaro Herrera <alvherre(at)commandprompt(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Robert Haas <robertmhaas(at)gmail(dot)com>, PG Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Boolean operators without commutators vs. ALL/ANY
Date: 2011-06-20 10:55:42
Message-ID: 0C2FE18F-DFE0-452C-8FA1-4495CCD719EA@phlo.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Jun20, 2011, at 03:16 , Greg Stark wrote:
> On Fri, Jun 17, 2011 at 3:49 PM, Florian Pflug <fgp(at)phlo(dot)org> wrote:
>>> The regex is always to the right of the operator.
>>
>> Which is something you have to remember... It's not in any
>> way deducible from "foo ~ bar" alone.
>
> Except that it's always been this way, going back to perl4 or tcl or
> their predecessors. The regexp binding operator always has the regexp
> on the right.

Yeah. The strength of that argument really depends on one's
prior exposure to these languages, though...

>>>> How is that worse than the situation with "=~" and "~="?
>>>
>>> With =~ it is to the right, with ~= it is to the left.
>>
>> It's always where the tilde is. Yeah, you have to remember that.
>
> And when you get it wrong it will fail silently. No errors, just wrong results.

Yeah, but this is hardly the only case where you'll get
unintended results if you mix up operator names.

Now, one might argue, I guess, that mixing up "=~" and "~="
or more likely than mixing up, say, "~" and "~~". But ultimately,
whether or not that is highly dependent on one's personal background,
so we're unlikely to ever reach agreement on that...

> While I've never accidentally written /foo/ =~ $_ in perl I have
> *frequently* forgotten whether the operator is ~= or =~. Actually I
> forget that pretty much every time I start writing some perl. I just
> put whichever comes first and if I get an error I reverse it.

Yeah, the nice thing in perl (and ruby also, which is *my* background)
is that regexp's and strings are distinguished by the type system,
and also by the parser.

The latter (i.e. regexp literals enclosed by /../) probably isn't
desirably for postgres, but the former definitely is (i.e. distinguishing
regexp's and text in the type system). Please see the thread
"Adding a distinct pattern type to resolve the ~ commutator stalemate"
for the details of the proposal.

> I can see the temptation to make it symmetric but it's going to cause
> an awful lot of confusion.

I do believe that by adding a distinct type we can actually *reduce*
confusion. It makes "text ~ pattern" readable even for people who
don't intuitively know that the pattern always goes on the right.

best regards,
Florian Pflug

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Pavel Stehule 2011-06-20 11:19:22 Re: patch: plpgsql - remove unnecessary ccache search when a array variable is updated
Previous Message Simon Riggs 2011-06-20 10:23:07 Re: patch: plpgsql - remove unnecessary ccache search when a array variable is updated