Jump to page: 1 24  
Page
Thread overview
Pow operator precedence
Jan 13, 2012
bearophile
Jan 13, 2012
Gor Gyolchanyan
Jan 13, 2012
Mail Mantis
Jan 13, 2012
Manu
Jan 13, 2012
Don Clugston
Jan 13, 2012
Denis Shelomovskij
Jan 13, 2012
Mail Mantis
Jan 13, 2012
Manu
Jan 13, 2012
Stewart Gordon
Jan 13, 2012
Manu
Jan 13, 2012
bearophile
Jan 13, 2012
Manu
Jan 13, 2012
bearophile
Jan 14, 2012
Alvaro
Jan 13, 2012
Stewart Gordon
Jan 13, 2012
Somedude
Jan 13, 2012
Andrew Wiley
Jan 13, 2012
Russel Winder
Jan 13, 2012
Piotr Szturmaj
Jan 13, 2012
Mehrdad
Jan 13, 2012
Mehrdad
Jan 13, 2012
Matej Nanut
Jan 13, 2012
Manu
Jan 13, 2012
Stewart Gordon
Jan 13, 2012
Timon Gehr
Jan 13, 2012
Matej Nanut
Jan 13, 2012
Manu
Jan 14, 2012
Walter Bright
Jan 14, 2012
Mehrdad
Jan 14, 2012
Chad J
Jan 13, 2012
Manu
Jan 13, 2012
Grue
Jan 13, 2012
Manu
Jan 13, 2012
Nick Sabalausky
Jan 13, 2012
Grue
Jan 13, 2012
Stewart Gordon
Jan 13, 2012
Matej Nanut
Jan 14, 2012
Chad J
Jan 14, 2012
bearophile
January 13, 2012
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?

Bye,
bearophile
January 13, 2012
the problem is, that there are two popular use cases of this expression. One is plain old power expression and the other is writing scientific notations of numbers. I thing we should stick with the first use case, because at least for literals we already have scientific notation.

On Fri, Jan 13, 2012 at 4:48 PM, bearophile <bearophileHUGS@lycos.com> 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?
>
> Bye,
> bearophile



-- 
Bye,
Gor Gyolchanyan.
January 13, 2012
2012/1/13 bearophile <bearophileHUGS@lycos.com>:
> 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?
>
> Bye,
> bearophile

My fail =)
I guess that's the right behaviour, but for C++ programmer it's rather
confusing that binary operator precedes unary minus.
Don't see a way how such mistake may be helped to avoid though.
January 13, 2012
On 13 January 2012 14:48, bearophile <bearophileHUGS@lycos.com> 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?


January 13, 2012
Le 13/01/2012 13:48, bearophile a écrit :
> 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?
> 
> Bye,
> bearophile

Maybe a compiler warning ?
January 13, 2012
On Fri, Jan 13, 2012 at 7:47 AM, Manu <turkeyman@gmail.com> wrote:
> On 13 January 2012 14:48, bearophile <bearophileHUGS@lycos.com> 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.
January 13, 2012
On Fri, 2012-01-13 at 08:09 -0600, Andrew Wiley wrote:
> On Fri, Jan 13, 2012 at 7:47 AM, Manu <turkeyman@gmail.com> wrote:
> > On 13 January 2012 14:48, bearophile <bearophileHUGS@lycos.com> 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.

The problem here is the conflict introduced by allowing -10 to be the application of the unary minus operator to the positive value 10 instead of being a representation of the negative integer value -10.  BODMAS covers everything.


-- 
Russel. ============================================================================= Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder@ekiga.net 41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel@russel.org.uk London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder


January 13, 2012
On 13/01/12 14:47, Manu wrote:
> On 13 January 2012 14:48, bearophile <bearophileHUGS@lycos.com
> <mailto:bearophileHUGS@lycos.com>> 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?

Originally it worked the other way, but bearophile complained about it, so it got changed to this way <g>.

January 13, 2012
13.01.2012 19:56, Don Clugston пишет:
> On 13/01/12 14:47, Manu wrote:
>> On 13 January 2012 14:48, bearophile <bearophileHUGS@lycos.com
>> <mailto:bearophileHUGS@lycos.com>> 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?
>
> Originally it worked the other way, but bearophile complained about it,
> so it got changed to this way <g>.
>

Current behaviour is uncomfortable for me too. What was the reason of this change?
January 13, 2012
bearophile 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.)

Why x ^^ y is considered _unary_ expression?
« First   ‹ Prev
1 2 3 4