10 ms·
And for good reason! It's about time, too. The "Unix Philosophy" is intellectually bankrupt. You shouldn't have to fork a process from the shell to multiply two
by DonHopkins 7y ago
And for good reason! It's about time, too. The "Unix Philosophy" is intellectually bankrupt. You shouldn't have to fork a process from the shell to multiply two floating point numbers (especially when the CPU can do that in one instruction), or do simple string manipulation. That's ridiculous.
- 1_player 7y agoNot sure I agree with you there: should it not fork a process to run a heavy task? Should it not fork a process for each end of a pipe, especially considering we're deep into the multicore era of processors? The fact that the basic shell could use more builtins instead of delegating everything to external processes (like calculating a simple expression) is totally unrelated to the Unix Philosophy being bankrupt. If fork and processes weren't so expensive, I still think multiple processes are the best way to parallelise on multicore CPUs. In fact, there's a resurgence in programming environments based on multiple communicating, yet isolated, processes, see Erlang/Elixir. Though I definitely would like to see someone seriously exploring a different paradigm than UNIX. EDIT: Unix philosophy also is "everything is a file", and what is a file exactly? A bag of bytes. Everything we deal with is a bag of bytes if you think about it, so I find it perfectly fitting to model our world that way. But then again, the current construct to represent this idea such as labels organised in directories, might be a bit long in the tooth and we're due for some paradigm shift on this front as well, but I digress.
- DonHopkins 7y agoSo you propose making a "floating point multiply server", even though the CPU can do that in one instruction? Talk about microservices!
- 1_player 7y agoAu contraire, I'm saying the shell could turn your multiplication command into a single instruction, no need to call an external process. But at some point you need to delegate to other processes. You can't have /bin/bash embed your Chrome browser in it. But that's not even Unix philosophy. That's how DOS used to work as well.
- DonHopkins 7y agoI'm talking about the shell that actually exists, not some hypothetical shell that doesn't exist and never will. You can't defend the "Unix Philosophy" by proposing a non-standard MONOLITHIC shell be universally adopted that totally goes against what the Unix Philosophy explicitly states: "Make each program do one thing well. To do a new job, build afresh rather than complicate old programs by adding new "features". At least Apple figured out that floating point was useful early enough to replace INTEGER BASIC with APPLESOFT. Forking "bc" from "bash" is the canonical way to multiply two floating point numbers in Unix, according to the "Unix Philosophy". https://stackoverflow.com/questions/12722095/how-do-i-use-floating-point-division-in-bash https://stackoverflow.com/questions/12722095/how-do-i-use-fl... >You can't. bash only does integers; you must delegate to a tool such as bc.
- Crinus 7y agoThe shell is meant to pipe programs together, not perform computations itself. Computations are meant to be made by programs, not shell scripts. Use the right tool for the job, do not complain that you screwdriver sucks because you cannot cut wood with it.
- DonHopkins 7y agoYou too are blinded by the limitations of your tools. Of course the shell performs all kinds of computations. Just not a useful enough set of them that you don't still need "bc" and "awk" and "sed" and "grep" and many other ridiculous "Unix Philosophy Compliant" tools. I complain my screwdriver sucks when it's made of plastic, and it's only good for driving plastic screws into styrofoam.
- Crinus 7y agoThe idea is that the tools are meant to be limited to avoid complexity (this is why bash, like most GNU tools, isn't really a good example of unix philosophy - it is too complex) and instead rely on composition.
- DonHopkins 7y ago"Everything is a file". Except ioctl. Except mmap. Except the shell makes it a huge pain in the ass to hook up arbitrary graphs of streams between processes.
- tntn 7y agoEDIT: I'm too old for this. Think what you want about mmap and ioctl.
- DonHopkins 7y agoMy point is that ioctl and mmap disprove the "Unix Philosophy" idea that files are one-dimensional streams of characters that are all you need to plug programs together.
- uep 7y agoDo they though? Everything as a file is an abstraction, an enormously useful abstraction. The point isn't that it has to behave like a file in every way. At the C level, the fact that open(), read(), write(), or e/poll() behave the similarly is extremely helpful. I can have a whole suite of functions that do not care what type of file descriptor they hold, but just that those functions behave in a predictable way. Maybe only 10% of my code has to care about the differences between them, instead of 70%.
- pjmlp 7y agoExcept sockets, Sys V IPC, GPGPUs, better then?
- deleted 7y ago[deleted]
- p_l 7y agoBSD Sockets were never part of "UNIX Philosophy", they are an ugly quick'n'dirty port/rewrite of code from totally alien system (TOPS-20) because DoD had to deal with vendor abandonment
- 0815test 7y agoThe point of processes is to be meaningful protection boundaries, especially post Spectre and Meltdown. Maybe you shouldn't have to spawn a separate process to do a simple calculation, but spawning processes had better be as cheap as possible, and things you do from the shell will (in principle if not always in practice) be limited by the speed of human input, so the overhead of a separate process just won't matter. The Unix philosophy gives you these things, together with a reasonably-efficient common interface (byte streams) which can be used to combine independent programs in order to accomplish more complex tasks.
- DonHopkins 7y agoThink about how many orders of magnitude more instructions and system calls it takes to fork a process, open a new pipe, write bytes to the pipe, context switch to the new process, start it up, read bytes from the pipe, multiple two numbers, write bytes to the pipe, terminate the process, context switch back to the original process, read bytes from the pipe, and close the pipe (no matter how efficient forking and context switching and making system calls is), than it takes to execute a single floating point "fmul" instruction.
- Crinus 7y agoIf you are doing this for a bunch of images once in a while it is meaningless to even care about the performance implications. If you are doing this often enough where such computation affects the throughput of your application, then you are using the wrong approach - computation is not meant to be done via the shell or shell scripts, these are meant to be used to tie together applications. That you can use bc for computations is just a convenience the overall design enables you, but that doesn't mean it is how you should use it.
- DonHopkins 7y ago>"computation is not meant to be done via the shell or shell scripts" You are using the passive voice, which is useful when you want to obscure the subject of the sentence. So WHO does not mean for you to perform floating point calculations and string manipulation with the shell? The shell is a human designed artifact. God did not create the category of shell scripting languages and declare that nobody should ever use them perform floating point or string manipulation. Windows Powershell isn't ridiculously crippled like bash is. It's still a shell. That disproves your point that there is some universal definition of a shell that precludes it being useful for general purpose programming tasks.
- deleted 7y ago[deleted]
- hedora 7y agoLet’s compare the alternatives to forking for a floating point op (ignoring the fact that it would be easy to add this to the shell if it were common enough): The Unix way pays to fork a process for a floating point operation in shell, then delegates the expensive work to something written in an appropriate (probably compiled, maybe vectorized/gpu optimized) language. Forking the process took 10-100s of usec. If the hard work is comparable to this, the prompt returns immediately, so it is fast enough. If the hard work is non-trivial, the fork for the floating point op is << 1% of the runtime. Either way, the fork is effectively free. The “modern” ways (which Unix mostly killed off in the 70’s, but that are currently in revival), are to write the hard work in a high-level, and usually interpreted language or write the process control logic in a lower level language. In the case of the high level language, the hard work is now ~2-10x slower than unoptimized logic in a compiled language, so you spend ~50-90% of your time in useless overhead. If you move the process control to a low level language, then it is more verbose, and you also have to recompile (or jit) the bulk of the program, which is much more expensive than forking a process. It likely takes 10s or even 10,000s of milliseconds! There is a reason Unix won back when machines were orders of magnitude more expensive than they are now. (And why is it still more usable than its competitors today.)
- pdkl95 7y ago> The "Unix Philosophy" is intellectually bankrupt. The rest of your post appears to be about shell (presumably Bourne) script, leaving this claim unsupported. "UNIX philosophy" != "writing shell scripts". > You shouldn't have to fork a process from the shell to multiply two floating point numbers I can't remember a single time in the >25 years I've been writing Bourne shell (or bash) scripts where I've wanted to "multiply two floating point numbers". I've sent large lists of floating point numbers to various programs for processing, but other languages are far more appropriate for problems that requires any amount of actual calculation (especially floating point calculations). If I did need to multiply two floats for some reason, it would be such a rare event that the few hundred milliseconds "wasted" in spawning bc is utterly irrelevant. You seem to be complaining about shell by selecting a feature that is not actually needed in common use. What, specifically, were you doing that you needed fast floating point match but needed to use Bourne shell instead of C/Python/whatever? > fork a process ... do simple string manipulation. For many types of string manipulation, you don't. Manipulating strings (command lines) is what the shell was designed to do! Sometimes sed/awk/etc is useful for complex tasks, but the shell's variable expansion and other builtins are generally enough for most simple needs. And if your needs actually are complex, the cost to start another process (which is probably much smaller than you think) is insignificant.
- DonHopkins 7y agoYou're blinded by the limitations of your tools. Of course you wouldn't do something that's impossible with the shell, because you know it's impossible, and would switch to another language if you needed to do that. That doesn't mean that you never need to use floating point numbers. It just means you need to switch languages when you need to use them. Which is my point. And no, the kind of stuff you need to fork sed or awk to do is not "complex". It's simple. It only seems complex because you're writing a shell script, and the backflips you have to do to escape the parameters and fork the processes to do that simple string manipulation is complex, not the string manipulation itself.
- mixmastamyk 7y agoPerhaps you are arguing for a better shell? Which is something I could get behind. bash has always been a bit of a mess. xonsh is one example of a better one, however I am currently using fish. fish has a math and string manipulation builtin. https://fishshell.com/docs/current/commands.html#math https://fishshell.com/docs/current/commands.html#math https://fishshell.com/docs/current/commands.html#string https://fishshell.com/docs/current/commands.html#string https://xon.sh/tutorial.html https://xon.sh/tutorial.html