Thread overview | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
August 27, 2008 precedence of cast | ||||
---|---|---|---|---|
| ||||
I was wondering about the precedence of the cast operator. By experimenting I found that it is less than . and more than +, but I was wondering if there isn't a place where this is exactly explained. A table with the precedence of all operators would be welcome :) thanks Fawzi |
August 27, 2008 Re: precedence of cast | ||||
---|---|---|---|---|
| ||||
Posted in reply to Fawzi Mohamed | Fawzi Mohamed wrote: > A table with the precedence of all operators would be welcome If a table is needed, it suggests itself to not rely on yourself and others to know the contents of that table. Use parens and everyone sees the intention. -manfred -- Maybe some knowledge of some types of disagreeing and their relation can turn out to be useful: http://blog.createdebate.com/2008/04/07/writing-strong-arguments/ |
August 27, 2008 Re: precedence of cast | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manfred_Nowak | On 2008-08-27 18:14:40 +0200, "Manfred_Nowak" <svv1999@hotmail.com> said: > Fawzi Mohamed wrote: > >> A table with the precedence of all operators would be welcome > > If a table is needed, it suggests itself to not rely on yourself and > others to know the contents of that table. Use parens and everyone sees > the intention. I agree that in general it is a good advice, but if you have an expression that you need to use often, some optimization is in order, because (being it common in your code) excessive parens just weight it down and, whoever looks at your code will have to understand it once, to then apply it in all cases. And anyhow, just for the sake of knowing it I would like someplace where I can look at it. :) Fawzi > > -manfred |
August 27, 2008 Re: precedence of cast | ||||
---|---|---|---|---|
| ||||
Posted in reply to Fawzi Mohamed | On Wed, 27 Aug 2008 20:32:57 +0400, Fawzi Mohamed <fmohamed@mac.com> wrote:
> On 2008-08-27 18:14:40 +0200, "Manfred_Nowak" <svv1999@hotmail.com> said:
>
>> Fawzi Mohamed wrote:
>>
>>> A table with the precedence of all operators would be welcome
>> If a table is needed, it suggests itself to not rely on yourself and
>> others to know the contents of that table. Use parens and everyone sees
>> the intention.
>
> I agree that in general it is a good advice, but if you have an expression that you need to use often, some optimization is in order, because (being it common in your code) excessive parens just weight it down and, whoever looks at your code will have to understand it once, to then apply it in all cases.
>
> And anyhow, just for the sake of knowing it I would like someplace where I can look at it. :)
>
> Fawzi
>> -manfred
>
>
That's generally a good idea to have such a table, to reduce number of trial and error, for example.
|
August 27, 2008 Re: precedence of cast | ||||
---|---|---|---|---|
| ||||
Posted in reply to Denis Koroskin | Denis Koroskin: > That's generally a good idea to have such a table, to reduce number of trial and error, for example. Having a reference table is positive, but even better is to design a language & programs (D) that usually don't need the programmer (or the person that reads the code) to read such table to understand what the code does. D follows the design of the C language in many things. C has lots of precedence rules, while a language like Ada has chosen to have much less Operator Precedence Levels, to simplify the work of the programmer, see point 4F here: http://www.adahome.com/History/Steelman/steeltab.htm This means that D may eventually choose to decrease its number of precedence levels to simplify it. On the other hand Python has something like 17 precedence levels: http://books.google.it/books?id=nEJ-jcYF2fMC&pg=PA97&lpg=PA97&dq=python+operator+precedence+rules&source=web&ots=3_tES429hg&sig=WiLW5C5JyNXTg1HyJssbM-pe1Ns&hl=en&sa=X&oi=book_result&resnum=1&ct=result#PPA96,M1 Bye, bearophile |
August 28, 2008 Re: precedence of cast | ||||
---|---|---|---|---|
| ||||
Posted in reply to Fawzi Mohamed | Reply to Fawzi,
> And anyhow, just for the sake of knowing it I would like someplace
> where I can look at it. :)
>
If you know how to read it, the spec is peppered with BNF and that is the authoritative source
|
August 28, 2008 Re: precedence of cast | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | "bearophile" <bearophileHUGS@lycoc.com> wrote in message news:g94oul$2mi5$1@digitalmars.com... > Denis Koroskin: >> That's generally a good idea to have such a table, to reduce number of trial and error, for example. > > Having a reference table is positive, but even better is to design a language & programs (D) that usually don't need the programmer (or the person that reads the code) to read such table to understand what the code does. > > D follows the design of the C language in many things. C has lots of precedence rules, while a language like Ada has chosen to have much less Operator Precedence Levels, to simplify the work of the programmer, see point 4F here: > > http://www.adahome.com/History/Steelman/steeltab.htm > > This means that D may eventually choose to decrease its number of precedence levels to simplify it. On the other hand Python has something like 17 precedence levels: > > http://books.google.it/books?id=nEJ-jcYF2fMC&pg=PA97&lpg=PA97&dq=python+operator+precedence+rules&source=web&ots=3_tES429hg&sig=WiLW5C5JyNXTg1HyJssbM-pe1Ns&hl=en&sa=X&oi=book_result&resnum=1&ct=result#PPA96,M1 > > Bye, > bearophile OT: is there anything about D that you _are_ satisfied with? |
August 28, 2008 Re: precedence of cast | ||||
---|---|---|---|---|
| ||||
Posted in reply to Fawzi Mohamed | Fawzi Mohamed wrote: > I was wondering about the precedence of the cast operator. > By experimenting I found that it is less than . and more than +, but I was wondering if there isn't a place where this is exactly explained. > A table with the precedence of all operators would be welcome :) I just use a C operator precedence table, D follows that: http://www.difranco.net/cop2220/op-prec.htm |
August 28, 2008 Re: precedence of cast | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | Jarrett Billingsley:
> OT: is there anything about D that you _are_ satisfied with?
There are many things I like of it, but finding and listing them all may require too much time, few of the most important things I like of it:
- the people of D community, because with few exceptions, most people seem intelligent, helpful, gentle, etc.
- the idea of putting program correctness first, avoiding several mistakes commonly done in C programs
- its templates
- for having a built-in GC.
And I like other things too:
- the idea of having built-in AAs and dynamic arrays
- its slicing syntax, partially
- how numbers can be written, 0b_0000_0000, 1_000_000, etc.
- nestable functions
- out/ref parameters
- Array bounds checking
- aliases
- the idea of being module-based
- static ifs, static asserts
- for having a bit of type inference, instead none at all
- the idea of having Contract Programming and built-in unit testing
- the idea of having built-in ddoc comments
That's why I use D when I can, instead of C++ or Cython.
But no language is perfect :-)
Bye,
bearophile
|
August 28, 2008 Re: precedence of cast | ||||
---|---|---|---|---|
| ||||
Posted in reply to Fawzi Mohamed | Fawzi Mohamed wrote:
> I was wondering about the precedence of the cast operator.
> By experimenting I found that it is less than . and more than +, but I was wondering if there isn't a place where this is exactly explained.
> A table with the precedence of all operators would be welcome :)
>
> thanks
> Fawzi
>
If you downloaded DMD, you can take a look at src\dmd\expression.c initPrecedences(). I don't paste it here because I don't know if I'm allowed to do so.
|
Copyright © 1999-2021 by the D Language Foundation