Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Awk > Re: Is that pro...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 10 of 16 Topic 2155 of 2241
Post > Topic >>

Re: Is that problem for awk?

by Janis Papanagnou <Janis_Papanagnou@[EMAIL PROTECTED] > Feb 8, 2008 at 07:11 PM

Ed Morton wrote:
> On 2/8/2008 11:11 AM, Janis Papanagnou wrote:
[snip]
>>
>>You can shorten that a bit without sacrificing the action block by
>>
>>   awk '{ sub(/./,NR) } 1' file
>>
>>Personally I consider the concatenation of sub() and 1
>>
>>   awk 'sub(/./,NR) 1' file
>>
>>as a hack; it's an unnecessary level of obfuscation[*].
> 
> 
> I'm all about conciseness. Within that, normally, I'd trade clarity over
brevity
> if there is a trade-off as in this case BUT in this particular case, I
really
> like favoring brevity since it's a very small script so there isn't a
lot of
> clutter with other details and to understand what awk is doing in that
script,
> you have to understand how awk works in terms of condition-action
segments,
> string concatenation, default actions, and return codes so to understand
what
> the above is doing requires you to know a lot that you SHOULD know
anyway before
> doing any awk programming.
> 
> So, I like the above because if you understand the awk paradigm already,
the
> script is perfectly clear and if you don't then the small amount of
effort
> required to learn how that small script works takes you a long way to
that
> understanding.

Oh, I don't think that learning a couple characters of "awk paradigm"
would be a problem, and especially not for experienced awk programmers.
The expression is concise enough to be memorized as a "programming
pattern"; and, yes, even for newbies.

You know that I have no problem understanding all those expressions.
My critiques is the unnecessary complexity of unnecessarily involved
concepts in that expression; mainly the implicit conversion. Maybe I
shouldn't have put the point in my footnote, so I place it here...

 >> [*] Mixing integral expressions and "invisible" operators, having
 >> implicit type conversions, and just for a boolean condition result.

It's actually the implicit complexity of

   int(concat(string(sub(...)), string(1)))

that annoys me. (Others might not mind about such internals, though.)

>>A bit more
>>verbose but IMO conceptually clearer (no implicit casts) might be
>>
>>   awk 'sub(/./,NR) || 1' file

Which is just

   or(sub(...), 1)

all done within the integer domain.

> That seems confusing to me as I can't see any benefit to it over any
other
> approach so I think people would waste their time trying to figure out
what the
> benefit is.

Consider it as a programming pattern, as you do with the textually
more concise concatenation pattern.

> If you're going to do that, IMHO you'd be better off with:
> 
>      awk '{sub(/./,NR);print}' file
> or
>      awk '{sub(/./,NR)}1' file
> 
> as they're both clearer and about the same length.

Yes, I agree.

Janis

> Regards,
> 
> 	Ed

[snip]




 16 Posts in Topic:
Is that problem for awk?
Kurda Yon <kurdayon@[E  2008-02-07 12:37:10 
Re: Is that problem for awk?
Ed Morton <morton@[EMA  2008-02-07 14:45:08 
Re: Is that problem for awk?
"Luuk" <luuk  2008-02-08 13:50:57 
Re: Is that problem for awk?
Ed Morton <morton@[EMA  2008-02-08 08:58:17 
Re: Is that problem for awk?
Luuk <Luuk@[EMAIL PROT  2008-02-08 16:19:40 
Re: Is that problem for awk?
Ed Morton <morton@[EMA  2008-02-08 10:19:07 
Re: Is that problem for awk?
gazelle@[EMAIL PROTECTED]  2008-02-08 16:48:13 
Re: Is that problem for awk?
Janis Papanagnou <Jani  2008-02-08 18:11:32 
Re: Is that problem for awk?
Ed Morton <morton@[EMA  2008-02-08 11:29:42 
Re: Is that problem for awk?
Janis Papanagnou <Jani  2008-02-08 19:11:04 
Re: Is that problem for awk?
"Luuk" <luuk  2008-02-08 10:05:11 
Re: Is that problem for awk?
William James <w_a_x_m  2008-02-09 01:00:53 
Re: Is that problem for awk?
Luuk <Luuk@[EMAIL PROT  2008-02-09 10:34:28 
Re: Is that problem for awk?
gazelle@[EMAIL PROTECTED]  2008-02-09 13:09:48 
Re: Is that problem for awk?
Ed Morton <morton@[EMA  2008-02-09 09:49:35 
Re: Is that problem for awk?
Andrew Schorr <aschorr  2008-02-09 10:55:04 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat May 17 4:40:15 CDT 2008.