<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Shlrm.org Blag &#187; groovy</title>
	<atom:link href="http://shlrm.org/wordpress/tag/groovy/feed/" rel="self" type="application/rss+xml" />
	<link>http://shlrm.org/wordpress</link>
	<description>Linux, Java, Ruby, and Politics.</description>
	<lastBuildDate>Mon, 10 Oct 2011 18:50:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Groovy Threading and Java Threading</title>
		<link>http://shlrm.org/wordpress/2009/11/30/groovy-threading-and-java-threading/</link>
		<comments>http://shlrm.org/wordpress/2009/11/30/groovy-threading-and-java-threading/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 05:25:59 +0000</pubDate>
		<dc:creator>David Kowis</dc:creator>
				<category><![CDATA[Coding!]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[groovy]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[threads]]></category>

		<guid isPermaLink="false">http://shlrm.org/wordpress/?p=307</guid>
		<description><![CDATA[I must be doing something wrong in groovy. Of course I'm a groovy noob, so that is probably the case.]]></description>
			<content:encoded><![CDATA[<p>I must be doing something wrong regarding my groovy code. I was talking to a friend and fiddling with a tower of hanoi solver code. Just burns in CPU basically. Now I hacked it up in groovy, after he talked about it, just because. Well I came up with a groovy-ish solution that should do the same thing his java code did. However, the Java code actually ran like 8 threads, whereas my groovy code only ran about 3. Based entirely on CPU usage in linux. On the same box. I don&#8217;t understand&#8230; The code follows.<span id="more-307"></span></p>
<p>Groovy Code:</p>
<pre class="brush:groovy">import java.util.concurrent.atomic.AtomicInteger
import java.util.concurrent.Executors
import java.util.concurrent.Callable

def moveSingleDisk(source, dest) {
	//nothing!
}

def moveTower(number, source, dest, temp) {
	if (number &gt; 0) {
		moveTower(number -1, source, temp, dest)
		moveSingleDisk(source, dest)
		moveTower(number - 1, temp, dest, source)
	}
}

AtomicInteger counter = new AtomicInteger()
counter.set(1)

synchronized out(message) {
	println message
}

def logic = {
	start = System.nanoTime()
	moveTower(it, 'A','B','C')
	stop = System.nanoTime()
	out("${it} took ${(stop-start)/ 10**6} milliseconds")
}

def THREADS=16

pool = Executors.newFixedThreadPool(THREADS)
println "Creating a pool for $THREADS threads"

1.upto(64) {
	def value = it
	//out "Submitting job $value"
	task = {c -&gt; pool.submit( c as Callable)}
	task{logic(value)}
}

pool.shutdown()</pre>
<p>Java code:</p>
<pre class="brush:java">/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package hanoi2;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 *
 * @author brad
 */
public class Main {

	static private ExecutorService exec = Executors.newFixedThreadPool(8);

	static void moveSingleDisk(char src, char dst) {
		// System.out.println(src + " =&gt; " + dst);
	}

	static void moveTower(int n, char src, char dst, char tmp) {
		if (n &gt; 0) {
			moveTower(n - 1, src, tmp, dst);
			moveSingleDisk(src, dst);
			moveTower(n - 1, tmp, dst, src);
		}
	}

	public void run() {
	}

	public static void main(String[] args) {

		System.out.println("Starting with a thread pool of 8");

		for (int i = 0; i &lt; = 64; i++) {
//      long start, stop;
			final int blah = i;
			exec.submit(new Runnable() {
				public void run() {
					long start = System.nanoTime();
					moveTower(blah, 'A', 'B', 'C');
					long stop = System.nanoTime();
					System.out.println(blah + " took " + ((stop - start) / 1000000) + "ms");

				}
			});
		}
	}
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://shlrm.org/wordpress/2009/11/30/groovy-threading-and-java-threading/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Groovy!</title>
		<link>http://shlrm.org/wordpress/2009/01/12/groovy/</link>
		<comments>http://shlrm.org/wordpress/2009/01/12/groovy/#comments</comments>
		<pubDate>Mon, 12 Jan 2009 17:09:36 +0000</pubDate>
		<dc:creator>David Kowis</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[grails]]></category>
		<category><![CDATA[groovy]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rant]]></category>

		<guid isPermaLink="false">http://shlrm.org/wordpress/?p=175</guid>
		<description><![CDATA[Reading about groovy. It&#8217;s got some really interesting things. It brings the magic of dynamic typing and such (like ruby and python have) to java. But it doesn&#8217;t replace java, it simply adds it to java. So when you&#8217;re writing a groovy script, you can actually just write pure java and it&#8217;ll still work. That&#8217;s <a href='http://shlrm.org/wordpress/2009/01/12/groovy/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>Reading about groovy. It&#8217;s got some really interesting things. It brings the magic of dynamic typing and such (like ruby and python have) to java. But it doesn&#8217;t replace java, it simply adds it to java. So when you&#8217;re writing a groovy script, you can actually just write pure java and it&#8217;ll still work. That&#8217;s a very interesting (and potentially evil) feature. Imagine code with groovy and java intermingled. Yikes.</p>
<p>Anyway, there&#8217;s also something called grails. It&#8217;s groovy&#8217;s rails application framework. I&#8217;m hoping that it&#8217;ll be more useful to me than ruby on rails was. Whilst I was able to get some stuff done in rails, I wasn&#8217;t able to do quite what I wanted to do. Things didn&#8217;t interoperate the way I wanted them to. Building things to be completely REST-ful was a pain. It may simply be that I don&#8217;t know enough to do fully RESTful applications.</p>
<p>Also, testing was a pain in rails. I found several testing frameworks, but none quite fit what I wanted to do. That may have had something to do with my insistence upon using constraints in my database. Rails isn&#8217;t built to handle constraints, it wants your database to be dumb. I don&#8217;t really think that&#8217;s a good thing; having constraints in your database allows the database to make more intelligent optimizations regarding the data. Since rails assumes there aren&#8217;t any constraints on the database, it generates tests that break databases that use constraints. There are a few work-arounds, but none that exist well enough to actually run all my tests at once. I can piecemeal them and if I do them in the correct order, everything works just fine.</p>
<p>Regarding ruby itself, I miss the ability to create threads. I&#8217;ve finally understood threading in java, and how to efficiently and effectively use threads to handle things. Lacking a similar threading operation in ruby (at least an obvious one) I had a lot of trouble trying to implement some of the things I wanted to do. I love the dynamic-ness of ruby, and I like the ability to just write code and it does mostly what I think it should. There is probably a good way to do threading in ruby, I mean, people have written webservers entirely in ruby, I just haven&#8217;t figured it out. I&#8217;ll probably still use ruby for things, I&#8217;ve got a project or two churning around in the back of my mind to use ruby on, but for now, I think I&#8217;ll stick with Java.</p>
<p>This has turned more into a rant about what I don&#8217;t like about ruby and rails. I guess I&#8217;m hoping that grails will live up to my expectations more than rails did, and that groovy will give me the dynamic fun that I enjoyed with ruby.</p>
]]></content:encoded>
			<wfw:commentRss>http://shlrm.org/wordpress/2009/01/12/groovy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pragmatic Groovy and Thinking and Learning, Oh My!</title>
		<link>http://shlrm.org/wordpress/2008/12/18/pragmatic-groovy-and-thinking-and-learning-oh-my/</link>
		<comments>http://shlrm.org/wordpress/2008/12/18/pragmatic-groovy-and-thinking-and-learning-oh-my/#comments</comments>
		<pubDate>Fri, 19 Dec 2008 04:15:12 +0000</pubDate>
		<dc:creator>David Kowis</dc:creator>
				<category><![CDATA[Coding!]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[groovy]]></category>
		<category><![CDATA[learning]]></category>
		<category><![CDATA[pragmatic programmer]]></category>
		<category><![CDATA[wetware]]></category>

		<guid isPermaLink="false">http://shlrm.org/wordpress/?p=145</guid>
		<description><![CDATA[I haven&#8217;t yet completed an entire application in ruby (well that&#8217;s not completly true) and I&#8217;m already off on something different. Groovy feels like Ruby (the name even sounds like it!) but it&#8217;s closer to java than Ruby is. That&#8217;s good for me to rapidly do stuff. I&#8217;ve found that whilst I do enjoy learning <a href='http://shlrm.org/wordpress/2008/12/18/pragmatic-groovy-and-thinking-and-learning-oh-my/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>I haven&#8217;t yet completed an entire application in ruby (well that&#8217;s not completly true) and I&#8217;m already off on something different.</p>
<p>Groovy feels like Ruby (the name even sounds like it!) but it&#8217;s closer to java than Ruby is. That&#8217;s good for me to rapidly do stuff. I&#8217;ve found that whilst I do enjoy learning new languages and new frameworks, when I want to get stuff done learning the stuff is somewhat of a hindrance for me. Groovy, and it&#8217;s framework Grails, shows promise to be the best of both worlds. I (possibly foolishly) purchased the PDF and the Paper copy of <a href="http://www.pragprog.com/titles/vslg/programming-groovy">Programming Groovy</a> from the Pragmatic Programmers.</p>
<p>I think that if I were to have a favorite publisher, it&#8217;d be them. They&#8217;re fairly new, about <a href="http://www.pragprog.com/happy-fifth-anniversary">five years old</a>, and located in Texas. I&#8217;ve spent more on books through them than just about anywhere else. And I haven&#8217;t been dissappointed yet. I also purchased <a href="http://www.pragprog.com/titles/ahptl/pragmatic-thinking-and-learning">Pragmatic Thinking and Learning</a>. I&#8217;m hoping this will help me become more proficient in learning things. It also is somewhat of an interesting subject to me; mastering the mind to further enhance my ability to learn and become an expert in my field.</p>
<p>If you&#8217;re looking for some good programming books, I can highly reccomend <a href="http://www.pragprog.com/">The Pragmatic Bookstore</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://shlrm.org/wordpress/2008/12/18/pragmatic-groovy-and-thinking-and-learning-oh-my/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

