1. 10

  2. 5

    This article would be great if it was delivered as teaching someone on how to translate awk (as best as you can) to Python constructs and how to bring a programming language into your shell scripting toolkit.

    …missing other things that are now considered fundamentals of how a language works

    This is a common issue of developers that they regularly opine. A crazy notion that there is “one true language” whilst ignoring that everything is a bunch of compromises.

    Python chooses to compromise on speed, inflexibility in implementation and ability to prototype with as its primary mission is to write Pythonic code.

    …Python coding is a path toward more easily maintainable code

    Maintainable is a point of accessibility. Accessibility to jump in, to make changes, to make things easier, to communicate ideas to others. ‘Pythonic’ is awful on these points as everyone confuses familiarity for ease of use; similarly to why everyone ignores the latent costs of NAT when comparing it to IPv6.

    …but @jimdigriz, why the lack of love?

    Too often…when shown a shell based implementation that is 20x faster than the original Python version, the response I always receive is to rewrite the Python version to use shown better technique, ignore that it is still 50% slower and then have the working shell based pipe line swapped out.

    “but it’s better as it is Python!”

    …and that’s why I drink.

    1. 8

      Gawk has all of these. Don’t port anything.

      At some point, however, awk’s limitations start to show. It has no real concept of breaking files into modules, it lacks quality error reporting, and it’s missing other things that are now considered fundamentals of how a language works.

      1. 3

        GAWK is not portable. You could possibly say “neither is Python”, but I would bet that Python is more available than GAWK. and even if it isnt, if youre going to have to install a package anyway, wouldnt a butcher knife be better than a plastic kids knife?

        I like AWK, I have used it for many years and would consider myself an AWK expert. But when the question is “what is the right tool for the job”? The answer is rarely AWK or GAWK.

        1. 10

          The right tool is obviously Perl in this case.

          1. 7

            and the tool is a2p since forever.

            1. 2

              Came here to say that very thing. The syntax maps more precisely and the idioms fit more completely thanks to Perl’s history for this almost exact purpose. The right tool for the right job.

            2. 6

              What do you mean “gawk is not portable”? Name one platform that has awk and python that does not have gawk?

              The point is you can either spend your time rewriting or you can just keep using the same code with extensions.

              And if you really really want to rewrite, Perl is a lot closer. This whole article just seems like someone who has arbitrarily decided that python is a “real” language so it’s inherently better to use it.

              1. 8

                The author blurp has:

                He has been programming Python since 1999

                Looks like a case of hammer, nail to me.

                (and the examples with the yields only convince me more that python is not the better choice)

                1. 2

                  To be fair, I know far more carpenters with Python hammers than with Awk hammers.

                  I myself have but a ball peen Awk hammer, compared to my sledge Python hammer. So for really stubborn nails, Python is the better choice for me.

                  1. 1

                    I’ve been using Awk for even longer though.

                    The story in https://opensource.com/article/19/2/drinking-coffee-awk was in 1996.

                  2. 0

                    Um, Debian, BSD? should I go on?

                    1. 4

                      I suppose you mean that gawk features are not portable among the default awk on different OSes, so you shouldn’t use them and pretend that the script will work on any awk. That is totally true.

                      But the OP likely means that you can use gawk explicitly, treating it as a separate language. Gawk is available on almost all Unix OSes, so it is portable.

                      1. 2

                        My point is if your going to have to install a package, you might as well install $proper_programming_language instead of AWK. Unless what you need can be easily done with GAWK alone, its not really worth using.

                        Keep in mind that even with GAWK, proper support for indexed arrays is not available, nor first class functions, private variables in AWK are footguns, no HTTP client, no JSON, etc.

              2. 4

                Hahaha I have never encountered anyone with this problem. Literally only ever use awk for { print $1 } or similar, or { sum+=$1 } END { print sum } if I’m feeling really fancy.