On Saturday 23 November 2013 18:55:00 Marcos Douglas wrote:
> On Sat, Nov 23, 2013 at 8:20 AM, Martin Schreiber <mse00...@gmail.com> 
wrote:
> > On Thursday 21 November 2013 08:32:57 Martin Schreiber wrote:
> >> ...
> >
> > sub strfunc2(const avalue: msestring,para: boolean): msestring;
> > begin
> >  if para then
> >   return 'The not string result';
> >  end;
> >
> >  := 'The string result: '+avalue;
> >
> > end;
> > "
>
> The 'return' returned?  :)
>
Additional returns always were possible, the last mandatory 'return' 
before 'end' has been replaced by the assignment.

> Why not this simple syntax?
> "
> sub strfunc2(const avalue: msestring,para: boolean): msestring;
> begin
>  if para then
>   return 'The not string result';
>  end;
>  return 'The string result: '+avalue;
> end;
> "
>
> The 'return' keyword is simple, clean and readable... think about it,
> please.
>
The last return is mandatatory and at fix position the others are not. I don't 
like that. It should be possible to program without 'return' completely 
because 'return' is dangerous if one overlooks it.

"
var
 globflag: bool8;

sub test(a: bool8, b: bool8, c: bool8): int32;
var
 result: int32;
begin
 result:= 0;     //initilization
 if a then       //long deeply nested processing
  result:= 123;
 else
  if b and c then
   result:= -100;
  else
   result:= 88;
  end;
 end;

 globflag:= result > 0; //terminating statement, cleanup

 := result;
end;
"
After some time one needs to fix a bug:
"
begin
 result:= 0;     //initilization
 if a then       //long deeply nested processing
  result:= 123;
 else
  if b and c then
   result:= -100;
  else
   if not (a or b) then
    return 1000; //aua, the globflag will not be set!
   else
    result:= 88;
   end:
  end;
 end;

 globflag:= result > 0; //terminating statement, cleanup

 := result;
end;
"

So it should be possible to completely work without 'return' statement 
(or 'exit' in Delphi). In order to cancel operation it is often better to use 
a goto.

"
var
 globflag: bool8;

sub test(a: bool8, b: bool8, c: bool8): int32;
var
 result: int32;
label
 abort;
begin
 result:= 0;     //initilization
 if a then       //long deeply nested processing
  result:= 123;
 else
  if c then
   goto abort;   //abort processing
  end;
  if b and c then
   result:= -100;
  else
   result:= 88;
  end;
 end;

abort:
 globflag:= result > 0; //terminating statement, cleanup

 := result;
end;
"

Martin

------------------------------------------------------------------------------
Shape the Mobile Experience: Free Subscription
Software experts and developers: Be at the forefront of tech innovation.
Intel(R) Software Adrenaline delivers strategic insight and game-changing 
conversations that shape the rapidly evolving mobile landscape. Sign up now. 
http://pubads.g.doubleclick.net/gampad/clk?id=63431311&iu=/4140/ostg.clktrk
_______________________________________________
mseide-msegui-talk mailing list
mseide-msegui-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mseide-msegui-talk

Reply via email to