Minority Opinions

Not everyone can be mainstream, after all.

Stacking Considerations

leave a comment »

I’ve mentioned RPL before, as the language of my high-school calculator.  For some odd reason, I didn’t mention that it’s a stack-based language, like Forth.  I’m now dealing with another stack-based language, which makes me wonder whether that high school experience is helping me keep it all straight.

The explicit stack makes certain calculations incredibly convenient, but others tricky.  It also discourages variable use; information wants to be kept on the stack as much as possible, until it’s no longer needed.  However, only a few items are easily accessible; after a certain point, variables simply become easier to retrieve. Likewise, the programmer’s memory is limited; descriptive variable and procedure names, and/or detailed line-by-line comments, are essential for keeping track of what each stack slot means.  I have also found it helpful to ensure that each procedure pops and pushes the same number of items no matter which branch it takes; that lets me count the stack size delta for any stretch of code, providing a simple sanity check.

Procedures themselves have an interesting API choice.  Ideally, they should consume and information only via the stack, but sometimes it’s simply too large.  Variables are available, but global, so documentation is crucial.  Once in a while, a procedure wants to use a variable for implementation concerns, making it more efficient to have the caller leave it there than to cycle it through the stack, but changing that API to something less ugly will involve reworking each of its callers.

Engineering is about trade-offs like this.  That makes me suspicious of anyone claiming that something is a good idea without being able to explain why it might also be bad, and why the good outweighs that.  Sadly, schools often overlook the importance of decision-making skills, choosing instead to focus on the information that should go into those decisions, and the skills required to act on those decisions.  Has that been impacting the quality of the workforce, or does everyone learn on the job?


Written by eswald

3 Sep 2013 at 7:54 pm

Posted in Technology

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s