5 ms·
The 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
by 0815test 7y ago
The 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.
- Crinus 7y agoI didn't claim that there is a universal definition of shell. My comment is about how these tools are meant to be used and designed as to follow unix philosophy (btw Bash does not follow the unix philosophy as it is a very complicated program that tries to do way more than it needs to). If the Unix Philosophy is a good thing or not is another matter, but to judge that you first have to understand it.
- DonHopkins 7y agoIf you don't mean there's a universal definition of what a shell should and should not do, then WHO do you mean proclaimed that "computation is not meant to be done via the shell or shell scripts"? Just because Eric Raymond writes something in a book doesn't mean it's true. I've been using Unix for at least 37 years, and other operating systems before that, so I think I have enough experience and understanding to judge the "Unix Philosophy" myself, instead of simply believing without question and regurgitating everything Eric Raymond writes. (And unlike him, I also don't believe black people are violent and stupid, or that white people's long term objective must be to break, crush and eventually destroy Islamic culture, either!) https://en.wikiquote.org/wiki/Eric_S._Raymond https://en.wikiquote.org/wiki/Eric_S._Raymond
- Crinus 7y ago> If you don't mean there's a universal definition of what a shell should and should not do, then WHO do you mean proclaimed that "computation is not meant to be done via the shell or shell scripts"? One doesn't follow the other, the "computation is not meant to be done via the shell or shell scripts" is a statement i made and that was under the context of the Unix Philosophy. Also you are focusing on the wrong thing here. > Just because Eric Raymond writes something in a book doesn't mean it's true. I haven't read any of his books nor i see what he has to do with it. > I have enough experience to judge the "Unix Philosophy" myself Then why are you using floating point computation with a bash script as an example for where the Unix Philosophy is bad? Bash doesn't follow the Unix Philosophy, shell scripts aren't even meant to be used for floating point computation when you consider it, instead you should either use a tool dedicated to such computations or to the specific computation you want to perform. There are issues with the Unix Philosophy, like the simplicity it boasts only exists at a micro/local scale but it disappears at a macro/global scale - combining a few simple tools ends up with the combined complexity of all those tools plus the complexity inherent in the communication of them. To use these simple tools effectively you need to know all of them, knowledge of a single tool - despite how simple it might be by itself - is not very useful if it can only do one thing because an application almost never needs to do one thing. This isn't a matter of performance, since nobody ever claimed that following the Unix Philosophy would be fast - but many do claim that it is simple.