[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: On procedures within procedures
From: |
Thien-Thi Nguyen |
Subject: |
Re: On procedures within procedures |
Date: |
Wed, 03 Apr 2013 21:33:17 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux) |
() Mike Gran <address@hidden>
() Wed, 3 Apr 2013 07:04:43 -0700 (PDT)
Do you have a personal philosophy on how much you try to
minimize the scope of procedures?
I figure out the data structures first, then use procedures w/o
overmuch regard to inner/outer. However, i...
If you were writing a tutorial, what would you say?
...do try to keep to a minimum the number of arguments that are
passed from a procedure's caller to procedures it calls.
For example, in SGF Utils 0.6 src/render.scm, the procedure
‘make-screen-1’ is almost 700 lines long w/ 90 internal
procedures, the deepest being 6 levels (at least, depending on
what you count, precisely) from top. This particular proc, i.e.,
‘make-screen-1 ray! one! poly-vecs two-side normal’:
(define (two-sides actually)
(define (normal direction)
(make-polar radius (+ a (* (/ PI 2) direction))))
(let-values (((mx my) (actually (normal -1)))
((px py) (actually (normal 1))))
(values mx my px py)))
is not actually as tight as it could be:
(define (two-sides actually)
(define (normal direction)
(actually (make-polar radius (+ a (* (/ PI 2) direction)))))
(let-values (((mx my) (normal -1))
((px py) (normal 1)))
(values mx my px py)))
but hey, that's a code enhancement opportunity to mull over while
posting, what luck! The point is, the usual alternative to this
structuring would be to define a "graphics and board context, both
fundamental and elaborated" object to pass around. Shudder. I'd
rather have that monster out in the open and fixed (lexically),
than roaming hidden behind getters / setters and All That Rot (er,
entropy :-D). (It helps, too, to live in Emacs, froth froth.)
OK, time to calm down. Scheme is dangerously invigorating...
--
Thien-Thi Nguyen
GPG key: 4C807502
pgpTKRCQJgIjL.pgp
Description: PGP signature