Those simple one liners


 
Thread Tools Search this Thread
The Lounge What is on Your Mind? Those simple one liners
# 1  
Old 04-08-2013
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 https://www.unix.com/shell-programmin...ilename-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
# 2  
Old 04-08-2013
Quote:
Originally Posted by ahamed101
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.
And that's why i like UNIX Philosophy .

Quote:
Originally Posted by ahamed101
May be our brain misses something sometimes and thinks too complex?
I think the thing that most programmers missing while programming is : KISS principle :-)
# 3  
Old 04-09-2013
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.
# 4  
Old 04-12-2013
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. Smilie
This User Gave Thanks to hanson44 For This Post:
# 5  
Old 04-12-2013
Quote:
Originally Posted by Corona688
...

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.
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 ----------

Quote:
Originally Posted by ahamed101
...

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
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?
# 6  
Old 04-12-2013
Quote:
Originally Posted by MadeInGermany
Yep, it's already a bad habit to replace an unconditional {print} with 1.
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.
# 7  
Old 04-12-2013
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!!
These 3 Users Gave Thanks to Yoda For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

4 More Discussions You Might Find Interesting

1. What is on Your Mind?

One liners, quick rant...

Hi fellas and fella-esses... There are numerous threads on here where people ask for, and often expect, solutions to difficult problems solved using _one_liners_. Why do they insist as such when it is virtually no different in execution time with well thought out indented code? Is it me... (12 Replies)
Discussion started by: wisecracker
12 Replies

2. Shell Programming and Scripting

awk one liners into a nice script

Hi All, I got some awk one liners, how can i split it all into a nice script? Got these: gzcat capgw0.log-201308161376632741.gz | sed -n '/2013-08-16 05:56:/,/2013-08-16 05:58:/p' > timebased.log awk -F":|," 'FNR==NR && /INFO - AId:/ {a=$0;next} END {for (i in a) print i "|" a}'... (8 Replies)
Discussion started by: batka
8 Replies

3. Shell Programming and Scripting

awk - one liners

Guys, I have a requirement like this. A file has >5K records always. Separated by "|", it has 30 fields for each line. In some lines, I am getting an odd field. say, the 15th field is supposed to be 2 characters but comes in as >2. In this case, for resolving this I need to copy the value of... (6 Replies)
Discussion started by: PikK45
6 Replies

4. Shell Programming and Scripting

invaluable resource for shell one liners and more

Hi all, This link might help whom is seeking a quick solutions for thier daily shell needs. linkAll commands | commandlinefu.com (1 Reply)
Discussion started by: h@foorsa.biz
1 Replies
Login or Register to Ask a Question