Thread View: comp.lang.postscript
3 messages
3 total messages
Started by Rob Bradlee
Tue, 18 Aug 1992 14:21
PostScript coding style question
Author: Rob Bradlee
Date: Tue, 18 Aug 1992 14:21
Date: Tue, 18 Aug 1992 14:21
31 lines
1260 bytes
1260 bytes
Here is PostScript coding style question for all you gurus: Let's say you
have a PS procedure that does some like this
/utility_procedure {
mark
%
% imagine PS code here to do some useful things and load up the stack
%
% Now imagine some PS code that does a test based on some of the
% stack info to see if it's worth processing the rest of the data
% on the stack
{
% test was true. Process the rest of the items on the stack.
}
{
% test failed. cleanup.
cleartomark
} ifelse
} def
Is the cleartomark a legitimate way to make sure you've left the stack in good
shape or a cheap trick that absolves you from the effort of thinking?
Your opinions, please.
--
Rob Bradlee w:(508)-658-5600 X5153
Agfa Corporation. ...!{decvax}!cg-atla!bradlee
200 Ballardvale St. bradlee@cg-atla.agfa.com
Wilmington, Mass. 01887
Re: PostScript coding style question
Author: Glenn Reid
Date: Wed, 19 Aug 1992 01:45
Date: Wed, 19 Aug 1992 01:45
32 lines
1656 bytes
1656 bytes
Rob Bradlee writes > Is the cleartomark a legitimate way to make sure you've left the stack in good > shape or a cheap trick that absolves you from the effort of thinking? I think it's a cheap trick, myself :-) The only justified use of it is if you include arbitrary PostScript that you do not know or trust (as in an EPS file). If you wrote the code, you should clean up after yourself. If you write things properly, there shouldn't be anything on the stack anyway when you get to the "cleartomark". If you really aren't sure what's on the stack, how do you know there isn't another "mark" (equivalent to a "[", by the way) on the stack somewhere? Anyway, I'd avoid using it if I were you. One of the things that I sometimes do with particularly gnarly bits of code is to force an error where your "cleartomark" is and see the contents of the stack, count them, analyze them, then look back at the code to get rid of anything that shouldn't be there. For example, people often use "stringwidth" but forget to pop the unused "Y" value, and it's still sitting there later. Just my $.02 -- Glenn Reid NeXTmail: glenn@rightbrain.com RightBrain Software 415-326-2974 (NeXTfax 326-2977) Palo Alto, California
Re: PostScript coding style question
Author: Dick Dunn
Date: Fri, 21 Aug 1992 16:03
Date: Fri, 21 Aug 1992 16:03
33 lines
1526 bytes
1526 bytes
bradlee@cg-atla.UUCP (Rob Bradlee) writes:
>/utility_procedure {
> mark
...stuff...
> {
> % test was true. Process the rest of the items on the stack.
> }
> {
> % test failed. cleanup.
> cleartomark
> } ifelse
>} def
>Is the cleartomark a legitimate way to make sure you've left the stack in good
>shape or a cheap trick that absolves you from the effort of thinking?
Glenn Reid took the "cheap trick" position, which I think is true most of
the time. However, if testing and processing arguments, managing inter-
mediate results, etc., gets complex enough, I think the mark...cleartomark
is cleaner and clearer than a proc which ends something like:
} {
pop pop
} ifelse
pop
} {
exch pop pop
} ifelse
...as you try to dig your way back and balance the stack at the end. This
is hardest in a proc which is coping with error situations and trying to
invoke error handlers with the right stack context.
--
Dick Dunn rcd@raven.eklektix.com -or- raven!rcd Boulder, Colorado
Cats!
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads