1. private routines

I'm not sure if this was what Bernie Ryan had been asking about.. but I'm
gonna ask this anyway.

I ask that Eu supports routines within routines (whether funcs, procs or
types). This means that we would have global, local AND private routines.

-- Pseudocode example ahead:
function local_routine()
    procedude private_routine()
        -- code here
    end procedure
    -- code here
    -- code here
end function

I'd like this because sometimes I have to write lots of repeated code for
just one routine. The routine gets pretty long and less readable.

Do you guys agree?


______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com

new topic     » topic index » view message » categorize

2. Re: private routines

> Do you guys agree?

Why can't you use local routines to shorten yor code ?
There is a namespace problem, but this aint it.
Local routines work fine, as long as only those global routines, which were
directly requested are accesable.

Ralf

new topic     » goto parent     » topic index » view message » categorize

3. Re: private routines

On Sun, 16 May 1999 09:27:57 GMT, Lionel Wong <eljay98 at HOTMAIL.COM> wrote:

>I ask that Eu supports routines within routines (whether funcs, procs or
>types). This means that we would have global, local AND private routines.
>
>I'd like this because sometimes I have to write lots of repeated code for
>just one routine. The routine gets pretty long and less readable.
>
>Do you guys agree?
>
Pascal allows this. In the around 500,000 lines of pascal
I have written, I think I used this (private routine) once
or twice. I can't see that it simplifies things in any way.

Perhaps you should re-examine the structure of your code.
There's usually a better way that is not at first obvious.

I generally try to keep all routines to < 50 lines of code
(2 screens worth). That includes the "main". Whenever I
exceed those limits, I know I am writing poor, hacked, and
difficult to maintain code.

So no, I would prefer for Rob to work on better
namespacing, which is a more universal solution to this,
and other problems.


Regards,
Irv

new topic     » goto parent     » topic index » view message » categorize

4. Re: private routines

>Why can't you use local routines to shorten yor code ?
>There is a namespace problem, but this aint it.
>Local routines work fine, as long as only those global routines, which were
>directly requested are accesable.
>
>Ralf

There are times when "private routines" would be convenient.. like:

function foo( )
  atom a, b, c
  a = 1
  b = 2
  procedure bar( )
    c = a + b
  end procedure
  ...
end function

I'm so sorry I can't come up with a better (but *simple*) example... have to
resort to this lame one ..! :/


______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com

new topic     » goto parent     » topic index » view message » categorize

5. Re: private routines

> There are times when "private routines" would be convenient.. like:

The example shows what you want to do.
I already knew this 'primal' example. Precisely what are the benefits compared
to this syntax:

atom a, b, c

function foo ()
    a = 1
    b = 2
    ..
end function

procedure bar ()
    c = a + b
end procedure


Your syntax:
> function foo( )
>   atom a, b, c
>   a = 1
>   b = 2
>   procedure bar( )
>     c = a + b
>   end procedure
>   ...
> end function

new topic     » goto parent     » topic index » view message » categorize

6. Re: private routines

Ralf Nieuwenhuijsen wrote:

>The example shows what you want to do.
>I already knew this 'primal' example. Precisely what are the benefits
>compared to this syntax:
>
>atom a, b, c
>
>function foo ()
>     a = 1
>     b = 2
>     ..
>end function
>
>procedure bar ()
>     c = a + b
>end procedure

Ralf, if bar() is to be called from foo() (as I suppose from looking at the
"private routine" example) then bar() would need to be declared first. I
suspect that's what you intended anyway.

I do, however, think that it's more readable to have them separate instead
of one inside of another.

If EU allowed nested routines it WOULD be more CONVENIENT to code on the fly
this way but would encourage bad programming practices (IMHO).

Lewis Townsend.


_______________________________________________________________
Get Free Email and Do More On The Web. Visit http://www.msn.com

new topic     » goto parent     » topic index » view message » categorize

7. Re: private routines

Ralf


His example's procedure only has scope with in the function
in other words private outside of his function
That would be a benifit.

bernie

Ralf wrote :


>>> There are times when "private routines" would be convenient.. like:

..The example shows what you want to do.
..I already knew this 'primal' example. Precisely what are the benefits
..compared to this syntax:

..atom a, b, c

..function foo ()
..    a = 1
..    b = 2
    ..
..end function

..procedure bar ()
..    c = a + b
..end procedure


..Your syntax:
> function foo( )
>   atom a, b, c
>   a = 1
>   b = 2
>   procedure bar( )
>     c = a + b
>   end procedure
>   ...
> end function


----------------------------------------------------------------------------
----
Back to: Top of message | Previous page | Main EUPHORIA page


----------------------------------------------------------------------------
----
  Back to the LISTSERV home page at LISTSERV.MUOHIO.EDU.

new topic     » goto parent     » topic index » view message » categorize

8. Re: private routines

Rob has already made his views on nested routines clear, and it seems highly
unlikely that they will be incorporated into any future version of Euphoria.
I must say I agree with his reasoning: nested routines would only make the
scope rules harder to understand, without gaining very much. So, further
debate on this topic may be vaguely interesting, but IMO not very useful.

Be seeing you,
   Gabriel Boehme

new topic     » goto parent     » topic index » view message » categorize

9. Re: private routines

> His example's procedure only has scope with in the function
> in other words private outside of his function
> That would be a benifit.

Like I said, in my first respond. The need for such tight scoping rules is only
due to not-so-great scoping rules currently.
You shouldn't have libraries this big, complex and conflicting anyway. The
second includes are modularized, the scope advantage
can be achieved by using the much more clean approach of includes. (moduralized:
each include file is its own independent
identity. In other words, there should be no way to 'add' or 'remove' things
into the scope from anywhere else except from the
file and the files it directly includes.)

Ralf

new topic     » goto parent     » topic index » view message » categorize

10. Re: private routines

Ralf's original reply:

>atom a, b, c
>
>function foo ()
>     a = 1
>     b = 2
>     ..
>end function
>
>procedure bar ()
>     c = a + b
>end procedure

Ok... and I want that in a routine, please.

I don't want it for a program, but as includable code for ANY program.

And everyone knows that if I put *that* in an include file and include it,
the code in that file would be executed. Nope, it's not what I'd like.

So support for private routines would really help here.


______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com

new topic     » goto parent     » topic index » view message » categorize

11. Re: private routines

> And everyone knows that if I put *that* in an include file and include it,
> the code in that file would be executed. Nope, it's not what I'd like.

The code doesn't get executed until the routines are called.. Reread
'refman.doc'
There can't be any other benefit except scoping, since there isn't any other
cosmetic change other than with the scoping rules.
All other 'advantages' have got in fact nothing to do with nested routines. They
can't have.

Ralf

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu