Those simple one liners

I wanted to say LOL and punch my face when I saw post#11 (where Don_Cragun even reduced the string manipulation with a simple regex) in the thread http://www.unix.com/shell-programming-scripting/220553-add-0-start-filename-2.html

I mean, when things can be done with just a one liner, sometimes I tend to forgot those simple things and go for unwanted iterations.

Does this happen to you? You write a 10 liner and "HE" comes in with a one liner and you will be like "what?". Can't agree if someone says it cause of experience not in this case at least. May be our brain misses something sometimes and thinks too complex?

--ahamed

And that's why i like UNIX Philosophy .

I think the thing that most programmers missing while programming is : KISS principle :slight_smile:

It's also possible to make inefficient or unsafe one-liners; simplest isn't always best. Sometimes I see quality lost in the rush to squeeze things down into one line.

There's also some bad habits in trying to squeeze things down to the absolute mininum number of characters. I see this a lot in awk scripts -- using an unused variable instead of "" since it's one character shorter. That's baffling to read later.

Yes, sometimes the point seems to be to make a one-liner as short and cryptic as possible. It celebrates the brilliance and creativity of the creator. The reader stands back in awe, in amazement that the one-liner apparently works perfectly, but with only a vague idea of how it works. In contrast, a longer, spelled-out style is often easier to understand and more practical, but may seem pedestrian in comparison.

Maybe it's like the difference between the unpredictable, exciting attacking style of a Mikhail Tal vs the boring, grind-it-out style of a Tigran Petrosian. They both became world chess champion. But which games are more enjoyable to play through? Those of Mikhail Tal.

Of course, the best result is the one-liner that is also very easy to understand. Just like the best chess player is the one who can combine different styles.

Back to work. :mad:

1 Like

Yep, it's already a bad habit to replace an unconditional {print} with 1.
Nerd's artistic license or what?
Professors please! And no nerds!

---------- Post updated at 11:34 AM ---------- Previous update was at 11:26 AM ----------

Not really.
If s.o. "beats" me with a shorter and better readable solution, I am happy it can be improved. And hit the Thanks button.
That's another purpose of this forum, isn't it?

That's an important part of how the language works, though, and used for a lot more than an implied 'print'. It's not a hack, any more than FS is a hack -- neither of them are things which people will understand unless explained.

I totally agree with hanson44 that one-liners usually becomes too cryptic for OPs.

It will be a pretty much straightforward solution, but putting all steps in a line can drive them crazy.

So I recommend OPs to use pgawk (�profiling gawk�) if possible to execute the solution provided that will help them see the execution traces of awk programs.

I use it myself often when I am having a tough time understanding what the heck this piece of code is doing!!

3 Likes