Re: Boolean operators without commutators vs. ALL/ANY

Поиск
Список
Период
Сортировка
От Florian Pflug
Тема Re: Boolean operators without commutators vs. ALL/ANY
Дата
Msg-id 0C2FE18F-DFE0-452C-8FA1-4495CCD719EA@phlo.org
обсуждение исходный текст
Ответ на Re: Boolean operators without commutators vs. ALL/ANY  (Greg Stark <stark@mit.edu>)
Ответы Re: Boolean operators without commutators vs. ALL/ANY
Список pgsql-hackers
On Jun20, 2011, at 03:16 , Greg Stark wrote:
> On Fri, Jun 17, 2011 at 3:49 PM, Florian Pflug <fgp@phlo.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



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Simon Riggs
Дата:
Сообщение: Re: patch: plpgsql - remove unnecessary ccache search when a array variable is updated
Следующее
От: Pavel Stehule
Дата:
Сообщение: Re: patch: plpgsql - remove unnecessary ccache search when a array variable is updated