On 13 January 2012 16:09, Andrew Wiley <[email protected]> wrote:

> On Fri, Jan 13, 2012 at 7:47 AM, Manu <[email protected]> wrote:
> > On 13 January 2012 14:48, bearophile <[email protected]> wrote:
> >>
> >> This is the third time I see people trip on power operator precedence:
> >> http://d.puremagic.com/issues/show_bug.cgi?id=7268
> >>
> >> Some people expect this:
> >> (-10 ^^ 2)
> >> To be 100 instead of -100
> >> (Note: Python here uses the same operator precedences.)
> >>
> >> Do you think it's worth (and possible) to help D programmers avoid this
> >> mistake in their code?
> >
> >
> > I would certainly have made this mistake if I tried it. And knowing this
> > information will not cause me to do it properly, it will simply make me
> > question my code, and become very suspicious every time I ever use the
> > operator (ie. I will never understand the proper precedence, I don't
> think
> > it makes sense).
> > I'm fairly amazed it's not the other way around... what's the logic
> behind
> > this?
>
> The logic is that the precedence in the language matches the
> precedence of a written equation.
>

But the operator looks nothing like the written equation... nothing at all
like the written equation.
Perhaps D could support the unicode characters '²' '³' or 'ª' as kinda
handy operators. But to me, the operator looks NOTHING like maths notation,
and it would never have occurred to me that the operator was trying to
emulate maths notation (and by extension, its precedence rules).
I'd be interested to see a poll, and how many people see it one way or the
other...

Reply via email to