<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.0.5" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: Recursive Word Count</title>
	<link>http://www.terminally-incoherent.com/blog/2007/03/08/recursive-word-count/</link>
	<description>Utterly random, incoherent and disjointed rants and ramblings...</description>
	<pubDate>Thu, 08 Jan 2009 20:03:56 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.5</generator>

	<item>
		<title>by: Luke</title>
		<link>http://www.terminally-incoherent.com/blog/2007/03/08/recursive-word-count/#comment-3291</link>
		<pubDate>Fri, 09 Mar 2007 16:25:27 +0000</pubDate>
		<guid>http://www.terminally-incoherent.com/blog/2007/03/08/recursive-word-count/#comment-3291</guid>
					<description>Well, the 12 CPU's are not going to really amount to any speedup - the whole script will likely run on a single CPU because none of the core unix tools is multi-threaded.

Btw, I totally want that machine! All I have here to test my multi threaded apps is an ancient Sun-Fire-880 with four 750MHz CPU's and just a bit over 8GB of RAM . :(

But you're right - with a fast CPU it doesn't really matter if you grep the cat or not. Still even with unlimited resources greping the file directly instead of greping the cat is less typing. :)</description>
		<content:encoded><![CDATA[<p>Well, the 12 CPU&#8217;s are not going to really amount to any speedup - the whole script will likely run on a single CPU because none of the core unix tools is multi-threaded.</p>
<p>Btw, I totally want that machine! All I have here to test my multi threaded apps is an ancient Sun-Fire-880 with four 750MHz CPU&#8217;s and just a bit over 8GB of RAM . <img src="http://www.terminally-incoherent.com/blog/wp-includes/images/smilies/icon_sad.gif" alt="(" class="wp-smiley" /> </p>
<p>But you&#8217;re right - with a fast CPU it doesn&#8217;t really matter if you grep the cat or not. Still even with unlimited resources greping the file directly instead of greping the cat is less typing. <img src="http://www.terminally-incoherent.com/blog/wp-includes/images/smilies/icon_smile.gif" alt=")" class="wp-smiley" />
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Craig Betts</title>
		<link>http://www.terminally-incoherent.com/blog/2007/03/08/recursive-word-count/#comment-3289</link>
		<pubDate>Fri, 09 Mar 2007 16:01:28 +0000</pubDate>
		<guid>http://www.terminally-incoherent.com/blog/2007/03/08/recursive-word-count/#comment-3289</guid>
					<description>I myself actually live on a tcsh command line, but I script in bourne.  Sick?  Demented?  Most likely.  I started in UNIX land as a programmer, so tcsh was a logical choice.  As an admin though, well . . . tcsh is a really poor choice (can't redirect both standard-in and standard-out at the same time :-()  Not to mention all the exploits tc sh leaves open.  But I like the feel of the tcsh command line.  

As far as "grepping the cat", when you are running a Sun V1280 with twelve 1.2 GHz SPARC III cu processors and 80 GB of RAM, those two microseconds you save are not really going to be of value later . . . :-D

If resources are the scarce, you really need to go back to C and drop Java . . . ;-)</description>
		<content:encoded><![CDATA[<p>I myself actually live on a tcsh command line, but I script in bourne.  Sick?  Demented?  Most likely.  I started in UNIX land as a programmer, so tcsh was a logical choice.  As an admin though, well . . . tcsh is a really poor choice (can&#8217;t redirect both standard-in and standard-out at the same time <img src="http://www.terminally-incoherent.com/blog/wp-includes/images/smilies/icon_sad.gif" alt="-(" class="wp-smiley" /> )  Not to mention all the exploits tc sh leaves open.  But I like the feel of the tcsh command line.  </p>
<p>As far as &#8220;grepping the cat&#8221;, when you are running a Sun V1280 with twelve 1.2 GHz SPARC III cu processors and 80 GB of RAM, those two microseconds you save are not really going to be of value later . . . <img src="http://www.terminally-incoherent.com/blog/wp-includes/images/smilies/icon_biggrin.gif" alt="-D" class="wp-smiley" /> </p>
<p>If resources are the scarce, you really need to go back to C and drop Java . . . <img src="http://www.terminally-incoherent.com/blog/wp-includes/images/smilies/icon_wink.gif" alt="-)" class="wp-smiley" />
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Luke</title>
		<link>http://www.terminally-incoherent.com/blog/2007/03/08/recursive-word-count/#comment-3288</link>
		<pubDate>Fri, 09 Mar 2007 14:40:57 +0000</pubDate>
		<guid>http://www.terminally-incoherent.com/blog/2007/03/08/recursive-word-count/#comment-3288</guid>
					<description>You are correct Wikke. Line count is one of those metrics that doesn't really mean much and yet people keep attach significance to it. Even when you program normally, line count can vary. For example I use the BSD/Allman indent style and:

&lt;code&gt;for(int i=0; i&#60;a.lenght; i++)
{
	sum += i;
}&lt;/code&gt;

On the other hand someone using the K&#38;R style would write the same snippet of code like this:

&lt;code&gt;for(int i=0; i&#60;a.lenght; i++) {
	sum += i;
}&lt;/code&gt;

This means that I gain 1 line of code per each block of code that requires a brace. Every loop, every if statement, every try statement, every method and class declaration will be always 1 line longer for me. The bigger the project, the more this adds up to my line count. 

Our code can be semantically equivalent, and it can compile to the same exact set of assembler instructions. But my line count will be higher simply because of a visual formating choice that I made.

This makes for a very poor metric. Of course so is counting methods, classes, variables and etc. There is just no very good ways to measure progress and performance other than accomplishing set goals at the desired deadlines.

That's why at the beginning of this post I said that I never really cared how many lines my code had - because it didn't really mean anything. But when I tell people about the project they keep asking me about the line count.</description>
		<content:encoded><![CDATA[<p>You are correct Wikke. Line count is one of those metrics that doesn&#8217;t really mean much and yet people keep attach significance to it. Even when you program normally, line count can vary. For example I use the BSD/Allman indent style and:</p>
<p><code>for(int i=0; i&lt;a.lenght; i++)<br />
{<br />
	sum += i;<br />
}</code></p>
<p>On the other hand someone using the K&amp;R style would write the same snippet of code like this:</p>
<p><code>for(int i=0; i&lt;a.lenght; i++) {<br />
	sum += i;<br />
}</code></p>
<p>This means that I gain 1 line of code per each block of code that requires a brace. Every loop, every if statement, every try statement, every method and class declaration will be always 1 line longer for me. The bigger the project, the more this adds up to my line count. </p>
<p>Our code can be semantically equivalent, and it can compile to the same exact set of assembler instructions. But my line count will be higher simply because of a visual formating choice that I made.</p>
<p>This makes for a very poor metric. Of course so is counting methods, classes, variables and etc. There is just no very good ways to measure progress and performance other than accomplishing set goals at the desired deadlines.</p>
<p>That&#8217;s why at the beginning of this post I said that I never really cared how many lines my code had - because it didn&#8217;t really mean anything. But when I tell people about the project they keep asking me about the line count.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Wikke</title>
		<link>http://www.terminally-incoherent.com/blog/2007/03/08/recursive-word-count/#comment-3286</link>
		<pubDate>Fri, 09 Mar 2007 11:56:24 +0000</pubDate>
		<guid>http://www.terminally-incoherent.com/blog/2007/03/08/recursive-word-count/#comment-3286</guid>
					<description>All the cat jokes aside :P
Isn't line counting a bad guidance to see your progress?
I mean, it indicates only on how many lines you can break down your code.
Good if you're paid by the line, but elseway, I think it's useless.
Especially with Java and alikes, where you basically can type your entire program on 1 line or place every word on another line.</description>
		<content:encoded><![CDATA[<p>All the cat jokes aside <img src="http://www.terminally-incoherent.com/blog/wp-includes/images/smilies/icon_razz.gif" alt="P" class="wp-smiley" /><br />
Isn&#8217;t line counting a bad guidance to see your progress?<br />
I mean, it indicates only on how many lines you can break down your code.<br />
Good if you&#8217;re paid by the line, but elseway, I think it&#8217;s useless.<br />
Especially with Java and alikes, where you basically can type your entire program on 1 line or place every word on another line.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Luke</title>
		<link>http://www.terminally-incoherent.com/blog/2007/03/08/recursive-word-count/#comment-3284</link>
		<pubDate>Fri, 09 Mar 2007 05:54:11 +0000</pubDate>
		<guid>http://www.terminally-incoherent.com/blog/2007/03/08/recursive-word-count/#comment-3284</guid>
					<description>I do this too all the time. But the best advice I got regarding writing "good" shell scripts was "don't pipe the cat unless you absolutely have to" :mrgreen:

Some unix commands will only work with stdin, but many are able to access files on their own. Grep is probably most notorious for this:

&lt;code&gt;1. grep foo bar.txt # fast
2. grep foo &#124; cat bar.txt # slow&lt;/code&gt;

Many people will use #2 by habit, when #1 is much faster and actually easier to type. I remember this because we would always use to joke about this:

"Stop greping the cat you pervert!"
"Leave the poor cat alone dude!"
"Did you just pipe the cat? I'm gonna call animal services!"

So yeah - every time I see cat in a script I start looking for alternate solution to rescue the poor kitty form the pipe abuse. :)

Btw, I always forget the syntax of the bash loops and have to look it up. It also doesn't help that I spent a lot of time in tcsh on one of the unix stations at school - and tcsh loops are widely different from bash loops.</description>
		<content:encoded><![CDATA[<p>I do this too all the time. But the best advice I got regarding writing &#8220;good&#8221; shell scripts was &#8220;don&#8217;t pipe the cat unless you absolutely have to&#8221;  <img src="http://www.terminally-incoherent.com/blog/wp-includes/images/smilies/icon_mrgreen.gif" alt="mrgreen" class="wp-smiley" /> </p>
<p>Some unix commands will only work with stdin, but many are able to access files on their own. Grep is probably most notorious for this:</p>
<p><code>1. grep foo bar.txt # fast<br />
2. grep foo | cat bar.txt # slow</code></p>
<p>Many people will use #2 by habit, when #1 is much faster and actually easier to type. I remember this because we would always use to joke about this:</p>
<p>&#8220;Stop greping the cat you pervert!&#8221;<br />
&#8220;Leave the poor cat alone dude!&#8221;<br />
&#8220;Did you just pipe the cat? I&#8217;m gonna call animal services!&#8221;</p>
<p>So yeah - every time I see cat in a script I start looking for alternate solution to rescue the poor kitty form the pipe abuse. <img src="http://www.terminally-incoherent.com/blog/wp-includes/images/smilies/icon_smile.gif" alt=")" class="wp-smiley" /> </p>
<p>Btw, I always forget the syntax of the bash loops and have to look it up. It also doesn&#8217;t help that I spent a lot of time in tcsh on one of the unix stations at school - and tcsh loops are widely different from bash loops.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Craig Betts</title>
		<link>http://www.terminally-incoherent.com/blog/2007/03/08/recursive-word-count/#comment-3281</link>
		<pubDate>Fri, 09 Mar 2007 04:07:17 +0000</pubDate>
		<guid>http://www.terminally-incoherent.com/blog/2007/03/08/recursive-word-count/#comment-3281</guid>
					<description>Really!

*reads man page for wc*

Doy!  I keep thinking that only the shell can resolve multiple via wildcards versus the output of the command in the back ticks.  

Maybe I just like showing off running for loops in a command line . . .</description>
		<content:encoded><![CDATA[<p>Really!</p>
<p>*reads man page for wc*</p>
<p>Doy!  I keep thinking that only the shell can resolve multiple via wildcards versus the output of the command in the back ticks.  </p>
<p>Maybe I just like showing off running for loops in a command line . . .
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Luke</title>
		<link>http://www.terminally-incoherent.com/blog/2007/03/08/recursive-word-count/#comment-3280</link>
		<pubDate>Fri, 09 Mar 2007 03:59:48 +0000</pubDate>
		<guid>http://www.terminally-incoherent.com/blog/2007/03/08/recursive-word-count/#comment-3280</guid>
					<description>I think mine did the same thing - the find command in back ticks returns list of all the java files. The wc command can accept multiple arguments an then calculates number of lines for every one of them.

Yours will also work, but I think the cat step will make it a tad slower.

Oh, and by recursive I kinda meant "recurse into subdirectories". :mrgreen:</description>
		<content:encoded><![CDATA[<p>I think mine did the same thing - the find command in back ticks returns list of all the java files. The wc command can accept multiple arguments an then calculates number of lines for every one of them.</p>
<p>Yours will also work, but I think the cat step will make it a tad slower.</p>
<p>Oh, and by recursive I kinda meant &#8220;recurse into subdirectories&#8221;.  <img src="http://www.terminally-incoherent.com/blog/wp-includes/images/smilies/icon_mrgreen.gif" alt="mrgreen" class="wp-smiley" />
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Craig Betts</title>
		<link>http://www.terminally-incoherent.com/blog/2007/03/08/recursive-word-count/#comment-3279</link>
		<pubDate>Fri, 09 Mar 2007 03:48:34 +0000</pubDate>
		<guid>http://www.terminally-incoherent.com/blog/2007/03/08/recursive-word-count/#comment-3279</guid>
					<description>Nested loops, maybe, but not recursion.  You need a process/subroutine to call itself.  Kinda like calculating factorials.

Try this one for size . . . 
&lt;code&gt;
for file in `find . -name \*.java -type f`; do \
cat $file; done &#124; wc -l
&lt;/code&gt;

This will count the total number of lines in all the *.java files, not just how many *.java files there are.</description>
		<content:encoded><![CDATA[<p>Nested loops, maybe, but not recursion.  You need a process/subroutine to call itself.  Kinda like calculating factorials.</p>
<p>Try this one for size . . .<br />
<code><br />
for file in `find . -name \*.java -type f`; do \<br />
cat $file; done | wc -l<br />
</code></p>
<p>This will count the total number of lines in all the *.java files, not just how many *.java files there are.
</p>
]]></content:encoded>
				</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.990 seconds -->
