11 ms·
> What exactly is simple and elegant about it? Spawn-style APIs have to take a billion parameters that are mostly set to defaults, for things like working dire
by lmm 10y ago
> What exactly is simple and elegant about it?
Spawn-style APIs have to take a billion parameters that are mostly set to defaults, for things like working directory, environment variables, user ID, controlling terminal. Whereas fork+exec means you can express these things in a more compositional, buildery style: fork, change the two things you actually need to change, then exec.
- saynsedit 10y agoMeh, no one ever remembers all those stateful hidden parameters to fork() for process creation. This results in painful bugs later on, possibly affecting security. Speaking from experience. Python says explicit is better than implicit. I agree in this case.
- MichaelGG 10y agoI don't think this makes the case for elegance at all. Global vars set wherever in a program are preferable to explicit params when creating a new process? And there's no way to have default params or anything?
- lmm 10y ago> Global vars set wherever in a program are preferable to explicit params when creating a new process? The outside world is always going to be implicit global mutable state; spawning an arbitrary process to do who-knows-what is inherently that kind of problem. If you could express it as an actual function you wouldn't need to run a separate process. > And there's no way to have default params or anything? Well not in C. You can sort-of do it by having a struct with fields that you fill in where all-bits-zero is the default but that's generally more trouble than it's worth.
- MichaelGG 10y agoWell by that reasoning there's never any need for function purity since you can't eliminate global state on current computer designs. C easily allows you to have multiple functions. exec_with_current_state or something. And a struct is a way, too.
- lmm 10y ago> Well by that reasoning there's never any need for function purity since you can't eliminate global state on current computer designs. If you care about purity you don't use spawn-like functionality at all. > C easily allows you to have multiple functions. exec_with_current_state or something. That doesn't help. You'd need to have one variant where you just want to change the working directory, one variant where you just wanted to set an environment variable, one variant where you want to do both, one variant where you want to run as a different UID and change working directory but not touch the environment variables...
- the_mitsuhiko 10y agoYou can set all the sensible defaults automatically. In fact, most spawn APIs do set sensible defaults.