On Sun, Nov 24, 2013 at 5:46 AM, Martin Schreiber <mse00...@gmail.com> wrote:
> 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.

But if 'return' exists, why I will use ':= value'??? Two ways to do the same?

>> 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.

So, go back to 'RESULT' variable. ;-)

> "
> ...
> "
> 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.

You can not protect the programmers using this. Think. Even if you use
'return', 'result', whatever... if the programmer put a Exit on your
code the same error will happen! Bad programmers do it. They forget to
create some object, don't destroy them, etc. Who cares! No language
can protect all source.

> "
> 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

Pardon me but your algorithm -- I know this is just an example -- is
wrong. You do not need to use GOTO.
Using the real Pascal:
"
begin
  result:= 0;     //initilization
  if a then       //long deeply nested processing
    result:= 123
  else
  begin
    if b and c then
      result:= -100
    else
    begin
      if not (a or b) then
      begin
        result := 1000;
        globflag:= true;
        exit;
      end
      else
        result:= 88;
    end;
  end;
  globflag:= result > 0;
end;
"

--
Marcos Douglas

------------------------------------------------------------------------------
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