5 ms·
The one thing I find unfortunate about how people learn awk is the emphasis on making it terse and unreadable, especially trying to turn everything into a shell
by rspeer 8y ago
The one thing I find unfortunate about how people learn awk is the emphasis on making it terse and unreadable, especially trying to turn everything into a shell one-liner.
Don't write one-liners if they're not that simple. Write ten-liners! Add comments! Commit them to version control! Awk can be a nice, readable little language if you're not trying to win at code golf all the time.
- chrisfinazzo 8y agobwk addressed this in a video at U Nottingham a few years ago. In a nutshell, he's basically arguing that they designed it to be terse to avoid giving people an excuse to write 1000's of lines for no reason. Less code = better (at least to his mind).
- rspeer 8y agoI can't imagine what one would do with thousands of lines of awk, so that seems a little extreme. Awk is a pretty terse language, and that gives you plenty of room to put in whitespace and comments and still have something short and sweet. I think that the idea of writing code to be nicely readable by your collaborators, or your future self, might not have been around in the early days of UNIX. ("But it's just a one-off thing I'm never going to do again, why should I save it to a file?", you may ask. Is what you do important? Then you'll probably have to do something like it again.)
- msingle 8y agoone could write an assembler - http://doc.cat-v.org/henry_spencer/amazing_awk_assembler/ http://doc.cat-v.org/henry_spencer/amazing_awk_assembler/
- rspeer 8y ago"aaa" is a fitting name because that's what I said out loud when I followed the link.
- eckza 8y agoI have a little repo called “cleversql”. It’s full of little scripts that represent hard problems that I’ve had to solve, clearly-named and well-documented. I fall back on it often, when I remember that I’ve solved a certain kind of problem before, but I cannot recall exactly how. It’s an invaluable asset and saves me tons of time on a regular basis. I’d rather search my OWN hard drive for an example of my OWN code for how to - for instance - use a CTE to recursively populate a date dimension table, than to search Google and see someone else’s code, to refresh my memory.
- Pamar 8y agoHave you considered making it (or part of it) publicly available?
- QasimK 8y agoI suspect a huge amount of the value of it is because it is personal, I.e. based heavily on his past experience. It means he is always just refreshing his memory rather than looking at something new. It’s why my Programmer’s Compendium [0] may only ever be useful to me. If you try looking at some of the more complete pages there, you might think they’re useless, but they’re, in fact, all that I need to write down. However, mine is public, and there’s not much harm in these things being public, because perhaps it can be useful to someone else one day. I would encourage people to share knowledge by default. So while I also think making it public is a good idea, I would also say never be under pressure to make it accessible to others! What’s good for learning is almost never good for reference. [0] https://qasimk.gitbooks.io/programmers-compendium/content/ https://qasimk.gitbooks.io/programmers-compendium/content/
- lambertsimnel 8y agoIs this it? https://youtu.be/Sg4U4r_AgJU https://youtu.be/Sg4U4r_AgJU
- vram22 8y agoThe "strongly-hyped" and "lookalike" languages points are good, at around 8 to 9 mins in :)
- rspeer 8y agoOh, I think I understand the point here now. I said in my other comment that I can't imagine what one would do with thousands of lines of awk -- but maybe this means their design succeeded. By designing a terse language, they made people want to do things with it that are short and sweet, preventing it from feature-creeping into a full-featured language where you'd write thousands of lines of spaghetti. Is that the idea?
- chrisfinazzo 8y agoPretty much. Another bwk-ism I recall hearing was “don’t be too clever or too dumb” about whatever you write. Either you won’t understand it later, or you’re just wasting effort.
- textmode 8y agoI believe there is also an earlier reference where he said something similar. If I recall correctly, he said he was surprised when he became aware people were writing large programs in awk. I also recall a more recent interview where when asked about his language preferences, he admitted he does very little programming anymore. When the interviewer pressed for what language he would use now (sigh), he said he would just use Python.
- barrkel 8y agoI've written hundred-line awk scripts. It's not worth it. As soon as you go over about 3 lines, you're better off switching to Ruby, Python or even Perl.
- hinkley 8y agoBuild it bit by bit in a wiki. When it gets too big to type in reliably put it in version control. Add a help function and more flags for all the corner cases your coworkers discover.