Yeah, for our application I want to write very explicit code that's fairly self-explanatory as part of a tutorial so I chose i := i + 1. Even if they end up using INC(i) down the road, INC(i) isn't necessarily self-explanatory for a novice user without assembly experience *(like me for example)*. It's a small consideration though - I was mostly curious if they are compiled differently best, Jeff
My understanding is that if an experienced Python programmer just wanted to increment an integer variable they wouldn't write i = i + 1, instead they would write:
i += 1
Similarly C++ programmers would write
i++
INC(i) is the best match in Oberon for either of these statements.
I suspect they would be unhappy if you told them to rewrite this in Python / C++ as
i = i + 1
so they would see this as a disadvantage if they were told that they had to write it this way in Oberon.
Regards, Chris Burrows CFB Softwarehttps://www.astrobe.com
On Tue, May 4, 2021, at 10:59 PM, Jeff Maggio wrote:
[...] Even if they end up using INC(i) down the road, INC(i) isn't necessarily self-explanatory for a novice user without assembly experience *(like me for example)*.
It's a small consideration though - I was mostly curious if they are compiled differently
Every Pascal trained guy know very well what INC() does and this procedure isn't usually introduced with an assembly background but as a shortend for i := i + 1 (that is longer to type, especially if the variable is longer than "i"). I would have said - without Pascal experience :-) My explanation of INC() was targeted to advanced programmers for a deeper understanding, especially if you read Pascal-oriented compilers books or advanced Pascal programming books. Pascal compilers are simple and fast and often is better to use a procedure or function that emits a particular asm code instead of using complicated techniques to parse an expression. I guess most Pascal programmers aren't aware of this. Of course modern optimizing compilers emit the inc opcode in the case of i := i + 1, but with INC() you are sure of that in every Pascal compiler. -- Diego Sardina
INC/DEC, like i++ / i+= and i-- / i-= are also useful to show intent - for example when I'm reviewing someone else's code that says i := i + 1; j := j + 1; k := j + 1; it makes me wonder... :) No language or system is completely self-evident, but the idioms used often are reinforced by that use and learned quite quickly, and we move on. No need to leverage familiarity with another language at all in those cases. It's the subtleties that get 'em every time, like the equals sign in curly-bracket languages. Are we up to four in a row yet? :) Cheers Paul
it's what you get used to. For decades I was comfortable with Pascal syntax. Now it looks klunky & I want syntax-coloring to distinguish it's function/arguments/result. IMO `poplog` has the clearest syntax: "a+1->b" is better than "b :=a+1" Also: M$pook's Pastel colors & balerina-blue text is the worst; compared to BLACK background with bold syntax-colored text. --- CRG. On 5/4/21, Paul Reed <paulreed@paddedcell.com> wrote:
INC/DEC, like i++ / i+= and i-- / i-= are also useful to show intent - for example when I'm reviewing someone else's code that says
i := i + 1; j := j + 1; k := j + 1;
it makes me wonder... :)
No language or system is completely self-evident, but the idioms used often are reinforced by that use and learned quite quickly, and we move on. No need to leverage familiarity with another language at all in those cases. It's the subtleties that get 'em every time, like the equals sign in curly-bracket languages. Are we up to four in a row yet? :)
Cheers Paul -- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
On Thu, May 6, 2021, at 3:57 AM, eas lab wrote:
it's what you get used to. For decades I was comfortable with Pascal syntax. Now it looks klunky & I want syntax-coloring to distinguish it's function/arguments/result. IMO `poplog` has the clearest syntax: "a+1->b" is better than "b :=a+1"
Yes, older languages had this syntax. This is also mentioned in Wirth's compiler book but left as exercise. I would like to discuss it with you (all) since I wasn't sure of my answers. ---- 10.2. Had the assignment statement in Oberon been defined in a form where the assigned expression occurs to the left of the variable, that is for example by the form e =: v, would compilation of assignments be simpler in any way? 10.3. Consider the introduction of a multiple assignment in Oberon of the form e =: x0 =: x1 =: ... =: xn. Implement it. Does the definition of its semantics present any problems? ---- My answer for the first is that it simplifies the code generation for the assignment since it follows the flow and in the second I don't see any problems in its semantics. In general I see only advantages in both for lexing, parsing and code generation. What are your answers? -- Diego Sardina
I see it the same. But I would prefer -> iso =: Jörg Am 07.05.21, 14:44 schrieb "Oberon im Auftrag von Diego Sardina" <oberon-bounces@lists.inf.ethz.ch im Auftrag von dsar@eml.cc>: On Thu, May 6, 2021, at 3:57 AM, eas lab wrote: > it's what you get used to. > For decades I was comfortable with Pascal syntax. > Now it looks klunky & I want syntax-coloring to distinguish it's > function/arguments/result. > IMO `poplog` has the clearest syntax: > "a+1->b" is better than "b :=a+1" Yes, older languages had this syntax. This is also mentioned in Wirth's compiler book but left as exercise. I would like to discuss it with you (all) since I wasn't sure of my answers. ---- 10.2. Had the assignment statement in Oberon been defined in a form where the assigned expression occurs to the left of the variable, that is for example by the form e =: v, would compilation of assignments be simpler in any way? 10.3. Consider the introduction of a multiple assignment in Oberon of the form e =: x0 =: x1 =: ... =: xn. Implement it. Does the definition of its semantics present any problems? ---- My answer for the first is that it simplifies the code generation for the assignment since it follows the flow and in the second I don't see any problems in its semantics. In general I see only advantages in both for lexing, parsing and code generation. What are your answers? -- Diego Sardina -- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
On 2021-05-07 14:38, Diego Sardina wrote:
On Thu, May 6, 2021, at 3:57 AM, eas lab wrote:
IMO `poplog` has the clearest syntax: "a+1->b" is better than "b :=a+1" [...] In general I see only advantages in both for lexing, parsing and code generation.
What are your answers?
With the assigned variable to the right, the programmer needs to visually scan the entire line (or maybe more than one line) to find out what kind of statement it is. When the assigned variable comes first, the assignment symbol is close to the beginning of the line which in my opinion is clearer. -- August
On Sun, May 9, 2021, at 3:46 PM, August Karlstrom wrote:
With the assigned variable to the right, the programmer needs to visually scan the entire line (or maybe more than one line) to find out what kind of statement it is. When the assigned variable comes first, the assignment symbol is close to the beginning of the line which in my opinion is clearer.
I guess the viewpoint is the compiler in those exercises, not the programmer. -- Diego Sardina
If you've come up via hardware & asm you KNOW that left-to-right=> corresponds to REAL/ACTUAL sequence of events. Ie. for: C := A + B : <A is accessed first & C is accessed last> hence: A + B -> C is logical. OTOH: "Let C = A + B" corresponds to: C = FunctionRandoniser(A,B) where the complexity of the Function is hidden, and the result is emphasised. ---CRG. On 5/9/21, Diego Sardina <dsar@eml.cc> wrote:
On Sun, May 9, 2021, at 3:46 PM, August Karlstrom wrote:
With the assigned variable to the right, the programmer needs to visually scan the entire line (or maybe more than one line) to find out what kind of statement it is. When the assigned variable comes first, the assignment symbol is close to the beginning of the line which in my opinion is clearer.
I guess the viewpoint is the compiler in those exercises, not the programmer.
-- Diego Sardina -- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
Jeff Just as an example, find below the output of the RISC5 compiler: The statements “i := i+1;” and “INC(i);” generate exactly the same output, namely LDW R0 SP 4 load the local variable “i” (is at position 4 on the stack) ADD R0 R0 1 add 1 STW R0 SP 4 store register to local variable The statement “a[n] := a[n] + 1;” generates ; address of a[n] for LHS LDW R0 SP 8 load “n” (at position 8 on stack) SUB R1 R0 30 check array limit (in my case ARRAY 30 OF INTEGER) BLHI MT trap if outside LSL R0 R0 2 multiply “n” with size of INTEGER ADD R0 SP R0 add frame pointer ; address a[n] for RHS LDW R1 SP 8 load “n” (at position 8 on stack) SUB R2 R1 30 compare with upper limit of array BLHI MT trap if outside LSL R1 R1 2 multiply “n” with size of INTEGER ADD R1 SP R1 add frame pointer ; add and store LDW R1 R1 12 12 is offset of the array “a” ADD R1 R1 1 STW R1 R0 12 An optimizing compiler could detect, that ADR(a[n]) is already in R0 and could skip the second calculation for R1. But NW’s compiler does not do that. In contrast “INC(a[n]);” is a little shorter and hence faster, as you have to calculate the address only once ; address of a[n] LDW R0 SP 8 SUB R1 R0 30 BLHI MT LSL R0 R0 2 ADD R0 SP R0 ADD R0 R0 12 offset of a ; add and store LDW R1 R0 0 ADD R1 R1 1 STW R1 R0 0 br Jörg Von: Oberon <oberon-bounces@lists.inf.ethz.ch> im Auftrag von Jeff Maggio <jmaggio14@gmail.com> Antworten an: ETH Oberon and related systems <oberon@lists.inf.ethz.ch> Datum: Dienstag, 4. Mai 2021 um 23:00 An: <oberon@lists.inf.ethz.ch> Betreff: [Oberon] INC(i) vs i := i + 1 Yeah, for our application I want to write very explicit code that's fairly self-explanatory as part of a tutorial so I chose i := i + 1. Even if they end up using INC(i) down the road, INC(i) isn't necessarily self-explanatory for a novice user without assembly experience (like me for example). It's a small consideration though - I was mostly curious if they are compiled differently best, Jeff My understanding is that if an experienced Python programmer just wanted to increment an integer variable they wouldn't write i = i + 1, instead they would write: i += 1 Similarly C++ programmers would write i++ INC(i) is the best match in Oberon for either of these statements. I suspect they would be unhappy if you told them to rewrite this in Python / C++ as i = i + 1 so they would see this as a disadvantage if they were told that they had to write it this way in Oberon. Regards, Chris Burrows CFB Software https://www.astrobe.com -- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
participants (6)
-
August Karlstrom -
Diego Sardina -
eas lab -
Jeff Maggio -
Joerg -
Paul Reed