<?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>amazing development &#187; articles</title>
	<atom:link href="http://amazing-development.com/archives/category/articles/feed/" rel="self" type="application/rss+xml" />
	<link>http://amazing-development.com</link>
	<description>ruby, java and the rest</description>
	<lastBuildDate>Thu, 20 May 2010 06:31:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Code reviews work</title>
		<link>http://amazing-development.com/archives/2009/02/22/code-reviews-work/</link>
		<comments>http://amazing-development.com/archives/2009/02/22/code-reviews-work/#comments</comments>
		<pubDate>Sun, 22 Feb 2009 20:24:50 +0000</pubDate>
		<dc:creator>Frank Spychalski</dc:creator>
				<category><![CDATA[articles]]></category>
		<category><![CDATA[comments]]></category>
		<category><![CDATA[google]]></category>

		<guid isPermaLink="false">http://amazing-development.com/?p=354</guid>
		<description><![CDATA[Seems like nowadays I only write blog posts in response to other blog articles&#8230; But I hope this is better than not writing at all. Ted Neward asks if code reviews do actually work because evidence suggests, that the scientific review process does not. Only 8% members of the Scientific Research Society agreed that &#8220;peer [...]]]></description>
			<content:encoded><![CDATA[<p>Seems like nowadays I only write blog posts in response to other blog articles&#8230; But I hope this is better than not writing at all. <a href="http://blogs.tedneward.com/2009/02/22/As+For+Peer+Review+Code+Review.aspx">Ted Neward asks if code reviews do actually work</a> because evidence suggests, that the scientific review process does not.<span id="more-354"></span></p>
<p><a href="http://en.wikipedia.org/wiki/File:Hooke-microscope.png"><img class="alignright" src="http://static.amazing-development.com/blog_images/09/microscope.png"/></a></p>
<blockquote><p>Only 8% members of the Scientific Research Society agreed that &#8220;peer review works well as it is&#8221;. (Chubin and Hackett, 1990; p.192).</p>
<p>&#8220;A recent U.S. Supreme Court decision and an analysis of the peer review system substantiate complaints about this fundamental aspect of scientific research.&#8221; (Horrobin, 2001)</p>
<p>Horrobin concludes that peer review &#8220;is a non-validated charade whose processes generate results little better than does chance.&#8221; (Horrobin, 2001). This has been statistically proven and reported by an increasing number of journal editors.</p>
<p>But, &#8220;Peer Review is one of the sacred pillars of the scientific edifice&#8221; (Goodstein, 2000), it is a necessary condition in quality assurance for Scientific/Engineering publications, and &#8220;Peer Review is central to the organization of modern science…why not apply scientific [and engineering] methods to the peer review process&#8221; (Horrobin, 2001).</p>
<p>&#8230;</p>
<p>Chubin, D. R. and Hackett E. J., 1990, Peerless Science, Peer Review and U.S. Science Policy; New York, State University of New York Press.</p>
<p>Horrobin, D., 2001, &#8220;Something Rotten at the Core of Science?&#8221; Trends in Pharmacological Sciences, Vol. 22, No. 2, February 2001. Also at <a href="http://www.whale.to/vaccine/sci.html">http://www.whale.to/vaccine/sci.html</a> and <a href="http://post.queensu.ca/~forsdyke/peerrev4.htm">http://post.queensu.ca/~forsdyke/peerrev4.htm</a> (both pages were accessed on February 1, 2009)</p>
<p>Goodstein, D., 2000, &#8220;How Science Works&#8221;, U.S. Federal Judiciary Reference Manual on Evidence, pp. 66-72 (referenced in Hoorobin, 2000)</p></blockquote>
<p>This sounds so true to me. I heard way more than one story from Ph.D. students where the professors who were supposed to review papers just forwarded this work to their slaves.</p>
<p>But the fact that academic peer reviews are possibly a failure should not be used to argue against the usefulness of code reviews.</p>
<p><b>As a reviewee</b><br />
My first project at Google was written in Python. I had never written a single line of Python before. The feedback I got from the first few reviews helped me learn a lot about Python in a very short time. I don&#8217;t know how many times I got these &#8220;Yes, this would work but if you replace these 6 lines with that short statement it would work, too&#8221; comments.</p>
<p>The same is true for my second project in C++. I have written some C++ before but this was for my Diploma thesis and the code was far from professional. Again the feedback I got from my reviewers helped me learn C++ a lot faster than I would have otherwise. This project was a lot bigger than the first one so I got a few &#8220;we already have this implemented here&#8221; comments.</p>
<p><b>As a reviewer</b><br />
I usually don&#8217;t pay that much attention to our coding conventions but my pet peeve is looking out for missing comments. Every time I have to think about a single line of code, this is a pretty good signal that a comment is missing.</p>
<p>Reviewing other people&#8217;s code makes sure that I have at least a little knowledge about the areas of our project I do not work on directly.</p>
<p><b>Conclusion</b><br />
Code reviews take time and need the proper tool support. But if it is done right, they are useful and help in a couple of different areas:</p>
<ul>
<li>Learning a new language or about new piece of code.</li>
<li>Avoiding code duplication.</li>
<li>Making sure code is documented.</li>
<li>Distribute the knowledge.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://amazing-development.com/archives/2009/02/22/code-reviews-work/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Playing on the CodeGolf Range</title>
		<link>http://amazing-development.com/archives/2006/08/07/playing-on-the-codegolf-range/</link>
		<comments>http://amazing-development.com/archives/2006/08/07/playing-on-the-codegolf-range/#comments</comments>
		<pubDate>Mon, 07 Aug 2006 19:51:14 +0000</pubDate>
		<dc:creator>Frank Spychalski</dc:creator>
				<category><![CDATA[Computer]]></category>
		<category><![CDATA[Fun]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[articles]]></category>

		<guid isPermaLink="false">http://amazing-development.com/archives/2006/08/07/playing-on-the-codegolf-range/</guid>
		<description><![CDATA[I stumbled over this funny site called CodeGolf.com and tried my luck on the first problem (actually it&#8217;s the sixth, but it was the last and therefore appeared first on their page &#8211; confused?) Writing a Brainfuck Interpreter: The brainfuck language uses a simple model of a computer consisting of an array of memory cells, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://flickr.com/photos/bigpru/159144054/"><img alt="picture by bigpru" class="framedr" src="http://static.amazing-development.com/blog_images/golf_1.jpg"/></a></p>
<p>I stumbled over this funny site called <a href="http://codegolf.com">CodeGolf.com</a> and tried my luck on the first problem (actually it&#8217;s the sixth, but it was the last and therefore appeared first on their page &#8211; confused?) <a href="http://www.codegolf.com/competition/index/8">Writing a Brainfuck Interpreter</a>:</p>
<blockquote><p>
The brainfuck language uses a simple model of a computer consisting of an array of memory cells, a movable pointer into the array, an output stream, an input stream and the program itself.  The program is formed from a sequence of the below commands :</p>
<ul>
<li><strong><code>&gt;</code></strong> &#8211; Increment the pointer to point to the next cell to the right.</li>
<li><strong><code>&lt;</code></strong> &#8211; Decrement the pointer to point to the next cell to the left.</li>
<li><strong><code>+</code></strong> &#8211; Increment the byte pointed to by the pointer.</li>
<li><strong><code>-</code></strong> &#8211; Decrement the byte pointed to by the pointer.</li>
<li><code><strong>[</strong></code> - Jump forward to the command after the corresponding <strong><code>]</code></strong> if the byte at the pointer is zero.</li>
<li><strong><code>]</code></strong> &#8211; Jump back to the command after the corresponding <strong><code>[</code></strong> if the byte at the pointer is non-zero.</li>
<li><strong><code>.</code></strong> - Output the value of the byte at the pointer.</li>
<li><strong><code>,</code></strong> - Accept one byte of input, storing its value in the byte at the pointer.</li>
</ul>
</blockquote>
<p>It didn't take me very long to write a running interpreter. My first version was more than a thousand characters. Even after renaming the variables and stripping all the whitespaces I still needed around 700 characters, which is huge compared to the best Ruby solution with only 142 characters.<span id="more-245"></span></p>
<p style="margin-top:10%"/>
<h2>Warning! Spoilers ahead - you might want to stop reading if you want to solve the problem, too</h2>
<p style="margin-top:50%"/>
<h2>Brainfuck Interpreter Version 1 - a real interpreter</h2>
<p>This was my very first idea. The algorithm is pretty obvious and nothing really fancy was done here. Two optimizations:</p>
<ul>
<li>aggregated the + and - operation and &lt; and &gt; into one <tt>when</tt> each to save space</li>
<li>iterate over the input program to get the target addresses for the jump operations</li>
</ul>
<p>But this code was still too slow. It passed the first 5 tests, but failed the rot13 performance test.</p>
<pre><code class="ruby"># Version 1 after a lot of rewrites

data = Array.new(30000,0)
datapointer = 0
codepointer = 0

(code,input) = STDIN.read.chomp.split '!'

# build a jump table to quickly access target address to jump to
stack = []
jmptbl = {}
(0..(code.size-1)).each {|i|
  case code[i]
    when 91: stack.push i
    when 93: m = stack.pop; jmptbl[i] = m; jmptbl[m] = i
  end
}

while codepointer &lt; code.size do
  x = code[codepointer]
  case x
# &lt; &gt;
    when 60, 62: datapointer = datapointer + x - 61
# + -
    when 43, 45: data[datapointer] = (data[datapointer] - x + 44) % 256
# [
    when 91: codepointer = (data[datapointer] == 0 ? jmptbl[codepointer] : codepointer)
# ]
    when 93: codepointer = (data[datapointer] != 0 ? jmptbl[codepointer] : codepointer)
# .
    when 46: print "#{data[datapointer].chr}"
# ,
    when 44: data[datapointer] = input.slice!(0)
             exit if data[datapointer].nil?
  end
  codepointer = codepointer + 1
end
</code></pre>
<pre><code class="ruby"># Version 1 obfuscated
# 389 characters without this comment
d=Array.new(30000,0)
a=0
b=0
(c,k)=STDIN.read.chomp.split'!'
s=[]
j={}
(0..(c.size-1)).each{|i|
case c[i]
when 91:s.push i
when 93:m=s.pop;j[i]=m;j[m]=i
end
}
while b&lt;c.size do
x=c[b]
case x
when 60,62:a=a+x-61
when 43,45:d[a]=(d[a]-x+44)%256
when 91:b=(d[a]==0?j[b]:b)
when 93:b=(d[a]!=0?j[b]:b)
when 46:print"#{d[a].chr}"
when 44:d[a]=k.slice!(0)
exit if d[a].nil?
end
b=b+1
end</code></pre>
<h2>Brainfuck Interpreter Version 2 - "optimize - don't do it"</h2>
<p>This code contains many useless optimizations <img src='http://amazing-development.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  </p>
<ul>
<li>store the target address inside the program as the address for ] or address plus codesize for [</li>
<li>store + and - as -255 and -257, so I can simply add the command to the data</li>
</ul>
<p>But these optimizations didn't provide any significant speedup, the code was only about 10 percent faster on my machine which was still too slow to pass the performance test. And the program was even larger than my original version with 533 characters. I could perhaps squeeze out a few characters with a complicated formula for the first 6 lines of the case statement, but I didn't try this because this version was too slow anyway.</p>
<pre><code class="ruby"># version 2 - forget it, it sucks
data = Array.new(30000,0)
codepointer = 0
datapointer = 0

(code,input) = STDIN.read.chomp.split '!'

codesize = code.size
stack = []
opt = []
(0..(codesize-1)).each {|i|
  case code[i]
    when 60: opt &lt;&lt; -3
    when 62: opt &lt;&lt; -1
    when 43: opt &lt;&lt; -255
    when 45: opt &lt;&lt; -257
    when 44: opt &lt;&lt; -5
    when 46: opt &lt;&lt; -6
    when 91: stack.push opt.size; opt &lt;&lt; 0 # just a placeholder
    when 93: m = stack.pop; opt[m] = opt.size + codesize; opt &lt;&lt; m
  end
}
while codepointer &lt; opt.size do
  x = opt[codepointer]
  if x &lt; -200
    data[datapointer] = (data[datapointer] + x) % 256
  elsif x &lt; -3
    if x == -5
      data[datapointer] = input.slice!(0)
      exit if data[datapointer].nil?
    else
      print "#{data[datapointer].chr}"
    end
  elsif x &lt; 0
    datapointer = datapointer + x + 2
  else
    if x &lt; codesize
      codepointer = (data[datapointer] != 0 ? x : codepointer)
    else
      codepointer = (data[datapointer] == 0 ? x % codesize : codepointer)
    end
  end
  codepointer = codepointer + 1
end
</code></pre>
<h2>Brainfuck Interpreter Version 3 - Brainfuck to Ruby</h2>
<p>As I realized I wasn't going to pass the performance test with my other ideas I knew I had to generate Ruby code. The tricky part was how to simulate the commands "[" and "]". I started with the "Hello World!" Brainfuck program and rewrote it step by step in Ruby until I had an idea on how to replace every character of the input language with a chunk of Ruby code. </p>
<p><a href="http://flickr.com/photos/digitalsextant/38310146/"><img alt="picture by digitalsextant" class="framedr" src="http://static.amazing-development.com/blog_images/golf_2.jpg"/></a></p>
<table border="1" cellpadding="3">
<tr>
<td colspan="2" align="center">My translation table:</td>
</tr>
<tr>
<td>[</td>
<td><tt>if currentCell != 0<br />
begin</tt></td>
</tr>
<tr>
<td>]</td>
<td><tt>end while currentCell != 0<br />
end</tt></td>
</tr>
<tr>
<td>&lt;</td>
<td><tt>plus -1</tt></td>
</tr>
<tr>
<td>&gt;</td>
<td><tt>plus 1</tt></td>
</tr>
<tr>
<td>+</td>
<td><tt>inc 1</tt></td>
</tr>
<tr>
<td>-</td>
<td><tt>inc -1</tt></td>
</tr>
<tr>
<td>.</td>
<td><tt>out</tt></td>
</tr>
<tr>
<td>,</td>
<td><tt>read</tt></td>
</tr>
</table>
<p>The definitions for the methods are shown below. The whole program was slightly larger than my version 1 but it is about 3 times faster, which was fast enough to pass the performance test.</p>
<pre><code class="ruby"># Version 3
def currentCell
  $data[$datapointer] || 0
end
def inc i
  $datapointer = $datapointer + i
end
def plus i
  $data[$datapointer] = currentCell + i) % 256
end
def out
  print "#{currentCell.chr}"
end
def read
  $data[$datapointer] = $input.slice!(0)
  exit if !$data[$datapointer]
end
def append s
  $program &lt;&lt; s &lt;&lt; "
"
end

$program = ''
$data = []
$datapointer = 0

($code,$input) = STDIN.read.chomp.split '!'

(0..($code.size-1)).each {|i|
  tmp = $code[i]
  case tmp
    when 60,62: append "inc #{tmp-61}"
    when 43,45: append "plus #{44-tmp}"
    when 91: append "if currentCell != 0
begin"
    when 93: append"end while currentCell != 0
end"
    when 46: append "out"
    when 44: append "read"
  end
}
eval $program </code></pre>
<pre><code class="ruby"># Version 3 obfuscated
# 401 characters without this comment
def x
$d[$a]||0
end
def y i
$a=$a+i
end
def v i
$d[$a]=(x+i)%256
end
def t
print"#{x.chr}"
end
def u
$d[$a]=$k.slice!(0)
exit if !$d[$a]
end
def r s
$p&lt;&lt;s&lt;&lt;"
"
end
$p=''
$d=[]
$a=0
($c,$k)=STDIN.read.chomp.split'!'
(0..($c.size-1)).each{|i|
q=$c[i]
case q
when 60,62:r"y #{q-61}"
when 43,45:r"v #{44-q}"
when 91:r"if x!=0
begin"
when 93:r"end while x!=0
end"
when 46:r"t"
when 44:r"u"
end
}
eval $p</code></pre>
<h2>What's next?</h2>
<p>I had a lot of fun writing these different versions. But now I'm stuck. I don't have the slightest clue on how to get to an even shorter piece of code. I already tried to add a method which generates the methods <tt>currentCell</tt>, <tt>inc</tt>, etc. but the overhead of one added method was more than what I gained by removing <tt>def</tt> and <tt>end</tt>.<br />
I'm still thinking about other possible techniques to move towards the 142 byte by <i>carldr</i>. I believe there is a trick that uses special knowledge of the Brainfuck language I just don't have. If anybody has some generic hints on how to write shorter Ruby code, please leave a note <img src='http://amazing-development.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://amazing-development.com/archives/2006/08/07/playing-on-the-codegolf-range/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Getting rid of Hypersonic Db in Jboss 4</title>
		<link>http://amazing-development.com/archives/2006/07/13/jbosshypersonic-annoyance/</link>
		<comments>http://amazing-development.com/archives/2006/07/13/jbosshypersonic-annoyance/#comments</comments>
		<pubDate>Thu, 13 Jul 2006 13:54:03 +0000</pubDate>
		<dc:creator>Frank Spychalski</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[articles]]></category>

		<guid isPermaLink="false">http://amazing-development.com/archives/2006/07/13/jbosshypersonic-annoyance/</guid>
		<description><![CDATA[I don&#8217;t know how much time I could have saved, if someone told me I should not use the hypersonic database for a production JBoss system. jboss.org/wiki: hsqldb is not a production quality database. I haven&#8217;t found a good tutorial, even the JBoss Developer&#8217;s Notebook wasn&#8217;t exhaustive, so here are my notes: How to remove [...]]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t know how much time I could have saved, if someone told me I should not use the hypersonic database for a production JBoss system.</p>
<blockquote><p><a href="http://wiki.jboss.org/wiki/Wiki.jsp?page=ConfigJBossMQDB">jboss.org/wiki</a>:<br />
hsqldb is not a production quality database.</p></blockquote>
<p><span id="more-236"></span><br />
I haven&#8217;t found a good tutorial, even the <a href="http://www.amazon.com/gp/redirect.html?link_code=ur2&#038;tag=amazingdevelo-20&#038;camp=1789&#038;creative=9325&#038;location=http%3A%2F%2Fwww.amazon.com%2Fgp%2Fproduct%2F0596100078%2Fref%3Dsr_11_1%3Fie%3DUTF8">JBoss Developer&#8217;s Notebook</a> wasn&#8217;t exhaustive, so here are my notes:</p>
<h3>How to remove the hypersonice db from JBoss</h3>
<ol>
<li>Remove datasource:<br />
delete <tt>deploy/hsqldb-ds.xml</tt></li>
<li>Add new datasource:<br />
for MySql add a file named <tt>deploy/mysql-ds.xml</tt> or whatever you like with something like:</p>
<pre><textarea wrap="off" class="code" rows="16" readonly>&lt;datasources&gt;
    &lt;local&#45;tx&#45;datasource&gt;
        &lt;jndi&#45;name&gt;MySqlDS&lt;/jndi&#45;name&gt;
        &lt;connection&#45;url&gt;jdbc&#58;mysql&#58;//localhost&#58;3306/datasource&lt;/connection&#45;url&gt;
        &lt;driver&#45;class&gt;com.mysql.jdbc.Driver&lt;/driver&#45;class&gt;
        &lt;user&#45;name&gt;myuser&lt;/user&#45;name&gt;
        &lt;password&gt;mypwd&lt;/password&gt;
        &lt;exception&#45;sorter&#45;class&#45;name&gt;
            org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter
        &lt;/exception&#45;sorter&#45;class&#45;name&gt;

        &lt;metadata&gt;
            &lt;type&#45;mapping&gt;mySQL&lt;/type&#45;mapping&gt;
        &lt;/metadata&gt;
    &lt;/local&#45;tx&#45;datasource&gt;
&lt;/datasources&gt;</textarea></pre>
<p>You should use <tt>MySqlDS</tt> as the jndi-name or you have to edit <tt>mysql-jdbc2-service.xml</tt> later</li>
<li>Use new datasource:<br />
find all references to <tt>DefaultDS</tt> and replace them with <tt>MySqlDS</tt> and all references to <tt>Hypersonic SQL</tt> with <tt>mySQL</tt></li>
<li>Configure jms:<br />
delete <tt>deploy/jms/hsqldb-jdbc2-service.xml</tt> and replace it with <tt>doc/examples/jms/mysql-jdbc2-service.xml</tt> and don&#8217;t forget to <a href="http://wiki.jboss.org/wiki/Wiki.jsp?page=ConfigJBossMQDB">edit mysql-jdbc2-service.xml</a></p>
<blockquote><p>Edit the persistence configuration and change the line :-</p>
<p>SELECT_MAX_TX = SELECT MAX(TXID) FROM (SELECT MAX(TXID) AS TXID FROM JMS_TRANSACTIONS UNION SELECT MAX(TXID) AS TXID FROM JMS_MESSAGES)</p>
<p>to: -</p>
<p>SELECT_MAX_TX = SELECT MAX(TXID) FROM JMS_MESSAGES </p></blockquote>
</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://amazing-development.com/archives/2006/07/13/jbosshypersonic-annoyance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Road to Ruby enlightenment &#8211; lambda, proc etc.</title>
		<link>http://amazing-development.com/archives/2006/07/02/road-to-ruby-enlightenment-lambda-proc-etc/</link>
		<comments>http://amazing-development.com/archives/2006/07/02/road-to-ruby-enlightenment-lambda-proc-etc/#comments</comments>
		<pubDate>Sun, 02 Jul 2006 12:39:37 +0000</pubDate>
		<dc:creator>Frank Spychalski</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[articles]]></category>

		<guid isPermaLink="false">http://amazing-development.com/archives/2006/07/02/road-to-ruby-enlightenment-lambda-proc-etc/</guid>
		<description><![CDATA[This is the fourth part of my Road to Ruby enlightenment. It started a long time ago with tutorials and first steps. Road&#160;To&#160;Ruby&#160;Enlightenment 1. tutorials and first steps 2. talk, quiz and cookbook 3. red and gray 4. lambda, proc etc. Blocks and closures are one of the reasons why you can do magic in [...]]]></description>
			<content:encoded><![CDATA[<p>This is the fourth part of my Road to Ruby enlightenment. It started a long time ago with <a href="http://amazing-development.com/archives/2006/05/05/road-to-ruby-enlightenment-tutorials-and-first-steps/">tutorials and first steps</a>.<span id="more-234"></span></p>
<div style="float:right; padding:10pt; border:1px black solid; margin-left:10pt;margin-top:0pt; margin-bottom:10pt;background-color: #e8e8e8;">
<b>Road&nbsp;To&nbsp;Ruby&nbsp;Enlightenment</b><br />
1. <a href="http://amazing-development.com/archives/2006/05/05/road-to-ruby-enlightenment-tutorials-and-first-steps/">tutorials and first steps</a><br />
2. <a href="http://amazing-development.com/archives/2006/05/08/road-to-ruby-enlightenment-talk-quiz-and-cookbook">talk, quiz and cookbook</a><br />
3. <a href="http://amazing-development.com/archives/2006/05/16/road-to-ruby-enlightenment-red-and-gray/">red and gray</a><br />
4. <b>lambda, proc etc.</b></div>
<p>Blocks and closures are one of the reasons why you can do magic in Ruby. Some time ago I read <a href="http://eli.thegreenplace.net">Eli&#8217;s</a> <a href="http://eli.thegreenplace.net/2006/04/18/understanding-ruby-blocks-procs-and-methods">Understanding Ruby blocks, Procs and methods</a> which does a great job of explainig the whole topic. As long as it doesn&#8217;t involve some high-level ruby magic (like Why&#8217;s <a href="http://redhanded.hobix.com/inspect/aBlockCostume.html">A Block Costume</a>) I felt like I understood most of the code using closure-like constructs.</p>
<p>When I used closures in my own code, every once in a while something would not work the way I expected it to. I always found a workaround and never spend much time worrying about these oddities. </p>
<p>This morning (via <a href="http://feeds.feedburner.com/RubyInside?m=119">Ruby Inside</a>) I found <a href="http://innig.net/software/ruby/closures-in-ruby.rb">closures-in-ruby.rb</a> by <a href="http://innig.net">Paul Cantrell</a>. Seems like he had the same problems but instead of ignoring them he played around and documented the things he found out. The article highlights some suprises and differences between the 7 ways of creating closure-like thingies in ruby. Highly recommended reading!</p>
]]></content:encoded>
			<wfw:commentRss>http://amazing-development.com/archives/2006/07/02/road-to-ruby-enlightenment-lambda-proc-etc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Road to Ruby enlightenment &#8211; red and gray</title>
		<link>http://amazing-development.com/archives/2006/05/16/road-to-ruby-enlightenment-red-and-gray/</link>
		<comments>http://amazing-development.com/archives/2006/05/16/road-to-ruby-enlightenment-red-and-gray/#comments</comments>
		<pubDate>Tue, 16 May 2006 07:57:29 +0000</pubDate>
		<dc:creator>Frank Spychalski</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[articles]]></category>

		<guid isPermaLink="false">http://amazing-development.com/archives/2006/05/16/road-to-ruby-enlightenment-red-and-gray/</guid>
		<description><![CDATA[This is the third part of my Road to Ruby enlightenment. It started with tutorials and first steps. Road&#160;To&#160;Ruby&#160;Enlightenment 1. tutorials and first steps 2. talk, quiz and cookbook 3. red and gray 4. lambda, proc etc. RedHanded RedHanded is Why&#8217;s (from Why’s (Poignant) Guide to Ruby) blog. I don&#8217;t really know why I didn&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>This is the third part of my Road to Ruby enlightenment. It started with <a href="http://amazing-development.com/archives/2006/05/05/road-to-ruby-enlightenment-tutorials-and-first-steps/">tutorials and first steps</a>.<span id="more-222"></span></p>
<div style="float:right; padding:10pt; border:1px black solid; margin-left:10pt;margin-top:0pt; margin-bottom:10pt;background-color: #e8e8e8;">
<b>Road&nbsp;To&nbsp;Ruby&nbsp;Enlightenment</b><br />
1. <a href="http://amazing-development.com/archives/2006/05/05/road-to-ruby-enlightenment-tutorials-and-first-steps/">tutorials and first steps</a><br />
2. <a href="http://amazing-development.com/archives/2006/05/08/road-to-ruby-enlightenment-talk-quiz-and-cookbook">talk, quiz and cookbook</a><br />
3. <b>red and gray</b><br />
4. <a href="http://amazing-development.com/archives/2006/07/02/road-to-ruby-enlightenment-lambda-proc-etc/">lambda, proc etc.</a></div>
<p><b>RedHanded</b></p>
<p><a href="http://redhanded.hobix.com/">RedHanded</a> is Why&#8217;s (from <a href="http://poignantguide.net/ruby/">Why’s (Poignant) Guide to Ruby</a>) blog. I don&#8217;t really know why I didn&#8217;t check out his blog earlier when I read WPGtR but I didn&#8217;t. </p>
<p><img class="alignleft" src="http://static.amazing-development.com/blog_images/camping.png"/>But I think this was a good thing, because I already knew a little bit about Ruby when I stumbled over his blog. This made reading his dazzling display of ruby magic more fun, like watching a stage magician with a slight chance of understanding and appreciating his tricks. </p>
<p>Go and check out <a href="http://redhanded.hobix.com/bits/">bits</a> and <a href="http://redhanded.hobix.com/inspect/">inspect</a>. My all time favorint post is <a href="http://redhanded.hobix.com/bits/campingAMicroframework.html">Camping Microframework</a>, the code is cryptic and I cannot say I understand it but the whole post is hilarious (<a href="http://camping.rubyforge.org/files/README.html">here</a> is the real docu for Camping, a &lt;4kb webframework).</p>
<p><b>Shades of Gray</b> </p>
<p><a href="http://www.amazon.com/exec/obidos/ASIN/1558607013/amazingdevelo-20?creative=327641&#038;camp=14573&#038;adid=0W6YKP7WDAWCPYNW86C0&#038;link_code=as1"><img class="alignright" src="http://rcm-images.amazon.com/images/P/1558607013.01._SL110_SCTZZZZZZZ_.jpg"/></a></p>
<p>In another post on this blog I asked for <a href="http://amazing-development.com/archives/2006/04/11/advanced-articles-on-ruby/">advanced articles on ruby</a> and <a href="http://on-ruby.blogspot.com/">Pat</a> pointed me to <a href="http://blog.grayproductions.net/">Shades of Gray</a>. I already knew the author James Edward Gray II as the organizer of the Ruby Quiz. Shades of Gray contains exactly the kind of articles I was looking for all the time. The only sad thing is that it contains only a handful of these articles. His <a href="http://blog.grayproductions.net/articles/category/higher-order-ruby">Higher Order Ruby</a> posts provide Ruby translations of the example code from the book <a href="http://www.amazon.com/exec/obidos/ASIN/1558607013/amazingdevelo-20?creative=327641&#038;camp=14573&#038;adid=0W6YKP7WDAWCPYNW86C0&#038;link_code=as1">Higher Order Perl</a>, his <a href="http://blog.grayproductions.net/articles/category/ruby-tutorials">Ruby tutorials</a> are among the best I&#8217;ve ever read and his other posts are worth reading, too.</p>
<p>If you read only a single sentence about good ruby style, it should be this one from <a href="http://blog.grayproductions.net/articles/2006/01/05/code-as-a-data-type">Code as a Data Type</a>:</p>
<blockquote><p>In my experience, you know you&#8217;re doing Ruby right when you are dropping code and gaining functionality</p></blockquote>
<p>This is true for almost any language, but in Ruby it is especially elegant to do. I guess this is the reason why I like programming in Ruby, it gives you the ability to write very compact but still readable code.</p>
<p>I&#8217;m getting pretty close to the present, but I hope I will find enough content for another post in this series so check again later&#8230;</p>
<p>BTW, if you have recommendations with other sites/articles/books on good ruby style, please let me know.</p>
]]></content:encoded>
			<wfw:commentRss>http://amazing-development.com/archives/2006/05/16/road-to-ruby-enlightenment-red-and-gray/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Road to Ruby enlightenment &#8211; talk, quiz and cookbook</title>
		<link>http://amazing-development.com/archives/2006/05/08/road-to-ruby-enlightenment-talk-quiz-and-cookbook/</link>
		<comments>http://amazing-development.com/archives/2006/05/08/road-to-ruby-enlightenment-talk-quiz-and-cookbook/#comments</comments>
		<pubDate>Mon, 08 May 2006 09:41:32 +0000</pubDate>
		<dc:creator>Frank Spychalski</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[articles]]></category>

		<guid isPermaLink="false">http://amazing-development.com/archives/2006/05/08/road-to-ruby-enlightenment-talk-quiz-and-cookbook/</guid>
		<description><![CDATA[This is the second leg on the Road to Ruby enlightenment. It started with tutorials and first steps. Road&#160;To&#160;Ruby&#160;Enlightenment 1. tutorials and first steps 2. talk, quiz and cookbook 3. red and gray 4. lambda, proc etc. Ruby-talk From ruby-lang.org I followed some links to the Ruby FAQ. Like the tutorials I read, the FAQ [...]]]></description>
			<content:encoded><![CDATA[<p>This is the second leg on the Road to Ruby enlightenment. It started with <a href="http://amazing-development.com/archives/2006/05/05/road-to-ruby-enlightenment-tutorials-and-first-steps/">tutorials and first steps</a>.<span id="more-221"></span></p>
<div style="float:right; padding:10pt; border:1px black solid; margin-left:10pt;margin-top:0pt; margin-bottom:10pt;background-color: #e8e8e8;">
<b>Road&nbsp;To&nbsp;Ruby&nbsp;Enlightenment</b><br />
1. <a href="http://amazing-development.com/archives/2006/05/05/road-to-ruby-enlightenment-tutorials-and-first-steps/">tutorials and first steps</a><br />
2. <b>talk, quiz and cookbook</b><br />
3. <a href="http://amazing-development.com/archives/2006/05/16/road-to-ruby-enlightenment-red-and-gray/">red and gray</a><br />
4. <a href="http://amazing-development.com/archives/2006/07/02/road-to-ruby-enlightenment-lambda-proc-etc/">lambda, proc etc.</a></div>
<p><b>Ruby-talk</b></p>
<p>From <a href="http://ruby-lang.org">ruby-lang.org</a> I followed some links to the <a href="http://www.rubygarden.org/faq">Ruby FAQ</a>. Like the tutorials I read, the FAQ itself answered only questions regarding the language Ruby but lacked information about &#8216;good style&#8217; or &#8216;the Ruby Way&#8217;. But the FAQ pointed me to the <a href="http://www.ruby-lang.org/en/20020104.html">Ruby Talk Mailinglist</a>. A few minutes later I was subscribed and messages started to come in<a href="#1">[1]</a>. There are just too many good posts to single out just a few. The mailing list archive (sorry) sucks, but fortunately the list is replicated via a ML-NetNews gateway with comp.lang.ruby which makes it possible to search for old posts via groups.google.com etc.</p>
<p><b>Ruby Quiz</b></p>
<p>After some time I noticed these strange posts to ruby-talk which had a [QUIZ] in the subject. I found the answer on <a href="http://rubyquiz.com/">rubyquiz.com</a>:</p>
<blockquote><p><i>What Is Ruby Quiz?</i><br />
Ruby Quiz is a weekly programming challenge for Ruby programmers in the spirit of the Perl Quiz of the Week. A new Ruby Quiz is sent to the Ruby Talk mailing list each Friday. (Watch for the [QUIZ] subject identifier.) After a 48 hour no-spoiler period has passed, everyone is invited to contribute solutions and/or discussion back to the list. The following Thursday a Summary will be sent to the list, discussing the quiz, solutions and discussion. The next day, the cycle begins again.</p></blockquote>
<p>The quiz is run by James Edward Gray II, who collects the solutions and writes a summary. A collection of quiz questions and solutions can be found on <a href="http://rubyquiz.com/">rubyquiz.com</a>.</p>
<p>My favorites:</p>
<ul>
<li><a href="http://rubyquiz.com/quiz22.html">Roman Numerals (#22)</a><br />
the last part, about how to add Roman Numeral Constants</li>
<li><a href="http://rubyquiz.com/quiz26.html">Code Cleaning (#26)</a><br />
how to unobfuscate Ruby code</li>
<li><a href="http://rubyquiz.com/quiz29.html">HighLine (#29)</a><br />
useful and I did learn something</li>
<li><a href="http://rubyquiz.com/quiz38.html">SerializableProc (#38)</a><br />
magic, especially Florian&#8217;s solution</li>
<li><a href="http://rubyquiz.com/quiz43.html">Sodoku Solver (#43)</a><br />
I like sudokus and I like Ruby&#8230;</li>
<li><a href="http://rubyquiz.com/quiz61.html">Dice Roller (#61)</a><br />
the old roleplayer came through, this was the first quiz I played around with</li>
</ul>
<p><b>PLEAC &#8211; Programming Language Examples Alike Cookbook</b></p>
<p>Another link I found via the FAQ was <a href="http://pleac.sourceforge.net/pleac_ruby/">PLEAC-Ruby</a>, a cookbook with a huge number of code samples. BTW, the <a href="http://pleac.sourceforge.net/">PLEAC Project</a> has cookbooks for other languages, too. Most of the examples were pretty obvious, but I recommend browsing through</p>
<ul>
<li><a href="http://pleac.sourceforge.net/pleac_ruby/arrays.html">Arrays</a> and <a href="http://pleac.sourceforge.net/pleac_ruby/hashes.html">Hashes</a>, just to see more examples on what to do with them</li>
<li><a href="http://pleac.sourceforge.net/pleac_ruby/patternmatching.html">Patternmatching</a> if you can&#8217;t remember all the regex magic</li>
<li><a href="http://pleac.sourceforge.net/pleac_ruby/packagesetc.html">Packages etc.</a> and <a href="http://pleac.sourceforge.net/pleac_ruby/classesetc.html">Classes etc.</a></li>
</ul>
<p>But like most of the documentation found online, it was more about code and less about style. </p>
<p>Check back later, there is still more to come <img src='http://amazing-development.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p><a name="1">[1]</a> I read my share of mailinglists, but ruby-talk is the only list with such a high volume which still has a low rate of flamewars, bashing, etc. Keep it up guys, even though I don&#8217;t write much, I really like reading this list.</p>
]]></content:encoded>
			<wfw:commentRss>http://amazing-development.com/archives/2006/05/08/road-to-ruby-enlightenment-talk-quiz-and-cookbook/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Road to Ruby enlightenment &#8211; tutorials and first steps</title>
		<link>http://amazing-development.com/archives/2006/05/05/road-to-ruby-enlightenment-tutorials-and-first-steps/</link>
		<comments>http://amazing-development.com/archives/2006/05/05/road-to-ruby-enlightenment-tutorials-and-first-steps/#comments</comments>
		<pubDate>Fri, 05 May 2006 09:42:35 +0000</pubDate>
		<dc:creator>Frank Spychalski</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[articles]]></category>

		<guid isPermaLink="false">http://amazing-development.com/archives/2006/05/05/road-to-ruby-enlightenment-tutorials-and-first-steps/</guid>
		<description><![CDATA[This is not a Ruby tutorial. Road&#160;To&#160;Ruby&#160;Enlightenment 1. tutorials and first steps 2. talk, quiz and cookbook 3. red and gray 4. lambda, proc etc. I heard about Ruby some years ago. I can&#8217;t remember where it was, must have been one of those perl newsgroups or mailinglists I was reading. The description was always [...]]]></description>
			<content:encoded><![CDATA[<p>This is not a Ruby tutorial.<span id="more-218"></span></p>
<div style="float:right; padding:10pt; border:1px black solid; margin-left:10pt;margin-top:0pt; margin-bottom:10pt;background-color: #e8e8e8;">
<b>Road&nbsp;To&nbsp;Ruby&nbsp;Enlightenment</b><br />
1. <b>tutorials and first steps</b><br />
2. <a href="http://amazing-development.com/archives/2006/05/08/road-to-ruby-enlightenment-talk-quiz-and-cookbook">talk, quiz and cookbook</a><br />
3. <a href="http://amazing-development.com/archives/2006/05/16/road-to-ruby-enlightenment-red-and-gray/">red and gray</a><br />
4. <a href="http://amazing-development.com/archives/2006/07/02/road-to-ruby-enlightenment-lambda-proc-etc/">lambda, proc etc.</a></div>
<p>I heard about Ruby some years ago. I can&#8217;t remember where it was, must have been one of those perl newsgroups or mailinglists I was reading. The description was always something like &#8220;Japanese Perl Clone with better Object-Orientation&#8221; which sounded neat. But as I was using Perl only for small scripts, it was not enough to make me look into the language. Last year the buzz around Ruby on Rails gave me the final push and I started to learn Ruby. This series of posts describes my learning process.</p>
<p><b>Tutorials</b></p>
<p>The first tutorial I stumpled upon was <a href="http://poignantguide.net/ruby/">Why’s (Poignant) Guide to Ruby (WPGtR)</a> which is the funniest tutorial for a programming language I ever read, but it somehow failed to teach me Ruby (I read it again later and by now I think it&#8217;s great &#8211; perhaps I just had a bad day).</p>
<p><a href="http://www.amazon.com/exec/obidos/redirect?link_code=ur2&#038;tag=amazingdevelo-20&#038;camp=1789&#038;creative=9325&#038;path=http%3A%2F%2Fwww.amazon.com%2Fgp%2Fproduct%2F0974514055%2F"><img class="framedr" src="http://images.amazon.com/images/P/0974514055.01._LCTHUMBZZZ_.jpg"/></a></p>
<p>But <a href="http://poignantguide.net/ruby/">WPGtR</a> showed me enough of Ruby to make me buy <a href="http://www.amazon.com/exec/obidos/redirect?link_code=ur2&#038;tag=amazingdevelo-20&#038;camp=1789&#038;creative=9325&#038;path=http%3A%2F%2Fwww.amazon.com%2Fgp%2Fproduct%2F0974514055%2F">Programming Ruby</a>. I really enjoyed Dave Thomas&#8217; style and read the whole book in just a few days. I highly recommend this book to anyone learning Ruby. If you want some samples first, the whole <a href="http://www.ruby-doc.org/docs/ProgrammingRuby/">first edition of Programming Ruby</a> is online. I don&#8217;t like reading online, but I use it sometimes to lookup stuff.</p>
<p>Just for completeness sake, I read a few pages of the <a href="http://en.wikibooks.org/wiki/Programming:Ruby">Programming:Ruby wikibook</a>. It is still in the making, but I hope it will become a useful resource sometime.</p>
<p>There are countless other tutorials out there. I just skimmed through <a href="http://pine.fm/LearnToProgram/">Learn To Program</a> and <a href="http://www.sapphiresteel.com/The-Little-Book-Of-Ruby">The Little Book Of Ruby (LBOR)</a> and both look pretty good at first glance. If you (like me) prefer to read your stuff offline, I recommend <a href="http://poignantguide.net/ruby/">WPGtR</a> or <a href="http://www.sapphiresteel.com/The-Little-Book-Of-Ruby">LBOR</a> which offer pdf versions.</p>
<p>After these three tutorials I knew how to write Ruby. But I was writing these programs in the same way I wrote my Java or Perl programs, without using any of the interesting Ruby features.</p>
<p><b>Rubygarden</b> </p>
<p>I found the first hints on how to improve my code on the <a href="http://www.rubygarden.org/ruby?HomePage">Rubygarden wiki</a>. I highly recommend reading at least the following few pages. There is a lot more to be found in the wiki, but like all wikis it&#8217;s damn hard to get to the good bits.</p>
<ul>
<li><a href="http://www.rubygarden.org/ruby?RubyIdioms">RubyIdioms</a><br />examples which show the difference between the naive way and <i>The Ruby Way</i></li>
<li><a href="http://www.rubygarden.org/ruby?RubyStyleGuide">RubyStyleGuide</a><br />coding conventions and some programming conventions which I found not as useful as the idioms above.</li>
<li><a href="http://www.rubygarden.org/ruby?RubyNuby">RubyNuby</a><br />a link page with pointers to a lot of useful resources in the wiki</li>
<li><a href="http://www.rubygarden.org/ruby?StandardClassExtensions">StandartClassExtensions</a><br /> extensions for standart classes, contains interesting code samples. I found this more useful than the <a href="http://www.rubygarden.org/ruby?RubyOnlineCookbook">RubyOnlineCookbook</a>. </li>
<li><a href="http://www.rubygarden.org/ruby?ExampleDesignPatternsInRuby">ExampleDesignPatternsInRuby</a><br />Code samples for some design patterns</li>
</ul>
<p>The journey continues <a href="http://amazing-development.com/archives/2006/05/08/road-to-ruby-enlightenment-talk-quiz-and-cookbook/">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://amazing-development.com/archives/2006/05/05/road-to-ruby-enlightenment-tutorials-and-first-steps/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Errorhandling Ruby vs. Java</title>
		<link>http://amazing-development.com/archives/2006/04/01/errorhandling-ruby-vs-java/</link>
		<comments>http://amazing-development.com/archives/2006/04/01/errorhandling-ruby-vs-java/#comments</comments>
		<pubDate>Sat, 01 Apr 2006 09:29:15 +0000</pubDate>
		<dc:creator>Frank Spychalski</dc:creator>
				<category><![CDATA[Computer]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Rants]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[articles]]></category>

		<guid isPermaLink="false">http://amazing-development.com/archives/2006/04/01/errorhandling-ruby-vs-java/</guid>
		<description><![CDATA[At my daytime job I had to rewrite a class which sends a Message to a Queue. Sounds simple? With EJB3 it is reasonably simple and can be done in around 10 lines of code involving lots of lookups. But if you are looking for a reliable solution which works even when the application server [...]]]></description>
			<content:encoded><![CDATA[<p><br />
At my daytime job I had to rewrite a class which sends a <a href="http://java.sun.com/javaee/5/docs/api/javax/jms/Message.html">Message</a> to a <a href="http://java.sun.com/javaee/5/docs/api/javax/jms/Queue.html">Queue</a>. Sounds simple? With EJB3 it is reasonably simple and can be done in around 10 lines of code involving lots of lookups. But if you are looking for a reliable solution which works even when the application server reboots every once in a while your code gets messy. My current solution has 120 lines of code and there are still some things to add like buffering of unsent messages.<span id="more-213"></span></p>
<h5>Bloated Exceptionhandling</h5>
<p>Why do I have to write so much more code to get a reliable solution? Part of the blame is on Java, because of its verbose exception handling &#8211; there is no elegant way of catching 2 or more exceptions<a href="#1">[1]</a> without catching Exception or Throwable, which I try to avoid where possible. Ruby has this simple solution compared to the bloated solution in java, especially with EJB where you have to catch half a dozend different exceptions.</p>
<pre><code class="ruby">begin
  eval string
rescue SyntaxError, NameError =&gt; boom
  print &quot;String doesn&apos;t compile&#58; &quot; + boom
rescue StandardError =&gt; bang
  print &quot;Error running script&#58; &quot; + bang
end</code></pre>
<h5>Retry</h5>
<p>Repeating whole blocks of code needs too much code, too. Ruby has the <a href="http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_expressions.html#UM"><tt>retry</tt></a> command, which restarts the current block:</p>
<pre><code class="ruby">c = 0
for i in 1..100
  tries = 0
  begin
    c = c + 1                 # dummy code
    if c % 4 != 0             # to create
      puts &quot;failed for #{i}&quot;  # a few
      raise &quot;uups&quot;            # exceptions
    end
    puts &quot;action #{i}&quot;
  rescue
    puts &quot;rescue&quot;
    tries = tries + 1
    retry if tries &lt; 3
  end
end</code></pre>
<p>This is just another name for goto, which might be harmful. Actually, I wouldn&#8217;t use this solution anyway because there is a better, more reusable way, to achieve the same.</p>
<h5>closures</h5>
<p>In ruby, it is possible (and very simple) to pass some code to a method. This allows me to create a method which excecutes my code multiple times, if an exceptions occurs:</p>
<pre><code class="ruby">def try(max_tries = 3)
  tries = 0
  begin
    yield
  rescue
    puts &quot;rescue&quot;
    tries = tries + 1
    retry if tries &lt; max_tries
  end
end

c = 0
for i in 1..100
  try do
    c = c + 1                 # dummy code
    if c % 4 != 0             # to create
      puts &quot;failed for #{i}&quot;  # a few
      raise &quot;uups&quot;            # exceptions
    end
    puts &quot;action #{i}&quot;
  end
end</code></pre>
<p />
<p>When I started this article, I just wanted to write a short rant about the missing features for errorhandling in java. While writing, I noticed that Ruby has them. Perhaps that&#8217;s the reason why I enjoy programming in ruby so much <img src='http://amazing-development.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p />
<p><a name="1">[1]</a>to clarify this point just for Jason: In general, there is no elegant way of catching two or more exceptions. If you look at the number of direct subclasses in <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Exception.html">java.lang.Exception</a>, it is nearly impossible to catch the exceptions you want using a superclass without catching some &#8216;innocent bystanders&#8217;.<br />
I would very much like to see a elegant solution which catches only java.sql.SQLException and java.util.concurrent.TimeoutException, you may use as much OOP and polymorphism as you like. This might not be the fault of the language but the plattform but as I cannot get one without the other, it doesn&#8217;t really matter to me. Don&#8217;t get me wrong, I think Java is pretty damn good, but there is still a lot of room to improve. And Ruby is showing some of the things which can be done better.</p>
]]></content:encoded>
			<wfw:commentRss>http://amazing-development.com/archives/2006/04/01/errorhandling-ruby-vs-java/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Rails, ActiveRecord and Distributed Ruby (DRb) in a nutshell</title>
		<link>http://amazing-development.com/archives/2006/03/16/rails-and-distributed-ruby-in-a-nutshell/</link>
		<comments>http://amazing-development.com/archives/2006/03/16/rails-and-distributed-ruby-in-a-nutshell/#comments</comments>
		<pubDate>Thu, 16 Mar 2006 09:52:09 +0000</pubDate>
		<dc:creator>Frank Spychalski</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[articles]]></category>

		<guid isPermaLink="false">http://amazing-development.com/archives/2006/03/16/rails-and-distributed-ruby-in-a-nutshell/</guid>
		<description><![CDATA[This tutorial shows how to use distributed ruby to connect a rails application with another ruby service not running inside Rails. Distributed Ruby (DRb) I won&#8217;t waste time here explaining how to use DRb. Just a short example from Rubycentral with a very simple server: require &apos;drb&apos; class TestServer def doit &#34;Hello, Distributed World&#34; end [...]]]></description>
			<content:encoded><![CDATA[<p></p>
<p>This tutorial shows how to use distributed ruby to connect a rails application with another ruby service not running inside Rails.<span id="more-208"></span></p>
<h3 class="article">Distributed Ruby (DRb)</h3>
<p>I won&#8217;t waste time here explaining how to use DRb. Just a short example from <a href="http://www.rubycentral.com/articles/drb.html">Rubycentral</a> with a very simple server:</p>
<pre><textarea wrap="off" class="code" rows="11" readonly>require &apos;drb&apos;

class TestServer
  def doit
    &quot;Hello, Distributed World&quot;
  end
end

aServerObject = TestServer.new
DRb.start_service(&apos;druby&#58;//localhost&#58;9000&apos;, aServerObject)
DRb.thread.join # Don&apos;t exit just yet!</textarea></pre>
<p>and an even simpler client:</p>
<pre><textarea wrap="off" class="code" rows="5" readonly>require &apos;drb&apos;
DRb.start_service
obj = DRbObject.new(nil, &apos;druby&#58;//localhost&#58;9000&apos;)
# Now use obj
puts obj.doit</textarea></pre>
<h3 class="article">Active Record</h3>
<p>As you want to connect the DRb Server to Rails, you probably want to use your model classes, too. Just include them (I&#8217;m still looking for a simple way to automagically include all models) and configure ActiveRecord:</p>
<pre><textarea wrap="off" class="code" rows="23" readonly>require &apos;drb&apos;
require &apos;rubygems&apos;
require_gem &apos;activerecord&apos;

require &apos;app/models/user.rb&apos;

class Server
  def dump
    puts User.find(&#58;first).inspect
  end
end

ActiveRecord&#58;&#58;Base.establish_connection(
    &#58;adapter  =&gt; &quot;mysql&quot;,
    &#58;username =&gt; &quot;xxxx&quot;,
    &#58;host     =&gt; &quot;localhost&quot;,
    &#58;password =&gt; &quot;xxxx&quot;,
    &#58;database =&gt; &quot;xxxx&quot;
)

DRb.start_service(&quot;druby&#58;//localhost&#58;9000&quot;, Server.new)
puts DRb.uri
DRb.thread.join</textarea></pre>
<h3 class="article">Don&#8217;t repeat yourself!</h3>
<p>Repeating the database configuration as I did in the above example is soooo against The Ruby Way. A better way is to parse <tt>config/database.yml</tt> and use the result to configure ActiveRecord. This has the added benefit of being able to use different database setups:</p>
<pre><textarea wrap="off" class="code" rows="22" readonly>require &apos;drb&apos;
require &apos;rubygems&apos;
require &apos;yaml&apos;
require_gem &apos;activerecord&apos;

require &apos;app/models/user.rb&apos;

class Server
  def dump
    puts User.find(&#58;first).inspect
  end
end

abort &quot;usage&#58; #{__FILE__} environment&quot; unless ARGV[0]
database_yaml = YAML.load_file(&quot;config/database.yml&quot;)
abort &quot;environment &apos;#{ARGV[0]}&apos; not found&quot; unless database_config = database_yaml[ARGV[0]]

ActiveRecord&#58;&#58;Base.establish_connection(database_config)

DRb.start_service(&quot;druby&#58;//localhost&#58;9000&quot;, Server.new)
puts DRb.uri
DRb.thread.join</textarea></pre>
<h3 class="article">From Rails?</h3>
<p>Just use the simple client from above inside your model or controller without special changes for Rails. Yes, it&#8217;s that simple. Enjoy!</p>
<pre><textarea wrap="off" class="code" rows="9" readonly>require &apos;drb&apos;
...
class DrbController &lt; ApplicationController

  def get_user_via_drb
    DRb.start_service
    obj = DRbObject.new(nil, &apos;druby&#58;//localhost&#58;9000&apos;)
    @user = obj.dump
  end </textarea></pre>
<p><a href="http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/ec565ebc86f25066/0b25eac91671699c">Here</a> is a short thread about problems with DRb.</p>
<h3 class="article">DRb over unix sockets</h3>
<p><a href="http://kasparov.skife.org/blog/">Brian</a> has a <a href="http://kasparov.skife.org/blog/2006/04/22/">nice writeup how to use DRb over unix sockets</a> &#8211; it&#8217;s extremly easy, just change the URI et voila&#8230;</p>
<p>Technorati Tags: <a href="http://technorati.com/tag/ruby" rel="tag">ruby</a>, <a href="http://technorati.com/tag/rails" rel="tag"> rails</a>, <a href="http://technorati.com/tag/drb" rel="tag"> drb</a></p>
]]></content:encoded>
			<wfw:commentRss>http://amazing-development.com/archives/2006/03/16/rails-and-distributed-ruby-in-a-nutshell/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>DVD burning without SCSI emulation</title>
		<link>http://amazing-development.com/archives/2006/03/12/dvd-burning-without-scsi-emulation/</link>
		<comments>http://amazing-development.com/archives/2006/03/12/dvd-burning-without-scsi-emulation/#comments</comments>
		<pubDate>Sun, 12 Mar 2006 21:34:36 +0000</pubDate>
		<dc:creator>schlumpf</dc:creator>
				<category><![CDATA[Computer]]></category>
		<category><![CDATA[articles]]></category>

		<guid isPermaLink="false">http://amazing-development.com/archives/2006/03/12/dvd-burning-without-scsi-emulation/</guid>
		<description><![CDATA[While I was trying to figure out how to make my computer burn a DVD, I found this quote in someone&#8217;s signature in a newsgroup post: UNIX is user-friendly, it&#8217;s just picky about who it&#8217;s friends are. This definitely is true for linux as well. And today I got one step closer to being Linux&#8217; [...]]]></description>
			<content:encoded><![CDATA[<p>While I was trying to figure out how to make my computer burn a DVD, I found this quote in someone&#8217;s signature in a newsgroup post:</p>
<blockquote><p>UNIX is user-friendly, it&#8217;s just picky about who it&#8217;s friends are.</p></blockquote>
<p>This definitely is true for linux as well. And today I got one step closer to being Linux&#8217; best friend. <span id="more-206"></span></p>
<p>When I googled for &#8220;dvd ide linux&#8221; I read in most articles that you can&#8217;t burn DVDs on an IDE drive if you don&#8217;t enable SCSI emulation in the kernel. So I tried to do that, everything went fine until I tried to make my boot loader (yes, I know <a href="http://lilo.go.dyndns.org/">Lilo</a> is deprecated in favour of <a href="http://www.gnu.org/software/grub/">grub</a>) decided to announce a floating point error rather than writing the new config to the boot sector. Meanwhile, I had found some hints that with 2.6 Kernels SCSI emulation was o longer required and that cdrecord would recognise IDE drives as well. And it did indeed:<br />
<code><br />
$ cdrecord --scanbus dev=ATAPI<br />
scsibus0:<br />
        0,0,0     0) 'TEAC    ' 'DV-W58G-A       ' 'U4S2' Removable CD-ROM<br />
</code><br />
That doesn&#8217;t mean <a href="http://www.xcdroast.org/">xcdroast</a> is willing to burn a DVD, though. It works fine for CD-ROM, but with DVDs it complains that it can&#8217;t find the SCSI driver for some strange device I didn&#8217;t even know my computer had.<br />
Then I read the name <code>growisofs</code> in some forum thread and I looked it up and landed on the <a href="http://fy.chalmers.se/~appro/linux/DVD+RW/">DVD+RW/+R/-R[W] for Linux</a> page. I had seen that before but was scared away by all that talk about kernel patches and stuff. Now I read on and it looked very promising and very simple. A quick<br />
<code><br />
emerge -va dvd+rw-tools<br />
</code><br />
installed the package and I was ready to go:<br />
<code><br />
growisofs -Z /dev/hdc -R -J /home/schlumpf<br />
</code><br />
writes the data from the directory <code>/home/schlumpf</code> to the dvd device <code>/dev/hdc</code>, writes a header (the -Z param; use it for DVD+R) and writes Rock Ridge protocol (-R) and Joliet (-J) extended information on the disk.<br />
By the way, <code>growisofs</code> is only a frontend for the <code>mkisofs</code> command which should be present in nearly all linux installations. </p>
<p>This is a prime example of the power and curse of Linux: some things are so simple you just don&#8217;t think of them!<br />
Here&#8217;s another: How to read a file backwards? Reverse <code>cat</code>: <a href="http://www.thunderstone.com/site/texisman/node331.html"><code>tac</code></a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://amazing-development.com/archives/2006/03/12/dvd-burning-without-scsi-emulation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Java Posse in a nutshell</title>
		<link>http://amazing-development.com/archives/2006/02/10/the-java-posse-in-a-nutshell/</link>
		<comments>http://amazing-development.com/archives/2006/02/10/the-java-posse-in-a-nutshell/#comments</comments>
		<pubDate>Fri, 10 Feb 2006 14:20:24 +0000</pubDate>
		<dc:creator>Frank Spychalski</dc:creator>
				<category><![CDATA[Computer]]></category>
		<category><![CDATA[articles]]></category>

		<guid isPermaLink="false">http://amazing-development.com/?p=184</guid>
		<description><![CDATA[I read about &#8216;The Java Posse&#8217; in Bruce Eckel&#8217;s blog. I really like the short transcript containing a collection of related links with each cast. Here&#8217;s my very short review of the interviews I heard so far. 001.mp3 Interview with Rob Harwood of Jetbrains about IntelliJ IDEA 64:23 How much did IntelliJ pay for this [...]]]></description>
			<content:encoded><![CDATA[<p></p>
<p>I read about <a href="http://javaposse.com/">&#8216;The Java Posse&#8217;</a> in <a href="http://www.artima.com/weblogs/viewpost.jsp?thread=147347">Bruce Eckel&#8217;s blog</a>. I really like the short transcript containing a collection of related links with each cast. Here&#8217;s my very short review of the interviews I heard so far.<span id="more-184"></span><br />
<br clear="all"/></p>
<table>
<tr valign="top">
<td><a href="http://javaposse.com/media/dickwall/JavaPosse001.mp3">001.mp3</a></td>
<td>
<a href="http://javaposse.com/index.php?post_id=22795">Interview with Rob Harwood of Jetbrains about IntelliJ IDEA</a></td>
<td>64:23</td>
<td><img src="http://static.amazing-development.com/stars-0-0.gif" alt="0.0"/></td>
</tr>
<tr valign="top">
<td></td>
<td colspan="3">How much did IntelliJ pay for this advertisement? Boring marketing speech. Skipped to the next episode after 40 minutes.</td>
</tr>
<tr valign="top">
<td><a href="http://javaposse.com/media/dickwall/JavaPosse002.mp3">002.mp3</a></td>
<td>
<a href="http://javaposse.com/index.php?post_id=24145">NewsCast for Sept 29 2005</a></td>
<td>31:02</td>
<td><img src="http://static.amazing-development.com/stars-1-5.gif" alt="1.5"/></td>
</tr>
<tr valign="top">
<td></td>
<td colspan="3">Old news, but there was still some stuff I didn&#8217;t know. The voice of the second guy (Carl?) sounded like he was talking into a bucket. I will skip the other old NewsCast and stick to interviews.</td>
</tr>
<tr valign="top">
<td></td>
<td colspan="3"><b>pointer:</b> <a href="http://www.softwarereality.com/programming/annotations.jsp">Annotations: Don&#8217;t Mess with Java</a></td>
</tr>
<tr valign="top">
<td><a href="http://javaposse.com/media/dickwall/JavaPosse003.mp3">003.mp3</a></td>
<td>
<a href="http://javaposse.com/index.php?post_id=24841">Interview with David Barnes about BlueJ</a></td>
<td>36:06</td>
<td><img src="http://static.amazing-development.com/stars-2-5.gif" alt="2.5"/></td>
</tr>
<tr valign="top">
<td></td>
<td colspan="3">How well is Java suited to teaching programming? Introducing BlueJ an Java IDE for beginners. Terrible music at the end.</td>
</tr>
<tr valign="top">
<td></td>
<td colspan="3"><b>pointer:</b> <a href="http://www.bluej.org/">bluej.org</a></td>
</tr>
<tr valign="top">
<td><a href="http://javaposse.com/media/dickwall/JavaPosse005.mp3">005.mp3</a></td>
<td>
<a href="http://javaposse.com/index.php?post_id=26274">Interview with Chuck Hill about WebObjects</a></td>
<td>28:54</td>
<td><img src="http://static.amazing-development.com/stars-1-5.gif" alt="1.5"/></td>
</tr>
<tr valign="top">
<td></td>
<td colspan="3">A short intro into WebObjects.</td>
</tr>
<tr valign="top">
<td><a href="http://javaposse.com/media/dickwall/JavaPosse007.mp3">007.mp3</a></td>
<td>
<a href="http://javaposse.com/index.php?post_id=27725">Interview with Cameron Purdy of Tangosol</a></td>
<td>43:33</td>
<td><img src="http://static.amazing-development.com/stars-1-5.gif" alt="1.5"/></td>
</tr>
<tr valign="top">
<td></td>
<td colspan="3">Grid Computing, a lot of buzzwords, java.nio</td>
</tr>
<tr valign="top">
<td><a href="http://javaposse.com/media/dickwall/JavaPosse009.mp3">009.mp3</a></td>
<td>
<a href="http://javaposse.com/index.php?post_id=29225">Interview with Josh Bloch of Google</a></td>
<td>41:20</td>
<td><img src="http://static.amazing-development.com/stars-1-0.gif" alt="1.0"/></td>
</tr>
<tr valign="top">
<td></td>
<td colspan="3">nice chit chat about java</td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://amazing-development.com/archives/2006/02/10/the-java-posse-in-a-nutshell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Google Talk with kopete</title>
		<link>http://amazing-development.com/archives/2006/01/20/using-google-talk-with-kopete/</link>
		<comments>http://amazing-development.com/archives/2006/01/20/using-google-talk-with-kopete/#comments</comments>
		<pubDate>Fri, 20 Jan 2006 12:49:09 +0000</pubDate>
		<dc:creator>Frank Spychalski</dc:creator>
				<category><![CDATA[Computer]]></category>
		<category><![CDATA[articles]]></category>

		<guid isPermaLink="false">http://amazing-development.com/?p=176</guid>
		<description><![CDATA[Descripton how to use google talk with kopete.]]></description>
			<content:encoded><![CDATA[<p><br />
</p>
<p>Google has <a href="http://www.google.com/talk/otherclients.html">extensive information how to use Google Talk</a> but no info for <a href="http://kopete.kde.org/">kopete</a> users like me. This is a step by step description, how to configure kopete.<span id="more-176"></span></p>
<p>First, you might need to install an additional package called tca-tls or similar, if it&#8217;s not already present. It seems every distribution has a slightly different name for the same thingy:</p>
<table>
<tr>
<td></td>
<td>package name</td>
</tr>
<tr>
<td>Debian</td>
<td>qca-tls</td>
</tr>
<tr>
<td>Fedora Core 4</td>
<td>qca-tls</td>
</tr>
<tr>
<td>Gentoo</td>
<td>app-crypt/qca-tls</td>
</tr>
<tr>
<td>Mandriva</td>
<td>libqca1-tls</td>
</tr>
<tr>
<td>SUSE</td>
<td>qca</td>
</tr>
<tr>
<td>Ubuntu</td>
<td>qca-tls</td>
</tr>
</table>
<p>When you have installed this package, the most difficult part is probably over, the actual setup is pretty simple:</p>
<ol>
<li><b>Settings-&gt;Configure</b></li>
<li><b>New</b></li>
<li><b>Next</b></li>
<li>Select <b>Jabber</b></li>
<li>On the first tab enter your account information
<pre>
<b>Basic Setup</b>
     Jabber Id: [<b>xxxx@gmail.com</b>]
 [ ] Remeber Password <i>whatever you prefer</i>
     Password: [xxxx]
</pre>
</li>
<li>On the second tab enter
<pre>
<b>Connection</b>
 [<b>x</b>] Use protocol encryption (SSL)
 [<b>x</b>] Allow plain-text password authentication
 [<b>x</b>] Override default server information
     Server: [<b>talk.google.com</b>]         Port: [5223]
</pre>
</li>
</ol>
<p>enjoy &#8230;</p>
<p>Related Posts:</p>
<ul>
<li><a href="http://amazing-development.com/archives/2006/10/23/how-to-remove-old-kopete-status-messages/"> How to remove old kopete status messages</a></li>
<li><a href="http://amazing-development.com/archives/2007/07/20/install-new-themes-for-kopete/">Install new themes for kopete</a></li>
</ul>
<p>Technorati Tags: <a href="http://technorati.com/tag/GoogleTalk" rel="tag">GoogleTalk</a>, <a href="http://technorati.com/tag/gtalk" rel="tag"> gtalk</a>, <a href="http://technorati.com/tag/kopete" rel="tag"> kopete</a></p>
]]></content:encoded>
			<wfw:commentRss>http://amazing-development.com/archives/2006/01/20/using-google-talk-with-kopete/feed/</wfw:commentRss>
		<slash:comments>65</slash:comments>
		</item>
		<item>
		<title>Ruby on Rails cheatsheet</title>
		<link>http://amazing-development.com/archives/2006/01/04/ruby-on-rails-cheatsheet/</link>
		<comments>http://amazing-development.com/archives/2006/01/04/ruby-on-rails-cheatsheet/#comments</comments>
		<pubDate>Wed, 04 Jan 2006 12:05:45 +0000</pubDate>
		<dc:creator>Frank Spychalski</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[articles]]></category>

		<guid isPermaLink="false">http://amazing-development.com/?p=170</guid>
		<description><![CDATA[A growing list of things I don&#8217;t want to forget&#8230; Disclaimer: This is still very beta! AFAIK there are no errors on this page, but a lot of stuff is still incomplete. Sections General Ruby Rails Model View Features Books General Setup for debian Install the following packages: ruby &#8211; An interpreter of object-oriented scripting [...]]]></description>
			<content:encoded><![CDATA[<p></p>
<p>A growing list of things I don&#8217;t want to forget&#8230;<span id="more-170"></span></p>
<p><img style="float:left;" src="http://amazing-development.com/blog_images/beta-small.gif"/><br />
<h5>Disclaimer:</h5>
<p>This is still very beta! AFAIK there are no errors on this page, but a lot of stuff is still incomplete.</p>
<p><br clear="all"/></p>
<h5>Sections</h5>
<ul class="compact inline">
<li><a href="#general">General</a></li>
<li><a href="#ruby">Ruby</a></li>
<li><a href="#rails">Rails</a></li>
<li><a href="#model">Model</a></li>
<li><a href="#view">View</a></li>
<li><a href="#features">Features</a></li>
<li><a href="#books">Books</a></li>
</ul>
<p><a name="general"><br />
<h3 class="article">General</h3>
<p></a></p>
<h5>Setup for debian</h5>
<p>Install the following packages:</p>
<div class="alignright"></div>
<ul class="compact">
<li>ruby &#8211; An interpreter of object-oriented scripting language Ruby</li>
<li>irb &#8211; Interactive Ruby</li>
<li>ri &#8211; Ruby Interactive reference</li>
<li>rdoc &#8211; Generate documentation from ruby source files</li>
<li>libmysql-ruby &#8211; MySQL module for Ruby</li>
</ul>
<p>For the first few steps I highly recommend toying around with <tt>irb</tt>, an interactive ruby shell.</p>
<pre><textarea wrap="off" class="code" rows="1" readonly>apt-get install ruby irb ri rdoc libmysql-ruby</textarea></pre>
<h5>Useful gems</h5>
<ul class="compact">
<li>actionmailer &#8211;  Service layer for easy email delivery and testing.</li>
<li>actionpack &#8211; Web-flow and rendering framework putting the VC in MVC.</li>
<li>actionwebservice &#8211; Web service support for Action Pack.</li>
<li>activerecord &#8211; Implements the ActiveRecord pattern for ORM.</li>
<li>activesupport &#8211;  Support and utility classes used by the Rails framework.</li>
<li>db_structure &#8211; [Rails] Database utilities.</li>
<li>localization_generator &#8211; [Rails] Localization generator.</li>
<li>rails &#8211; Web-application framework with template engine, control-flow layer, and ORM.</li>
<li>rake &#8211; Ruby based make-like utility.</li>
<li>salted_login_generator &#8211; [Rails] Login generator with salted passwords.</li>
</ul>
<pre><textarea wrap="off" class="code" rows="1" readonly>gem install actionmailer actionpack actionwebservice activerecord activesupport db_structure localization_generator rails rake salted_login_generator</textarea></pre>
<h5>Ruby Developer Tools for Eclipse</h5>
<ul class="compact">
<li>Help->Software Updates->Find and Install</li>
<li>&#8220;Search for new features to install&#8221;, click Next</li>
<li>&#8220;New Remote Site&#8221;</li>
<li>name: whatever you like, “Ruby Developer Tools” would be sensible, URL: <tt>http://rubyeclipse.sf.net/updatesite</tt>, click OK</li>
<li>select RDT, click Next</li>
<li>select RDT again, click Next</li>
</ul>
<h5>Online documentation</h5>
<ul class="compact">
<li><a href="http://api.rubyonrails.org/">api.rubyonrails.org/</a><br />
read these:</p>
<ul>
<li><a href="http://api.rubyonrails.org/classes/ActionController/Base.html">ActionController:Base API Doc</a></li>
<li><a href="http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html">FormHelper API Doc</a></li>
<li><a href="http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html">UrlHelper API Doc</a></li>
</ul>
</li>
</ul>
<h5>Support</h5>
<ul class="compact">
<li><a href="http://lists.rubyonrails.org/mailman/listinfo/rails">Rails Mailinglist</a></li>
<li><a href="irc://irc.freenode.org/#ruby-talk">#ruby-talk</a></li>
<li><a href="irc://irc.freenode.org/#rubyonrails">#rubyonrails</a></li>
</ul>
<p><a name="ruby"><br />
<h3 class="article">Ruby</h3>
<p></a></p>
<pre>
attr_accessor :name
attr_reader   :name
attr_writer   :name
</pre>
<p><a name="rails"><br />
<h3 class="article">Rails</h3>
<p></a></p>
<h5>Rails configfiles</h5>
<ul class="compact">
<li>config/boot.rb: don&#8217;t touch</li>
<li>config/database.yml: database config for all environment</li>
<li>config/environments/(development|production|test).rb: config which differs between environments</li>
<li>config/environment.rb: global config</li>
<li>config/routes.rb: configure mapping of urls to controllers and actions</li>
</ul>
<h5>Environments</h5>
<p>Start server for the different environments:</p>
<pre>ruby script/server -e <i>development|test|production</i></pre>
<h5>script/generate</h5>
<pre><textarea wrap="off" class="code" rows="4" readonly>ruby script/generate controller $controller
ruby script/generate controller $controller $action1 $action2 $action3
ruby script/generate scaffold $model $controller
ruby script/generate model $modelname</textarea></pre>
<p><a name="model"><br />
<h3 class="article">Model</h3>
<p></a></p>
<ul>
<li><a href="http://api.rubyonrails.com/classes/ActiveRecord/Associations/ClassMethods.html">Module ActiveRecord::Associations</a></li>
</ul>
<h5>Naming conventions</h5>
<ul class="compact">
<li>Class names: <tt>CamelCase</tt>, <tt>MyEntry</tt></li>
<li>Table names: <tt>lowercase_underscores_plural</tt>, <tt>my_entries</tt></li>
</ul>
<h5>finder</h5>
<pre>
User.find(&#58;all, &#58;conditions =&gt; [&quot;login != ?&quot;, user.login])
</pre>
<h5>table joins</h5>
<p>user table with user table in friends table (columns <tt>user_id</tt> and <tt>friend_id</tt>)</p>
<pre>
<textarea wrap="off" class="code" rows="3" readonly>has_and_belongs_to_many &#58;friends, &#58;join_table =&gt; &apos;friends&apos;, &#58;class_name =&gt; &apos;User&apos;, &#58;foreign_key =&gt; &apos;friend_id&apos;

has_and_belongs_to_many &#58;friends_of, &#58;join_table =&gt; &apos;friends&apos;, &#58;class_name =&gt; &apos;User&apos;, &#58;foreign_key =&gt; &apos;user_id&apos;, &#58;association_foreign_key =&gt; &apos;friend_id&apos;</textarea>
</pre>
<p>creates for example for <tt>friends</tt> the following methods:</p>
<ul class="compact">
<li>add_friends</li>
<li>friends</li>
<li>friends=</li>
<li>friends_count</li>
<li>has_friends?</li>
<li>remove_friends</li>
<li>validate_associated_records_for_friends</li>
</ul>
<p><a name="view"><br />
<h3 class="article">View</h3>
<p></a></p>
<h5>ERb</h5>
<ul class="compact">
<li>&lt;%= returns value %&gt;</li>
<li>&lt;% just execute this %&gt;</li>
<li>no newline afterwards if closed with &#45;%&gt;</li>
</ul>
<h5>render</h5>
<pre><textarea wrap="off" class="code" rows="12" readonly>render &#58;action =&gt; &quot;goal&quot;
render &#58;action =&gt; &quot;short_goal&quot;, &#58;layout =&gt; false
render &#58;action =&gt; &quot;long_goal&quot;, &#58;layout =&gt; &quot;spectacular&quot;

# partials always start with a '_' e.g.  _win.r(html|xml)
render &#58;partial =&gt; &quot;win&quot;
render &#58;partial =&gt; &quot;broken&quot;, &#58;status =&gt; 500
render &#58;partial =&gt; &quot;win&quot;, &#58;locals =&gt; { &#58;name =&gt; &quot;david&quot; }

# render partial for every item in collection
render &#58;partial =&gt; &quot;win&quot;, &#58;collection =&gt; @wins
render &#58;partial =&gt; &quot;win&quot;, &#58;collection =&gt; @wins, &#58;spacer_template =&gt; &quot;win_divider&quot;</textarea></pre>
<h5>form helpers</h5>
<pre><textarea wrap="off" class="code" rows="5" readonly>form_tag &#58;controller=&gt;&quot;user&quot;, &#58;action=&gt;&#58;login

text_field(&#58;variable, &#58;attribute, &#58;size =&gt; 16)
hidden_field(&#58;variable, &#58;attribute, &#58;maxsize =&gt; 16)
password_field(&#58;variable, &#58;attribute)</textarea></pre>
<p><tt>size</tt> and <tt>maxsize</tt> are optional parametes for *_field</p>
<h5>other helpers</h5>
<pre><textarea wrap="off" class="code" rows="2" readonly>stylesheet_link_tag &quot;main&quot;, &#58;media =&gt; &apos;all&apos;
stylesheet_link_tag &quot;main&quot;,&quot;second&quot;, &#58;media =&gt; &apos;all&apos;</textarea></pre>
<p>create one / two stylesheet <tt>&lt;link&gt;</tt>s.</p>
<p><a name="features"><br />
<h3 class="article">Features</h3>
<p></a></p>
<h5>Login</h5>
<ul class="compact">
<li>the original <a href="http://wiki.rubyonrails.com/rails/pages/LoginGenerator">LoginGenerator</a></li>
<li>newer, better: <a href="http://wiki.rubyonrails.org/rails/pages/SaltedHashLoginGenerator">SaltedHashLoginGenerator</a></li>
<li>even newer and even better <a href="http://www.rails-engines.org/login_engine">LoginEngine</a></li>
</ul>
<p><a name="books"><br />
<h3 class="article">Books</h3>
<p></a></p>
<p><a title="David Thomas, David Heinemeier Hansson - Agile Web Development with Rails" href="http://www.amazon.de/exec/obidos/ASIN/097669400X/frankspycha0b-21/"><img src="http://images-eu.amazon.com/images/P/097669400X.01.MZZZZZZZ.jpg"/></a>&nbsp;<a title="Dave Thomas - Programming Ruby" href="http://www.amazon.de/exec/obidos/ASIN/0974514055/frankspycha0b-21/"><img src="http://images-eu.amazon.com/images/P/0974514055.03.MZZZZZZZ.jpg"/><br />
</a></p>
]]></content:encoded>
			<wfw:commentRss>http://amazing-development.com/archives/2006/01/04/ruby-on-rails-cheatsheet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to customize your wordpress blog: Add information from a file</title>
		<link>http://amazing-development.com/archives/2005/12/18/how-to-customize-your-wordpress-blog/</link>
		<comments>http://amazing-development.com/archives/2005/12/18/how-to-customize-your-wordpress-blog/#comments</comments>
		<pubDate>Sun, 18 Dec 2005 15:55:10 +0000</pubDate>
		<dc:creator>Frank Spychalski</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[articles]]></category>

		<guid isPermaLink="false">http://amazing-development.com/?p=166</guid>
		<description><![CDATA[There are a lot of good articles available about how to customize the layout of you blog but sometimes want to add some kind of outside information to your blog. For complex or large amounts of information, you should consider a database solution but in a lot of cases a simple file based solution works, [...]]]></description>
			<content:encoded><![CDATA[<p></p>
<p>There are a lot of <a href="http://performancing.com/node/429">good articles</a> available about how to customize the layout of you blog but sometimes want to add some kind of outside information to your blog. For complex or large amounts of information, you should consider a database solution but in a lot of cases a simple file based solution works, too. This tutorial shows you how to add information from a file to your blog.<span id="more-166"></span></p>
<p>Recently I added a &#8220;Just read&#8221; block to my sidebar containing links and images to the books I have read and a rating. At first this was a static html block, just to see how it will look. Lazy as I am, I didn&#8217;t want to write html every time I finish a book. This is why I moved the information from the <tt>sidebar.php</tt> into a seperate file called <tt>books.txt</tt> in the main directory of my blog.</p>
<h5>The file</h5>
<p>The file contains 5 tab seperated columns for author, title, amazon url, amazon image url and url for the rating image. A sample line looks like this:</p>
<pre>
<textarea wrap="off" class="code" rows="1" readonly>Dave Thomas&lt;tab&gt;Programming Ruby&lt;tab&gt;http://www.amazon.de/exec/obidos/ASIN/0974514055/&lt;tab&gt;http://images-eu.amazon.com/images/P/0974514055.03.MZZZZZZZ.jpg&lt;tab&gt;/pics/stars-2-5.gif</textarea>
</pre>
<p>Reading and parsing the file is pretty easy in php (this is taken directly from the php manual):</p>
<pre>
$lines = file(&apos;books.txt&apos;);
foreach ($lines as $line_num =&gt; $line) {
  $parsed = explode(&quot;&#92;t&quot;, rtrim($line));
  ...
}
</pre>
<p>As I wanted only the first 4 books to show, I added a check to echo only the lines with a line number less than 4. <tt>rtrim</tt> removes the whitespaces/newlines from the end of the line and <tt>explode</tt> splits the line at every tab. This leaves me with an array of 5 strings. The final step of assembling an entry for a book within a <tt>&lt;td&gt;</tt> is straightforward. After every 2 books a <tt>&lt;/tr&gt;&lt;tr&gt;</tt> is added to create a 2&#215;2 block of books.</p>
<p>Here&#8217;s the whole block, as it is used in my sidebar, if you have any questions feel free to ask&#8230;</p>
<pre>
<textarea wrap="off" class="code" rows="20" readonly>
&lt;li&gt;&lt;h4&gt;Just read&lt;/h4&gt;
  &lt;table&gt;
    &lt;tr&gt;

&lt;?php
$lines = file(&apos;books.txt&apos;);
foreach ($lines as $line_num =&gt; $line) {
  if ($line_num &lt; 4) {
    $parsed = explode(&quot;&#92;t&quot;, rtrim($line));

    $book_author = $parsed[0];
    $book_title = $parsed[1];
    $book_url = $parsed[2];
    $book_img = $parsed[3];
    $book_rate = $parsed[4];
    echo &quot;&lt;td&gt;&lt;a title=&#92;&quot;$book_author &#45; $book_title&#92;&quot; href=&#92;&quot;$book_url/frankspycha0b&#45;21/&#92;&quot;&gt;&lt;img src=&#92;&quot;$book_img&#92;&quot;/&gt;&lt;br/&gt;&lt;img src=&#92;&quot;$book_rate&#92;&quot;/&gt;&lt;/a&gt;&lt;/td&gt;&#92;n&quot;;
    if ($line_num % 2 == 1) {
      echo &quot;&lt;/tr&gt;&lt;tr&gt;&#92;n&quot;;
    }
  } else {
    break;
  }
}?&gt;

    &lt;/tr&gt;
  &lt;/table&gt;
&lt;/li&gt;
</textarea>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://amazing-development.com/archives/2005/12/18/how-to-customize-your-wordpress-blog/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Usefull Errormessages With Schema and XInclude</title>
		<link>http://amazing-development.com/archives/2005/12/09/usefull-errormessages-with-schema-and-xinclude/</link>
		<comments>http://amazing-development.com/archives/2005/12/09/usefull-errormessages-with-schema-and-xinclude/#comments</comments>
		<pubDate>Fri, 09 Dec 2005 12:39:56 +0000</pubDate>
		<dc:creator>Frank Spychalski</dc:creator>
				<category><![CDATA[Work]]></category>
		<category><![CDATA[articles]]></category>

		<guid isPermaLink="false">http://amazing-development.com/?p=161</guid>
		<description><![CDATA[As I promised yesterday, here&#8217;s the workaround for the problem that Xerces only provides a not very errormessages in case of an error in an included document when using Schema and Xinclude. If there is a error in the main document you get the normal error messages, explaining why your document is not valid (e.g. [...]]]></description>
			<content:encoded><![CDATA[<p><br />
As I promised <a href="http://amazing-development.com/archives/2005/12/08/xml-with-schema-and-xinclude-in-java/">yesterday</a>, here&#8217;s the workaround for the problem that Xerces only provides a not very errormessages in case of an error in an included document when using Schema and Xinclude. If there is a error in the main document you get the normal error messages, explaining why your document is not valid (e.g. if we change an id attribute to ID we get &#8220;<tt>Attribute 'ID' is not allowed to appear in element 'e'</tt>&#8220;) but if the same error is made in the included element, the errormessage says: &#8220;<tt>Error on line 12 of document file:///home/psycho/workspace/Tests/xinclude/test.xml: Error attempting to parse XML file (href='include.xml').</tt>&#8220;.<span id="more-161"></span></p>
<p>There is a simple workaround, which sadly wastes a lot of cpu cycles, but I can&#8217;t think of another simple solution with less overhead.</p>
<ol>
<li>parse document with schema validation and XInclude, if there is no exception (which should be the default case) return result</li>
<li>if there is an exception parse document again with XInclude but without schema validation</li>
<li>if there is another exception, throw this exception (something is wrong with XInclude)</li>
<li>write the result to String and parse the String yet again, this time with schema validation but without XInclude (we included everything in the second step)</li>
<li>this will fail again, but the exception will include a useful errormessage</li>
</ol>
<pre>
<textarea wrap="off" class="code" rows="20" readonly>public class XInclude {
  private static final XMLOutputter XMLO = new XMLOutputter();

  private static Document doParse(String file, boolean val, boolean xinlcude, boolean fixbase, boolean fixlang) throws JDOMException {
    final SAXBuilder saxB = new SAXBuilder(val);
    saxB.setFeature(&quot;http://apache.org/xml/features/validation/schema&quot;, val);
    saxB.setFeature(&quot;http://apache.org/xml/features/xinclude&quot;, xinlcude);
    saxB.setFeature(&quot;http://apache.org/xml/features/xinclude/fixup&#45;base&#45;uris&quot;, fixbase);
    saxB.setFeature(&quot;http://apache.org/xml/features/xinclude/fixup&#45;language&quot;, fixlang);
    return saxB.build(file);
  }

  private static Document parse2(String file) throws JDOMException {
    try {
      return doParse(file, true, true, false, false);
    } catch (JDOMException jde) {
      final Document doc = doParse(file, false, true, false, false);
      final String included = XMLO.outputString(doc);
      final SAXBuilder saxB = new SAXBuilder(true);
      saxB.setFeature(&quot;http://apache.org/xml/features/validation/schema&quot;, true);
      saxB.setFeature(&quot;http://apache.org/xml/features/xinclude/fixup&#45;base&#45;uris&quot;, false);
      saxB.setFeature(&quot;http://apache.org/xml/features/xinclude/fixup&#45;language&quot;, false);
      return saxB.build(new StringReader(included));
  }
}

  public static void main(String[] strings) throws JDOMException {
    try {
      doParse(&quot;xinclude/test.xml&quot;, true, true, false, false);
    } catch (JDOMException jde) {
      System.out.println(jde.getMessage());
    }
    parse2(&quot;xinclude/test.xml&quot;);
  }
}
</textarea></pre>
<div class="related">
Related articles:</p>
<ul>
<li><a href="http://amazing-development.com/archives/2005/12/08/xml-with-schema-and-xinclude-in-java/">XML with Schema and XInclude in Java</a>
</li>
<li><a href="http://amazing-development.com/archives/2005/02/14/xml-design-patterns/">XML Design Patterns &#8211; element vs. attribute</a></li>
<li><a href="http://amazing-development.com/archives/2005/02/03/creating-an-extensible-schema/">creating an extensible schema</a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://amazing-development.com/archives/2005/12/09/usefull-errormessages-with-schema-and-xinclude/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XML with Schema and XInclude in Java</title>
		<link>http://amazing-development.com/archives/2005/12/08/xml-with-schema-and-xinclude-in-java/</link>
		<comments>http://amazing-development.com/archives/2005/12/08/xml-with-schema-and-xinclude-in-java/#comments</comments>
		<pubDate>Thu, 08 Dec 2005 15:47:55 +0000</pubDate>
		<dc:creator>Frank Spychalski</dc:creator>
				<category><![CDATA[articles]]></category>

		<guid isPermaLink="false">http://amazing-development.com/?p=159</guid>
		<description><![CDATA[This post explains how to use XML Schema to validate your document and XInclude to partition it in manageable chunks in Java using Xerces. For this example I use the following documents: main.xml the main document, imports include.xml include.xml the included document, contains just a single element main.xsd a simple schema for the main document [...]]]></description>
			<content:encoded><![CDATA[<p><br />
This post explains how to use XML Schema to validate your document and XInclude to partition it in manageable chunks in Java using Xerces.<span id="more-159"></span></p>
<p>For this example I use the following documents:</p>
<ul>
<li><tt>main.xml</tt> the main document, imports <tt>include.xml</tt></li>
<li><tt>include.xml</tt> the included document, contains just a single element</li>
<li><tt>main.xsd</tt> a simple schema for the main document</li>
</ul>
<pre><textarea wrap="off" class="code" rows="16" readonly>main.xml
&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;root xmlns=&quot;http://main.xml&quot;
      xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema&#45;instance&quot;
      xmlns:xi=&quot;http://www.w3.org/2001/XInclude&quot;
      xsi:schemaLocation=&quot;http://main.xml
      file:///<i>path to schema</i>/main.xsd&quot;&gt;

  &lt;e id=&quot;1&quot;/&gt;
  &lt;e id=&quot;2&quot;/&gt;
  &lt;e id=&quot;3&quot;/&gt;
  <b>&lt;xi:include href=&quot;include.xml&quot;/&gt;</b>
  &lt;e id=&quot;4&quot;/&gt;
  &lt;e id=&quot;5&quot;/&gt;
  &lt;e id=&quot;6&quot;/&gt;
&lt;/root&gt;</textarea></pre>
<p>And this is the included file:</p>
<pre><textarea wrap="off" class="code" rows="3" readonly>include.xml
&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;e xmlns=&quot;http://main.xml&quot; id=&quot;23&quot;/&gt;</textarea></pre>
<p>and a very simple Schema to validate the file:</p>
<pre><textarea wrap="off" class="code" rows="21" readonly>main.xsd
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF&#45;8&quot;?&gt;
&lt;xsd:schema targetNamespace=&quot;http://main.xml&quot;
  xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot;
  xmlns:sn=&quot;http://main.xml&quot;
  elementFormDefault=&quot;qualified&quot;&gt;

  &lt;xsd:element name=&quot;root&quot;&gt;
    &lt;xsd:complexType&gt;
      &lt;xsd:sequence&gt;
        &lt;xsd:element name=&quot;e&quot; type=&quot;sn:elementType&quot; maxOccurs=&quot;unbounded&quot;/&gt;
      &lt;/xsd:sequence&gt;
    &lt;/xsd:complexType&gt;
  &lt;/xsd:element&gt;

  &lt;xsd:complexType name=&quot;elementType&quot;&gt;
    &lt;xsd:attribute name=&quot;id&quot; type=&quot;xsd:string&quot; use=&quot;required&quot;/&gt;
  &lt;/xsd:complexType&gt;
&lt;/xsd:schema&gt;</textarea></pre>
<p>The solution seems obvious, use a SAXParser and set the features for Schema Validation and XInclude to true.</p>
<pre><textarea wrap="off" class="code" rows="4" readonly>final SAXBuilder saxB = new SAXBuilder(&quot;org.apache.xerces.parsers.SAXParser&quot;, true);
saxB.setFeature(&quot;http://apache.org/xml/features/validation/schema&quot;, true);
saxB.setFeature(&quot;http://apache.org/xml/features/xinclude&quot;, true);
saxB.build(&quot;main.xml&quot;);</textarea></pre>
<p>Sadly, it fails with <tt>Exception in thread &quot;main&quot; org.jdom.JDOMException: Error on line 12 of document <i>a path</i>main.xml: Error attempting to parse XML file (href=&apos;include.xml&apos;).</tt> Line 12 is the line containing the XInclude statement which suggested an error in the syntax. But multiple rereads of the spec didn&#8217;t help so turned off Schema Validation for a change. Now everything worked fine and a look at the document shows what went wrong with the Schema Validation:</p>
<pre><textarea wrap="off" class="code" rows="16" readonly>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF&#45;8&quot;?&gt;
&lt;root xmlns=&quot;http://main.xml&quot;
      xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema&#45;instance&quot;
      xmlns:xi=&quot;http://www.w3.org/2001/XInclude&quot;
      xsi:schemaLocation=&quot;http://main.xml
      file:///<i>path to schema</i>/test.xsd&quot;&gt;

  &lt;e id=&quot;1&quot; /&gt;
  &lt;e id=&quot;2&quot; /&gt;
  &lt;e id=&quot;3&quot; /&gt;
  &lt;e id=&quot;23&quot; <b>xml:base=&quot;include.xml&quot; </b>/&gt;
  &lt;e id=&quot;4&quot; /&gt;
  &lt;e id=&quot;5&quot; /&gt;
  &lt;e id=&quot;6&quot; /&gt;
&lt;/root&gt;</textarea></pre>
<p>Xerces inserts a <tt>xml:base</tt> attribute when in insert an element and this attribute is not allowed in my Schema. But fortunately I don&#8217;t have to change my schema to suit this. There&#8217;s a feature called <tt>fixup-base-uris (http://apache.org/xml/features/xinclude/fixup-base-uris)</tt> which removes these additional attributes.</p>
<pre><textarea wrap="off" class="code" rows="4" readonly>final SAXBuilder saxB = new SAXBuilder(&quot;org.apache.xerces.parsers.SAXParser&quot;, true);
saxB.setFeature(&quot;http://apache.org/xml/features/validation/schema&quot;, true);
saxB.setFeature(&quot;http://apache.org/xml/features/xinclude&quot;, true);
saxB.setFeature(&quot;http://apache.org/xml/features/xinclude/fixup&#45;base&#45;uris&quot;, false);</textarea></pre>
<p>This works fine, with one minor problem left: if there is an error in the included XML document, it fails with <tt>Exception in thread &quot;main&quot; org.jdom.JDOMException: Error on line 12 of document file:<i>a path</i>/main.xml: Error attempting to parse XML file (href=&apos;include.xml&apos;).</tt> which is not very helpful. <a href="http://amazing-development.com/archives/2005/12/09/usefull-errormessages-with-schema-and-xinclude/">I&#8217;ll post a workaround for this problem tomorrow</a>.</p>
<div class="related">
Related articles:</p>
<ul>
<li><a href="http://amazing-development.com/archives/2005/12/09/usefull-errormessages-with-schema-and-xinclude/">Usefull Errormessages With Schema and XInclude</a>
</li>
<li><a href="http://amazing-development.com/archives/2005/02/14/xml-design-patterns/">XML Design Patterns &#8211; element vs. attribute</a></li>
<li><a href="http://amazing-development.com/archives/2005/02/03/creating-an-extensible-schema/">creating an extensible schema</a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://amazing-development.com/archives/2005/12/08/xml-with-schema-and-xinclude-in-java/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
