r/suckless • • Jun 09 '23
[DISCUSSION] POSIX sh is a better interpreter than python
This is a frustration I have for sometime and it's getting extremely irritating.
I don't mind seeing python as tool of quick iteration for which it is really really good especially for iterating novel software but sometimes it is deeply engraved in some of the important tools I use.
Say I want to install mpv, macports doesn't install it without python because someone decided that they have to use to use python for building the man pages or whatever for mpv.
The only reason I considered python in the past was because of it's cross platform nature. But I came to finally understand that it cannot be farthest from the truth.
POSIX sh is the much better interpreter and easily can be found in any other operating system.
Even in environments such as win32, we have https://frippery.org/busybox/ that is just fucking awesome. Staying the size below an 1mb while being extremely fast. Unlike the shitty python package which has 40mb archive size and leave breadcrumbs for me to cleanup all over my filesystem.
Well you may say there c bindings for python and for sh there is none. Not true at all. sh calls the executable and is'nt that the c binding? If you need to execute the functions in a shared library, you can do that too, infact that's how python does it under the hood. And POSIX sh spec is a fucking masterpiece and enjoyable to read.
Despite all of that, why is everyone using python? I understand normies using it because of shiny object syndrome, but why do some really big software developers use it? I really don't get it.
13
u/[deleted] Jun 09 '23
The big one is module support. I have a 500 line shell script at a big company, and it's getting to the size to where it needs to be rewritten in something with classes/structs and modules. If you write shell code, nobody else is going to want to read it, no matter what pains you take to make it neat.
8
u/[deleted] Jun 09 '23 edited Jun 16 '23
[ This content was removed by the author as part of the sitewide protest against Reddit's open hostility to its users. u/spez eat shit. ]
4
u/[deleted] Jun 09 '23
Go on, elaborate.
Please consider the usecase to python or sh. Shell can fit very well when the usecase is a simple script, simple concept, etc. As for python it fits more when a usecase needs to access certain libraries unaccessible from shell. Additionally don't forget Lua. I think it is better in a way than python and also shell.
3
u/Ok-State2053 Jun 09 '23 edited Jun 09 '23
Posix sh is a poor shell.You need a modern and powerful shell. For example, ksh93. You can use an associative array or an object in it. https://blog.fpmurphy.com/2010/05/ksh93-using-types-to-create-object-orientated-scripts.html And it is always faster than other shells. You will find more features in it,float point... But it sucks more... although it is smaller than python.
2
u/mohrcore Jun 10 '23
People are using python because it is simpler than perl.
Sh is slow, lacks anything besides the very bare-bones features of a scripting language, does an extremely poor job at encapsulating anything, as variables leak everywhere, does weird implicit string processing and relies on spawning independent processes for stuff that you would have on standard libraries of pretty much any other language - I genuinely hope I don't have to explain why this is slower by several orders than calling a function, one could say it's a massive runtime bloat.
Python also comes pre-installed with almost all desktop and server distros. Package files, while a bit messy, are still quite manageable if you know what you are doing.
2
u/adriangrigore Jun 14 '23
Maybe you would enjoy my shell based static site generator https://mkws.sh/ :) You could use Plan9's mk https://9p.io/sys/doc/mk.html instead of the main script for other fancy stuff.
1
u/[deleted] Jun 10 '23
🗿
2
u/AxeyEndres Aug 06 '23
I wrote a multi threaded data acquisition software in posix shell, it runs fine 24/7 in freebsd and never ever had a problem with it. No obscure bugs either. Arrays are stored in memory by a tmpfs system and data is accessed using common tools. It connects to multiple equipment to gather data and send to zabbix
1
u/armoar334 Jun 10 '23
Nah. I would have said the same until about a month ago, when I tried to write a text editor in it. As far as portability it's great, but that's about it. No arrays, no c-style loops and no scope makes it pretty useless. If you need speed and want to stick to coreutils, awk is 100% the way to go over sh
1
u/scrapwork Jun 10 '23
Preach
1
u/sabutilnik Jun 10 '23
You are comparing 2 very different things