<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Bugs you can write in Groovy, but can&#8217;t in Java</title>
	<atom:link href="http://thediscoblog.com/2007/06/25/bugs-you-can-write-in-groovy-but-cant-in-java/feed/" rel="self" type="application/rss+xml" />
	<link>http://thediscoblog.com/2007/06/25/bugs-you-can-write-in-groovy-but-cant-in-java/</link>
	<description>Can you dig it man?</description>
	<pubDate>Sat, 22 Nov 2008 05:08:15 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
		<item>
		<title>By: Raoul Duke</title>
		<link>http://thediscoblog.com/2007/06/25/bugs-you-can-write-in-groovy-but-cant-in-java/#comment-79451</link>
		<dc:creator>Raoul Duke</dc:creator>
		<pubDate>Fri, 22 Aug 2008 19:40:24 +0000</pubDate>
		<guid isPermaLink="false">http://thediscoblog.com/2007/06/25/bugs-you-can-write-in-groovy-but-cant-in-java/#comment-79451</guid>
		<description>@Kevin
"For example, I frequently see variables defined to be integers, when the correct values range over a much smaller range than -MAXINT to +MAXINT."

thought: perhaps there is a way of instead of throwing the baby + bath water out, having better typing? some pascals let you restrict the range. perhaps dependent typing some day will let us do similar and more powerful things.</description>
		<content:encoded><![CDATA[<p>@Kevin<br />
&#8220;For example, I frequently see variables defined to be integers, when the correct values range over a much smaller range than -MAXINT to +MAXINT.&#8221;</p>
<p>thought: perhaps there is a way of instead of throwing the baby + bath water out, having better typing? some pascals let you restrict the range. perhaps dependent typing some day will let us do similar and more powerful things.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Type Of Cat Litter</title>
		<link>http://thediscoblog.com/2007/06/25/bugs-you-can-write-in-groovy-but-cant-in-java/#comment-44421</link>
		<dc:creator>Type Of Cat Litter</dc:creator>
		<pubDate>Sun, 17 Feb 2008 20:24:08 +0000</pubDate>
		<guid isPermaLink="false">http://thediscoblog.com/2007/06/25/bugs-you-can-write-in-groovy-but-cant-in-java/#comment-44421</guid>
		<description>&lt;strong&gt;Choosing The Right Cat Litter Box...&lt;/strong&gt;

Cats are primarily clean animals, but the cat litter box they use is usually a different story altogether. Pet owners have a wide variety of cat litter boxes to choose from. Scoop litters are a big help for those who want to keep a clean household. If ...</description>
		<content:encoded><![CDATA[<p><strong>Choosing The Right Cat Litter Box&#8230;</strong></p>
<p>Cats are primarily clean animals, but the cat litter box they use is usually a different story altogether. Pet owners have a wide variety of cat litter boxes to choose from. Scoop litters are a big help for those who want to keep a clean household. If &#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stephan Schmidt</title>
		<link>http://thediscoblog.com/2007/06/25/bugs-you-can-write-in-groovy-but-cant-in-java/#comment-17885</link>
		<dc:creator>Stephan Schmidt</dc:creator>
		<pubDate>Sat, 30 Jun 2007 21:22:39 +0000</pubDate>
		<guid isPermaLink="false">http://thediscoblog.com/2007/06/25/bugs-you-can-write-in-groovy-but-cant-in-java/#comment-17885</guid>
		<description>I love expliciet typing. For some time I thought I like type inference like in Haskell, but having expliciet types makes reading some code you are newly responsible for much easier.</description>
		<content:encoded><![CDATA[<p>I love expliciet typing. For some time I thought I like type inference like in Haskell, but having expliciet types makes reading some code you are newly responsible for much easier.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sidu</title>
		<link>http://thediscoblog.com/2007/06/25/bugs-you-can-write-in-groovy-but-cant-in-java/#comment-17505</link>
		<dc:creator>Sidu</dc:creator>
		<pubDate>Wed, 27 Jun 2007 07:04:00 +0000</pubDate>
		<guid isPermaLink="false">http://thediscoblog.com/2007/06/25/bugs-you-can-write-in-groovy-but-cant-in-java/#comment-17505</guid>
		<description>+1 to Ricky's comment. If you can't be sure everyone involved in a project is writing unit tests, then that is sufficient reason to not use Groovy/Ruby/Python/etc. and stick with ol' Java/C#/C++.</description>
		<content:encoded><![CDATA[<p>+1 to Ricky&#8217;s comment. If you can&#8217;t be sure everyone involved in a project is writing unit tests, then that is sufficient reason to not use Groovy/Ruby/Python/etc. and stick with ol&#8217; Java/C#/C++.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ricky Clarkson</title>
		<link>http://thediscoblog.com/2007/06/25/bugs-you-can-write-in-groovy-but-cant-in-java/#comment-17111</link>
		<dc:creator>Ricky Clarkson</dc:creator>
		<pubDate>Mon, 25 Jun 2007 23:43:12 +0000</pubDate>
		<guid isPermaLink="false">http://thediscoblog.com/2007/06/25/bugs-you-can-write-in-groovy-but-cant-in-java/#comment-17111</guid>
		<description>Andy, yes, of course there is a difference between the Groovy code and the Java code.  I assert that it won't matter though.  A good programmer will read that code closely enough (at least when it fails) that they will see that it is a partial function.  Further, there's nothing stopping you from interfacing with a Groovy parser to discover partial functions (as I demonstrated, but I used Lisp).

You can tool yourself to the hilt, qualify everything with static types and write more unit test than production code, but there's no getting away from the fact that when humans write code, they need to think about it.  That's a great reason to make machines write code. ;)

Testing or production will reveal the logic error, and if you are using a statically-typed language, then you'll see the logic error there too (you'd have to make the input parameter of type "a string of length 0 or &#62;3").

It's hard to say that the author forgot (unless you are the author, which, um, you are).  They might have known Groovy's rules, and been merely using them on purpose.

About mandatory static typing in general - any language where 1/2==0 is a bit dodgy.

Kevin appears to be looking for Haskell's QuickCheck (which has been ported to some other languages) but I'm unsure.

"given that not everyone actually takes the time to write tests, weâ€™ll have to settle for mandatory technologies like compilers for the time being!"

Perhaps it's worth not considering everyone.  Use what fits you the best.  You don't have to aim for the lowest common denominator.</description>
		<content:encoded><![CDATA[<p>Andy, yes, of course there is a difference between the Groovy code and the Java code.  I assert that it won&#8217;t matter though.  A good programmer will read that code closely enough (at least when it fails) that they will see that it is a partial function.  Further, there&#8217;s nothing stopping you from interfacing with a Groovy parser to discover partial functions (as I demonstrated, but I used Lisp).</p>
<p>You can tool yourself to the hilt, qualify everything with static types and write more unit test than production code, but there&#8217;s no getting away from the fact that when humans write code, they need to think about it.  That&#8217;s a great reason to make machines write code. <img src='http://thediscoblog.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Testing or production will reveal the logic error, and if you are using a statically-typed language, then you&#8217;ll see the logic error there too (you&#8217;d have to make the input parameter of type &#8220;a string of length 0 or &gt;3&#8243;).</p>
<p>It&#8217;s hard to say that the author forgot (unless you are the author, which, um, you are).  They might have known Groovy&#8217;s rules, and been merely using them on purpose.</p>
<p>About mandatory static typing in general - any language where 1/2==0 is a bit dodgy.</p>
<p>Kevin appears to be looking for Haskell&#8217;s QuickCheck (which has been ported to some other languages) but I&#8217;m unsure.</p>
<p>&#8220;given that not everyone actually takes the time to write tests, weâ€™ll have to settle for mandatory technologies like compilers for the time being!&#8221;</p>
<p>Perhaps it&#8217;s worth not considering everyone.  Use what fits you the best.  You don&#8217;t have to aim for the lowest common denominator.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andy</title>
		<link>http://thediscoblog.com/2007/06/25/bugs-you-can-write-in-groovy-but-cant-in-java/#comment-17045</link>
		<dc:creator>Andy</dc:creator>
		<pubDate>Mon, 25 Jun 2007 19:01:24 +0000</pubDate>
		<guid isPermaLink="false">http://thediscoblog.com/2007/06/25/bugs-you-can-write-in-groovy-but-cant-in-java/#comment-17045</guid>
		<description>Kevin- great point!! I agree with the unit test - compilation notion; however, given that not everyone actually takes the time to write tests, we'll have to settle for mandatory technologies like compilers for the time being!</description>
		<content:encoded><![CDATA[<p>Kevin- great point!! I agree with the unit test - compilation notion; however, given that not everyone actually takes the time to write tests, we&#8217;ll have to settle for mandatory technologies like compilers for the time being!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andy</title>
		<link>http://thediscoblog.com/2007/06/25/bugs-you-can-write-in-groovy-but-cant-in-java/#comment-17042</link>
		<dc:creator>Andy</dc:creator>
		<pubDate>Mon, 25 Jun 2007 18:56:57 +0000</pubDate>
		<guid isPermaLink="false">http://thediscoblog.com/2007/06/25/bugs-you-can-write-in-groovy-but-cant-in-java/#comment-17042</guid>
		<description>Ricky- You raise a valid point-- is it &lt;i&gt;really&lt;/i&gt; a bug? And yes, "guess" is a rather misleading term, man. But I think the point is still valid-- given the Groovy method as defined, Groovy realizes that there are more than two possible paths, so it needs to handle the 3rd default path and assumes the author meant &lt;code&gt;null&lt;/code&gt;, when in reality, the developer "forgot" to handle a 3rd condition (probably thinking about disco dancing rather than the task at hand) and was intending to return another Integer value. Whether or not you define this as a  bug, the point being that you can't write this method in normal Java (for better or for worse). 

Thanks for your input-- your thoughts on Haskell are extremely interesting!</description>
		<content:encoded><![CDATA[<p>Ricky- You raise a valid point&#8211; is it <i>really</i> a bug? And yes, &#8220;guess&#8221; is a rather misleading term, man. But I think the point is still valid&#8211; given the Groovy method as defined, Groovy realizes that there are more than two possible paths, so it needs to handle the 3rd default path and assumes the author meant <code>null</code>, when in reality, the developer &#8220;forgot&#8221; to handle a 3rd condition (probably thinking about disco dancing rather than the task at hand) and was intending to return another Integer value. Whether or not you define this as a  bug, the point being that you can&#8217;t write this method in normal Java (for better or for worse). </p>
<p>Thanks for your input&#8211; your thoughts on Haskell are extremely interesting!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kevin Kleinfelter</title>
		<link>http://thediscoblog.com/2007/06/25/bugs-you-can-write-in-groovy-but-cant-in-java/#comment-16982</link>
		<dc:creator>Kevin Kleinfelter</dc:creator>
		<pubDate>Mon, 25 Jun 2007 14:39:06 +0000</pubDate>
		<guid isPermaLink="false">http://thediscoblog.com/2007/06/25/bugs-you-can-write-in-groovy-but-cant-in-java/#comment-16982</guid>
		<description>#define compile execute_unit_test

Given that many dynamic languages have no explicit compile step, I assert that execute-unit-test takes the place of an explicit compile step.

I used to be a strong advocate of explicit static typing.    Now I'm less certain of the value.  I'm certain that, as commonly used, explicit static types are of less value than we might expect.  For example, I frequently see variables defined to be integers, when the correct values range over a much smaller range than -MAXINT to +MAXINT.

It has been suggested by others that compile-time type checking is just an exceptionally weak form of unit test.  If I write a function that is expected to return only 0 or 3, I have a responsibility to write a unit test *before* I write the function that confirms that the function returns only a 0 or a 3.

However, I do think that some sort of static type definition may be useful as a part of automated unit testing.  If I specify that a function accepts an integer parameter and returns an integer value, an automated unit test tool that exercises the function by sending it a broad range of integers and validates that it returns only integers, would be a useful tool.

Using the example from the original posting, a unit test spec that defined allowable inputs as being all strings and allowable outputs as 0 or 3, would quickly demonstrate the bug and would validate correct behavior much more thoroughly than compile-time type checking.

So I come to the theory that static definition of types is not useful at compile time, where they are commonly used (currently), but they may be useful at unit-test time, where they are infrequently used!</description>
		<content:encoded><![CDATA[<p>#define compile execute_unit_test</p>
<p>Given that many dynamic languages have no explicit compile step, I assert that execute-unit-test takes the place of an explicit compile step.</p>
<p>I used to be a strong advocate of explicit static typing.    Now I&#8217;m less certain of the value.  I&#8217;m certain that, as commonly used, explicit static types are of less value than we might expect.  For example, I frequently see variables defined to be integers, when the correct values range over a much smaller range than -MAXINT to +MAXINT.</p>
<p>It has been suggested by others that compile-time type checking is just an exceptionally weak form of unit test.  If I write a function that is expected to return only 0 or 3, I have a responsibility to write a unit test *before* I write the function that confirms that the function returns only a 0 or a 3.</p>
<p>However, I do think that some sort of static type definition may be useful as a part of automated unit testing.  If I specify that a function accepts an integer parameter and returns an integer value, an automated unit test tool that exercises the function by sending it a broad range of integers and validates that it returns only integers, would be a useful tool.</p>
<p>Using the example from the original posting, a unit test spec that defined allowable inputs as being all strings and allowable outputs as 0 or 3, would quickly demonstrate the bug and would validate correct behavior much more thoroughly than compile-time type checking.</p>
<p>So I come to the theory that static definition of types is not useful at compile time, where they are commonly used (currently), but they may be useful at unit-test time, where they are infrequently used!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ricky Clarkson</title>
		<link>http://thediscoblog.com/2007/06/25/bugs-you-can-write-in-groovy-but-cant-in-java/#comment-16957</link>
		<dc:creator>Ricky Clarkson</dc:creator>
		<pubDate>Mon, 25 Jun 2007 12:43:39 +0000</pubDate>
		<guid isPermaLink="false">http://thediscoblog.com/2007/06/25/bugs-you-can-write-in-groovy-but-cant-in-java/#comment-16957</guid>
		<description>A stray &#60; destroyed some of my last post.  A preview button would be good!

Here's the missing bit again (clipboard to the rescue):

((lambda (f x) (funcall f f x)) (lambda (f x) (if (&#60;= x 1) x (* x (funcall f f (1- x))))) 5)

(To explain that, the inner lambda is a factorial function that takes itself as a parameter.  The outer lambda is a combinator that takes a function (the factorial) and a number, and calls the function, passing it to itself.  Here's the same code written with a name, *fac*:

(defparameter *fac* (lambda (f x) (if (&#60;= x 1) x (* x (funcall f f (1- x))))))

(funcall *fac* *fac* 5)
 - outputs 120
)

There are apparently other static type systems that can express this (infinite types), but it makes you realise that when you're using Lisp, you just don't have to think about the maths there.  It's not even as if the environment is doing the thinking for you - it just isn't there.  You don't have to be able to prove code to run code.

So, having dropped off the bottom of static typing, and gone around to Lisp, Ruby, Groovy, etc., you will find yourself making the occasional type error, and missing Java-quality refactoring tools.  That's where optional static typing comes in.

In this particular case, in Lisp you could write a macro that checks your functions to see whether they definitely return a value, resulting in code like:

(defun-explicit-return calculate-norm-length (str)
. (if (zerop (length str))
. . 0
. . (progn
. . . (print "Wasn't zero")
. . . (if (&#62; (length str) 3)
. . . . 3))))

..giving a compile error.</description>
		<content:encoded><![CDATA[<p>A stray &lt; destroyed some of my last post.  A preview button would be good!</p>
<p>Here&#8217;s the missing bit again (clipboard to the rescue):</p>
<p>((lambda (f x) (funcall f f x)) (lambda (f x) (if (&lt;= x 1) x (* x (funcall f f (1- x))))) 5)</p>
<p>(To explain that, the inner lambda is a factorial function that takes itself as a parameter.  The outer lambda is a combinator that takes a function (the factorial) and a number, and calls the function, passing it to itself.  Here&#8217;s the same code written with a name, *fac*:</p>
<p>(defparameter *fac* (lambda (f x) (if (&lt;= x 1) x (* x (funcall f f (1- x))))))</p>
<p>(funcall *fac* *fac* 5)<br />
 - outputs 120<br />
)</p>
<p>There are apparently other static type systems that can express this (infinite types), but it makes you realise that when you&#8217;re using Lisp, you just don&#8217;t have to think about the maths there.  It&#8217;s not even as if the environment is doing the thinking for you - it just isn&#8217;t there.  You don&#8217;t have to be able to prove code to run code.</p>
<p>So, having dropped off the bottom of static typing, and gone around to Lisp, Ruby, Groovy, etc., you will find yourself making the occasional type error, and missing Java-quality refactoring tools.  That&#8217;s where optional static typing comes in.</p>
<p>In this particular case, in Lisp you could write a macro that checks your functions to see whether they definitely return a value, resulting in code like:</p>
<p>(defun-explicit-return calculate-norm-length (str)<br />
. (if (zerop (length str))<br />
. . 0<br />
. . (progn<br />
. . . (print &#8220;Wasn&#8217;t zero&#8221;)<br />
. . . (if (&gt; (length str) 3)<br />
. . . . 3))))</p>
<p>..giving a compile error.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ricky Clarkson</title>
		<link>http://thediscoblog.com/2007/06/25/bugs-you-can-write-in-groovy-but-cant-in-java/#comment-16952</link>
		<dc:creator>Ricky Clarkson</dc:creator>
		<pubDate>Mon, 25 Jun 2007 12:20:52 +0000</pubDate>
		<guid isPermaLink="false">http://thediscoblog.com/2007/06/25/bugs-you-can-write-in-groovy-but-cant-in-java/#comment-16952</guid>
		<description>I'm struggling to see why you think that returning null in the Groovy code is a bug.  I've never used Groovy, I'm mainly a Java programmer, but I assumed straight away that the code would return null given "cat".

Lisp has been returning NIL for aeons with similar code.  Writing code that explicitly returns null, or throws an exception, etc., just makes a partial function (that's a well-defined term, plug it into wikipedia) harder to read.

Static typing, ultimately, is about proving that the code will work, even for cases you haven't actually tried yet.  Java doesn't go very far there, e.g., it allows null references, and it doesn't have a particularly advanced static type system.  Haskell, on the other hand, does go very far, and it's worth looking at, to realise that ultimately if you use static typing to construct proofs, you end up being quite removed from the actual problem you're trying to solve, and also find yourself reading mathematics papers with Greek symbols in.

You can fall off the bottom (a pun for those who know) of Haskell's static typing - for example, this Lisp code is inexpressible in Haskell - the type system isn't flexible enough:

((lambda (f x) (funcall f f x)) (lambda (f x) (if ( (length str) 3)
. . . . 3))))

..giving a compile error.  You could, instead, make it signal a condition (which is like throwing an exception but doesn't destroy the stack) at runtime, instead of returning NIL, but without actually having to litter the code with the rather irrelevant else clauses.

Also, dynamic language users do use types, they just don't use static types (usually).  Be careful on your terminology.  And, there are no guesses to be made by the runtime engine, the language defines the rules.  I've not yet seen a language that relies on heuristics for its interpretation.

I'd like to write in a dynamic language, then when I feel like I want to prove the correctness of some code, add static types to it, with the full power of Haskell's type system (or something better), until I have.  When I find myself writing more test code than production code, I know what I'm really looking for is a proof.</description>
		<content:encoded><![CDATA[<p>I&#8217;m struggling to see why you think that returning null in the Groovy code is a bug.  I&#8217;ve never used Groovy, I&#8217;m mainly a Java programmer, but I assumed straight away that the code would return null given &#8220;cat&#8221;.</p>
<p>Lisp has been returning NIL for aeons with similar code.  Writing code that explicitly returns null, or throws an exception, etc., just makes a partial function (that&#8217;s a well-defined term, plug it into wikipedia) harder to read.</p>
<p>Static typing, ultimately, is about proving that the code will work, even for cases you haven&#8217;t actually tried yet.  Java doesn&#8217;t go very far there, e.g., it allows null references, and it doesn&#8217;t have a particularly advanced static type system.  Haskell, on the other hand, does go very far, and it&#8217;s worth looking at, to realise that ultimately if you use static typing to construct proofs, you end up being quite removed from the actual problem you&#8217;re trying to solve, and also find yourself reading mathematics papers with Greek symbols in.</p>
<p>You can fall off the bottom (a pun for those who know) of Haskell&#8217;s static typing - for example, this Lisp code is inexpressible in Haskell - the type system isn&#8217;t flexible enough:</p>
<p>((lambda (f x) (funcall f f x)) (lambda (f x) (if ( (length str) 3)<br />
. . . . 3))))</p>
<p>..giving a compile error.  You could, instead, make it signal a condition (which is like throwing an exception but doesn&#8217;t destroy the stack) at runtime, instead of returning NIL, but without actually having to litter the code with the rather irrelevant else clauses.</p>
<p>Also, dynamic language users do use types, they just don&#8217;t use static types (usually).  Be careful on your terminology.  And, there are no guesses to be made by the runtime engine, the language defines the rules.  I&#8217;ve not yet seen a language that relies on heuristics for its interpretation.</p>
<p>I&#8217;d like to write in a dynamic language, then when I feel like I want to prove the correctness of some code, add static types to it, with the full power of Haskell&#8217;s type system (or something better), until I have.  When I find myself writing more test code than production code, I know what I&#8217;m really looking for is a proof.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
