On 8/2/2018 1:24 PM, 'John Clements' via Racket Users wrote:
I hate to turn a little question into a big one, but… are parameters the right 
choice, here? It seems to me that optional parameters would be more suitable.

Unfortunately, I’ve been on the other side of this fence, too: parameters are 
vastly more convenient for implementors than adding optional parameters to 
every one of the internal calls. This certainly came up for me in the 
construction of a CSV writing library.

I can imagine a bunch of programming patterns that might assist this; the most 
obvious one would be an object-like metaphor where parameter values are 
represented as an object to which calls are made. Do others have ideas on a 
“best practice” for this situation and others like it?

John

In the case in question, I probably would go the object route as well.


Personally, I don't find a lot of use for parameters:  my biggest need for them is in threaded web server code where there may be multiple instances of a given handler and they need unique identifiers for client messages, log entries, etc.   Generic logging code doesn't know what thread it's running under, and Racket threads don't have a printable identifier themselves ... so I parameterize each handler thread with a useful [to me] identifier.

But parameters aren't useful for sideways communication between threads.  Almost all my use of continuations is for abort / escape purposes, and I don't find a lot of need there for the "special var" stack behavior of parameters.   For most code where I might possibly use parameters, I find they just don't add anything over using "global" variables. [I put "global" in quotes to mean only  "accessible to all the code that needs and/or shares the variable" - not necessarily that it is defined at the top level or exported from its module.  Even within modules, not infrequently I use the idiom of defining multiple functions within a let that defines their shared state.  Generally I prefer to limit an object's visibility to only that code that needs to see it.]

But I imagine there are other people who find parameters invaluable in their work.  Their utility for file I/O using standard ports is obvious ... I just don't tend to write a lot of that kind of code.

YMMV.
George

--
You received this message because you are subscribed to the Google Groups "Racket 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to