Comment

Comment by cpdean

I'm a huge fan of awk but the "Python vs awk" page this links to [1] shows python code that's almost deliberately atrocious.

Take this function the author wrote for converting a list of integers (or strings) into floats

    def ints2float(integerlist):
        for n in range(0,len(integerlist)):
            integerlist[n]=float(integerlist[n])
        return integerlist
Using `range(0,len(integerlist))` immediately betrays how the author doesn't understand python. The first arg in `range` is entirely redundant. Mutating the input list like this is also just bad design. If someone has used python for longer than a month, you'd write this with just `[float(i) for i in integerlist]`.

Further down in the function `format_captured` you see this attempt at obfuscation:

    freqs=ints2float(filter(None,captured[n].split(' '))[2:5])
Why bother with a `filter`? Who hurt you?

    freqs = ints2float(captured[n].split(' ')[2:5])
That said, the author's implementation in awk does look pretty clean. I'm just peeved that they straw-manned the other language.

[1] https://pmitev.github.io/to-awk-or-not/Python_vs_awk/

parent cpdean 3 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton