Live data from Hacker News

Awk: The Power and Promise of a 40-Year-Old Language

fosslife.org

91–100 of 122 posts

Re: Awk: The Power and Promise of a 40-Year-Old Language

#91
post #56

Earlier quoted context omitted.

Mark Espie rewrote the entire package system in perl in 2010, which is a bit late to be classed as legacy. https://undeadly.org/cgi?action=article;sid=20100323141307 I'm not sure what was used for the version before this, but the original BSD package system was written in C.

But perl was already the "standard" for other system/config utilities, no?

I don't know what we mean by "standard," but I found a number of perl references with the following shell fragment:

    $ for x in $(echo $PATH|sed 's/:/ /g'); do file $x/*|grep perl;done
All but two hits were in /usr/sbin, and /usr/bin. I isolated those files with:

    $ file /usr/sbin/* | awk '/perl/{sub(/:.*/,"");sub(/^.*[/]/,"");printf "%s, ", $0}';echo ''
The sbin results are:

    adduser, fw_update, pkg_add, pkg_check, pkg_create, pkg_delete, pkg_info, pkg_mklocatedb, pkg_sign, rmuser, 
There are more in /bin:

    $ file /usr/bin/* | awk '/perl/{sub(/:.*/,"");sub(/^.*[/]/,"");printf "%s, ", $0}';echo ''

    c2ph, corelist, cpan, enc2xs, encguess, h2ph, h2xs, instmodsh, libnetcfg, libtool, perl, perlbug, perldoc, perlivp, piconv, pkg-config, pl2pm, pod2html, pod2man, pod2text, pod2usage, podchecker, podselect, prove, pstruct, skeyprune, splain, streamzip, xsubpp, 
A perl script can't pledge() or unveil(), so I am guessing that anything sensitive has moved to C.

Re: Awk: The Power and Promise of a 40-Year-Old Language

#92

Earlier quoted context omitted.

You'll find this a lot in the embedded space. As well, you'll see a bunch of docker images that don't have perl/python.

Building a Docker image gives basically full freedom over the choice of a runtime. If your Dockerized application is written in Java or Python or PHP or C#, why not just write the tooling and scripts in the same language too? Or at least install a suitable runtime just for the scripts? Or if starting from an empty container, why not build the script into a statically-linked binary to be placed next to the application…

Typically, you want docker images as slim as possible. Both to make it faster to distribute and to prevent attacks if something escapes your application. The less in the image, the less exploitable your image is.

Beyond keeping the images slim, the times I'd reach for awk when dealing with a docker container would be when I'm debugging problems within that container. I might need to do some quick text parsing or finagling in order to troubleshoot why the application is sucking.

I'd rather not need to upload a Java script into my docker container just for quick troubleshooting.

Re: Awk: The Power and Promise of a 40-Year-Old Language

#93
post #67

Earlier quoted context omitted.

The POSIX specification includes awk, but not perl or python. The world of UNIX and UNIX-likes is larger than just Linux distributions. Depending on the utility you plan on building and the platforms you expect it to run on, it may be wiser to reach for awk than other PLs.

Modern BSDs, macOS, and Solaris certainly have Perl and Python. (iOS and Android don't, but they don't have awk either.) What other Unixes are you thinking of? AIX, HP/UX, IRIX, UnixWare, etc. should be considered retrocomputing at this point and not relevant to modern compatibility discussions. Linux distros based on busybox, as mentioned elsewhere in this thread, are a more compelling reason for considering awk tha…

Wasn't awk added to android in 9?

Re: Awk: The Power and Promise of a 40-Year-Old Language

#94

Earlier quoted context omitted.

I'm curious what linux distros don't have either some version of perl or python. I like awk, mind, but this is not necessarily (IME) a good argument for it.

A nice thing about awk vs. Perl/Python: there's a small focused set of things to learn. Once you learn them you're done. This suggests an opening for a Perl/Python intro focused on the exact same tasks, admittedly. That seems more realistic for Perl -- unless there's someone who writes Python one-liners at the shell?

I don't think true python "one liners" are a thing, but the awkward thing about awk is sits in this place where what you are doing is complicated enough you need awk, but simple enough you need a one liner? Those cases have been exceedingly few and far between for me enough that every time I want to reach for awk I have to go lookup how to do anything more complex than printing fields. That completely defeats the point of the quick one liner.

May as well open up vim, write my 7 lines of python, and run it. Because I use it everyday and didn't have to look anything up it ends up far faster. Then when I am done I either delete it, throw it in a scripts directory, or make it part of some existing infrastructure repo. Now if I keep it because I used python it is much more readable than the awk 1 liner would have been.

I have tried in earnest to memorize awk's idiosyncrasies multiple times now. By the time I go to use what I learned the last time it is months later and I have forgot enough I need to go look stuff up.

So in a way, here I am: The guy that writes "one liners" in python.

Re: Awk: The Power and Promise of a 40-Year-Old Language

#95
post #84

Earlier quoted context omitted.

Yeah, but if you are happy to program in Perl, that's basically every major Linux distro covered. Anything using DEB or RPM packaging, any machine with Git installed (which includes Windows), plus the ones I already mentioned, already have access to Perl. This is a formidable installed base with no effort needed to install a runtime.

I agree, but michaelcampbell's point seemed to be: why learn a language for its ubiquity, when more commonly used languages seem to be just as ubiquitous? So, I focused on how they're not that ubiquitous.

I see what you mean. I guess what I was trying to say is that my position is close to that of michaelcampbell's, and that I wanted to emphasize how little portability is sacrificed by adopting this position on most environments one will ever work in.

Re: Awk: The Power and Promise of a 40-Year-Old Language

#97

Earlier quoted context omitted.

Building a Docker image gives basically full freedom over the choice of a runtime. If your Dockerized application is written in Java or Python or PHP or C#, why not just write the tooling and scripts in the same language too? Or at least install a suitable runtime just for the scripts? Or if starting from an empty container, why not build the script into a statically-linked binary to be placed next to the application…

Typically, you want docker images as slim as possible. Both to make it faster to distribute and to prevent attacks if something escapes your application. The less in the image, the less exploitable your image is. Beyond keeping the images slim, the times I'd reach for awk when dealing with a docker container would be when I'm debugging problems within that container. I might need to do some quick text parsing or fina…

I agree on the slimness of Docker images, but if you e.g. have some kind of video or photo CMS written in PHP, then any housekeeping or export scripts etc are better off being written in PHP as well (or even integrated into the application) given how close they're already bound with the rest of the application.

For anything beyond that, I would very greatly prefer to have "black box", extremely verbose log dumps and database dumps that I could analyse over at my actual dev machine, or a good debugger that lets me step through the code to figure out what's going wrong.

I do realise that not all languages have good tooling, or that some people prefer to use `printf` style debugging, so it may not apply to all.

Re: Awk: The Power and Promise of a 40-Year-Old Language

#98

Earlier quoted context omitted.

Modern BSDs, macOS, and Solaris certainly have Perl and Python. (iOS and Android don't, but they don't have awk either.) What other Unixes are you thinking of? AIX, HP/UX, IRIX, UnixWare, etc. should be considered retrocomputing at this point and not relevant to modern compatibility discussions. Linux distros based on busybox, as mentioned elsewhere in this thread, are a more compelling reason for considering awk tha…

Wasn't awk added to android in 9?

Yep, https://android.googlesource.com/platform/system/core/+/mast...

Re: Awk: The Power and Promise of a 40-Year-Old Language

#99
post #94

Earlier quoted context omitted.

A nice thing about awk vs. Perl/Python: there's a small focused set of things to learn. Once you learn them you're done. This suggests an opening for a Perl/Python intro focused on the exact same tasks, admittedly. That seems more realistic for Perl -- unless there's someone who writes Python one-liners at the shell?

I don't think true python "one liners" are a thing, but the awkward thing about awk is sits in this place where what you are doing is complicated enough you need awk, but simple enough you need a one liner? Those cases have been exceedingly few and far between for me enough that every time I want to reach for awk I have to go lookup how to do anything more complex than printing fields. That completely defeats the poi…

Yeah, it's a different world from when I learned Awk. You might enjoy the (very short) book by the creators just because it's a great focused expression of the Unix way. But nobody needs to learn it.

Re: Awk: The Power and Promise of a 40-Year-Old Language

#100
post #67

Earlier quoted context omitted.

The POSIX specification includes awk, but not perl or python. The world of UNIX and UNIX-likes is larger than just Linux distributions. Depending on the utility you plan on building and the platforms you expect it to run on, it may be wiser to reach for awk than other PLs.

Modern BSDs, macOS, and Solaris certainly have Perl and Python. (iOS and Android don't, but they don't have awk either.) What other Unixes are you thinking of? AIX, HP/UX, IRIX, UnixWare, etc. should be considered retrocomputing at this point and not relevant to modern compatibility discussions. Linux distros based on busybox, as mentioned elsewhere in this thread, are a more compelling reason for considering awk tha…

You can install python and perl on BSDs, but its different than awk, where its part of the core OS and guaranteed to be there without needing to install extra stuff.
Post reply on HN