5 ms·
Python is readable, awk is not. I'd rather spend an extra 5 minutes writing something that I don't have to burn 20 minutes understanding in just a few months t
by rmrfstar 6y ago
Python is readable, awk is not. I'd rather spend an extra 5 minutes writing something that I don't have to burn 20 minutes understanding in just a few months time.
I think the popularity of Python for scripting is pretty good evidence that PG was dead wrong on the importance of brevity in programming languages. Further evidence can be found in Python's development of type hints.
- sillysaurusx 6y agoPython isn't that readable when piping. From https://docs.python.org/3/library/subprocess.html#replacing-shell-pipeline https://docs.python.org/3/library/subprocess.html#replacing-... output=$(dmesg | grep hda) becomes p1 = Popen(["dmesg"], stdout=PIPE) p2 = Popen(["grep", "hda"], stdin=p1.stdout, stdout=PIPE) p1.stdout.close() # Allow p1 to receive a SIGPIPE if p2 exits. output = p2.communicate()[0] This isn't a contrived example. One reason I like using macros in Python is because it simplifies exactly this boilerplate. You can write a simplifying function, but programs rarely do.
- powersnail 6y agoI agree. Subprocess isn't really a shell-ish pipe. And it's sometimes slow (at least it used to be). This is why I use the shell overall, but when I need to process something that's better expressed in python, I use pypyp.
- sillysaurusx 6y agoThanks for mentioning pypyp! It looks sweet.
- d0mine 6y agoWhy would you reimplement piping? Just use the shell: output = check_output(“dmesg | grep hda”, shell=True) Or regular Python string methods could be used instead of piping to grep.
- deleted 6y ago[deleted]
- deleted 6y ago[deleted]
- pbar 6y agoAnother counterpoint to readability: the benefit is diluted if the reader isn’t familiar with the dependencies. I know this goes both ways, though in some circles (say, devops) there’s more familiarity with Unix tools than Python. So the cognitive overhead of getting familiar with something you’re not IMO outweighs readability in either case.
- dig1 6y agoI believe it is a matter of taste and experience. Some people prefer to read & edit 3-4 concise lines, and some prefer ten pages of prose. > I think the popularity of Python for scripting is pretty good evidence that PG was dead wrong on the importance of brevity in programming languages. IMO Python has a fair number of brevity constructs, which was it's one of the selling points, besides keeping other things readable. If you look at the published code from the research community, many of it resembles Matlab or Mathematica's style.
- czynskee 6y agoIf you find awk unreadable, maybe check out this link? https://ferd.ca/awk-in-20-minutes.html https://ferd.ca/awk-in-20-minutes.html I actually find awk very readable. It's a far simpler language than Python really. The exception is perhaps if you need to do something complex, like parse a csv.
- busterarm 6y agoHonestly I think if someone finds awk unreadable, they're probably cutting corners elsewhere and probably shouldn't be doing unix systems programming. It's like all of the bash scripts that we see that don't handle failures and traps or print a usage block.
- rmrfstar 6y agoOut of curiosity, I grepped the Qubes github repos for awk. Here's the most complicated use I could find: awk -F : '/\/home/ { print $1":"$3":"$4":"$6 } '
- munificent 6y ago> It's a far simpler language than Python really. This is true, but if you already know Python, then "awk + Python" has greater total complexity than "just Python". So the question is does awk add enough value to be worth the incremental cost of learning it in addition to Python? I think for many, the answer is "no".
- coward8675309 6y agoDas Tolle an Deutsch ist, dass es lesbar ist, während Englisch nicht.
- busterarm 6y agoIch stimme zu.
- fomine3 6y agoIn this context (vs Bash), I argue that awk is pretty readable and perl is somewhat readable.