Re: Labels (was: Call by name)

2018-02-16 Thread Jon Perryman
Using numbers for labels is certainly a good way to discourage goto's. 
Eliminating GOTO sure makes code a lot more readable and maintainable.

Assembler toolkit has a set of structured programming macro's that greatly 
reduces the need for branch labels. I hated macro's that required branch labels 
(e.g. EOF). Structured macros greatly improve maintainability.

Macros only have goto logic so we are out of luck there.

Sadly, in a product dev environment, every line changed was considered a risk 
and must be thoroughly tested. Most vendors won't allow developer's to make 
such massive changes unless there is a real business need.

Regards, Jon.

Bernd Oppolozer wrote:

 he was not courageous enough
to leave goto and labels out of the language. So he came to this decision,
to allow numbers as labels only, and to force them to be declared before 
using
them.

So: if you forbid branches aka gotos, you don't need alphanumeric labels;
you don't need labels at all.


Re: Labels (was: Call by name)

2018-02-16 Thread Paul Gilmartin
On 2018-02-16, at 11:33:05, Bernd Oppolzer wrote:

> IMO, Niklaus Wirth ... came to this decision,
> to allow numbers as labels only, and to force them to be declared before using
> them.
> 
The prior declaration is (almost) necessary for single-pass compilation.

We added identifiers as labels, BREAK, and CONTINUE.

-- gil

Labels (was: Call by name)

2018-02-16 Thread Bernd Oppolzer

IMO, Niklaus Wirth, when designing Pascal, decided to discourage the
use of goto as much as possible. OTOH, he was not courageous enough
to leave goto and labels out of the language. So he came to this decision,
to allow numbers as labels only, and to force them to be declared before 
using

them.

When I started working on the Stanford Pascal compiler, it had 6.000 
lines of
code (ca.) and many labels. Because they are often local to a procedure, 
they

have numbers like 1, 2 or 10. They were used to leave loops (aka break)
or restart loops (aka continue) or to leave procedures or functions (aka 
return).

I added BREAK, CONTINUE and RETURN as normal control statements,
much the way as C has it. This way, many labels (and gotos) could be 
eliminated.

The compiler today has about 19.000 lines and only six goto statements.
(six different labels, 3 times label 1; - 3 times label 10;).

I could sure get rid of these remaining goto's, too.

This, for example, could be immediately replaced by CONTINUE; a no-brainer:

 while SY = SYCOMMA do
   begin
 INSYMBOL ;
 CONSTANT ( FSYS + [ SYCOMMA , SYRPARENT ] , LSP1 ,
    LVAL ) ;
 VARTS := VARTS + 1 ;

(*)
 (*   CHECK TO INSERT HERE:   *)
 (*   IS CONSTANT IN TAGFIELDTYPE RANGE   *)
(*)

 if LSP = NIL then
   ERROR ( 158 )
 else
   if LSP -> . FORM <> TAGFLD then
 ERROR ( 162 )
   else
 if LSP -> . TAGFIELDP <> NIL then
   if IS_CARRAY ( LSP1 ) or IS_STDTYPE ( LSP1 ,
   'R' ) then
 ERROR ( 159 )
   else
 if COMPTYPES ( LSP -> . TAGFIELDP -> .
 IDTYPE , LSP1 ) = 1 then
   begin
 LSP1 := LSP -> . FSTVAR ;
 while LSP1 <> NIL do
   with LSP1 -> do
 if VARVAL . IVAL = LVAL . IVAL
 then
   begin
 LSIZE := SIZE ;
 LSP := SUBVAR ;
 goto 1
   end (* then *)
 else
   LSP1 := NXTVAR ;
 LSIZE := LSP -> . SIZE ;
 LSP := NIL ;
   end (* then *)
 else
   ERROR ( 116 ) ;
 1 :

   end (* while *) ;

Back to ASSEMBLER:

at my former customer's site, we used a home-grown (and very powerful) 
version
of SP macros exclusively. The use of branch instructions was forbidden, 
and every time
an old module containing them needed maintenance, we removed them and 
inserted
SP macros. There were even test tools that used the SP macros as points 
of control
(breakpoint candidates for home grown debugging tools etc.); the control 
flow was

monitored based on the branches defined by these SP macros (for example:
how often was the THEN branch of an IF executed in a certain test run 
compared

to the ELSE branch etc.). The same tool was used for PL/1, too.

So: if you forbid branches aka gotos, you don't need alphanumeric labels;
you don't need labels at all.

It seems somehow strange to me that we talk about OO concepts in this 
thread,
and at the same time we talk about goto statements. This has absolutely 
nothing
to do with languages, but with modern or antique software development 
paradigms.


Kind regards

Bernd



Am 16.02.2018 um 06:44 schrieb Jon Perryman:

Seymour is talking about maintainable large amounts of code should have at 
least alphanumeric labels. Numeric labels can be confusing unless you have a 
really good numbering scheme. I suspect most programmers would not use numeric 
labels unless forced.
Regards, Jon.
 On Thursday, February 15, 2018 7:47 PM, Robin Vowels  
wrote:
  


  From: "Seymour J Metz" 
Sent: Friday, February 16, 2018 3:58 AM



Numeric labels are okay for write-only code. They are very bad in code that has 
to be maintained.

Eh?

Labels are labels.

It doesn't matter whether they are alphabetic, alphanumeric, or numeric.

---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus