←back to thread

IRCd service (2024)

(example.fi)
105 points pabs3 | 9 comments | | HN request time: 0.433s | source | bottom
1. epistasis ◴[] No.45755969[source]
A couple decades ago I remember somebody using awk in programming competitions, as a stunt, and doing surprisingly well. For tasks involving text processing it has a huge advantage, and it ends up doing ok with other stuff.
replies(3): >>45756120 #>>45756493 #>>45757286 #
2. ajross ◴[] No.45756120[source]
What I always point out though is the bathtub curve of that perception.

Awk started life as a unique, weird, but extremely clever and expressive environment with which you could do tricks that were impractical anywhere else. And that's sort of back where it is now.

But for a solid decade and a half, awk was a forgotten dinosaur that no one cared about. Because in the era where Everyone Knew Perl, awk had no home. Perl was awk but bigger and better.

But now all us perl nuts have moved on or gone silent, all the kids are writing code for node or python or whatnot, and No One Knows Perl.

And in a world where no one knows perl, awk looks clever again.

replies(2): >>45756779 #>>45757400 #
3. pram ◴[] No.45756493[source]
I’ve had people be very confused and perplexed when I told them awk is a programming language in the past lol. Most seem to think it’s solely a tool like sort or uniq etc
4. sanskarix ◴[] No.45756779[source]
The whole Perl era shaped so much of how we think about text processing. It's funny how tools cycle - awk is "new" again because we forgot the middle chapter. Same thing is happening with Rust vs C - people rediscovering memory safety like it's a fresh idea.
5. busfahrer ◴[] No.45757286[source]
I have only dabbled in AWK, but I love the book "The AWK Programming Language" by its authors. Its a great read for any programmer, highlighting pragmatic techniques to solve real-world problems.
replies(1): >>45759574 #
6. rtpg ◴[] No.45757400[source]
Does perl have an awk-y mode? Or is this just "perl has a bunch of regex-y things to make everything flow well".
replies(2): >>45757947 #>>45759781 #
7. shawn_w ◴[] No.45757947{3}[source]
It has options to split up input into fields and loop over every line for one-liners, yeah. For a trivial example,

    awk '{ print $2 }' foo.txt
becomes

    perl -lane 'print $F[1]' foo.txt
I'm one of those people who out off learning awk for a decade+ because I knew perl, but when I finally picked it up I found it's often simpler and cleaner. I still switch to perl for complicated processing but awk can get a lot done.
8. Y_Y ◴[] No.45759574[source]
Many books are by their authors, though perhaps fewer nowadays.

As many already know, the authors of that book and the related eponymous language are; Alfred Aho, Peter Weinberger, and Brian Kernighan.

9. ajross ◴[] No.45759781{3}[source]
As mentioned it actually does have modes that assume various loops over the input. But it also has a bunch of syntax that naturally lends itself to that kind of very-narrow-text-dsl kind of code. Things like implicit variables, "postfix if", BEGIN/END blocks, all make awk-like just as easy to express as in awk. And then you add on top of that a much more capable base engine (despite awk's reliance on regex matching, it's still stuck with regular unix extended expressions) and library ecosystem.

Again, in 1998, in the early perl 5 era, you'd be looked at as a nut if you seriously tried to argue for doing some new tool in awk, even a tiny script. Everything worked better in perl.