title: Groovy as a substitute for Java when using BigDecimal?
body: <p>I have just completed an evaluation of Java, Groovy and Scala.</p>
  
  <p>The factors I considered were: readability, precision</p>
  
  <p>The factors I would like to know: performance, ease of integration</p>
  
  <p>I needed a BigDecimal level of precision.</p>
  
  <p>Here are my results:</p>
  
  <p><strong>Java</strong></p>
  
  <pre><code>void someOp()
  {
      BigDecimal del_theta_1 = toDec(6);
      BigDecimal del_theta_2 = toDec(2);
      BigDecimal del_theta_m = toDec(0);
  
      del_theta_m = abs(del_theta_1.subtract(del_theta_2))
        .divide(log(del_theta_1.divide(del_theta_2)));
  
  }
  </code></pre>
  
  <p><strong>Groovy</strong></p>
  
  <pre><code>void someOp()
  {
   def del_theta_1 = 6.0
   def del_theta_2 = 2.0
   def del_theta_m = 0.0
  
   del_theta_m = Math.abs(del_theta_1 - del_theta_2) / Math.log(del_theta_1 / del_theta_2);
  }
  </code></pre>
  
  <p><strong>Scala</strong></p>
  
  <pre><code>def other(){
   var del_theta_1 = toDec(6);
   var del_theta_2 = toDec(2);
   var del_theta_m = toDec(0);
   del_theta_m = (
    abs(del_theta_1 - del_theta_2)  
    / log(del_theta_1 / del_theta_2)
   )
  }
  </code></pre>
  
  <p>Note that in Java and Scala I used static imports.</p>
  
  <p><strong>Java:</strong> 
  Pros: it is Java<br>
  Cons: no operator overloading (lots o methods), barely readable/codeable</p>
  
  <p><strong>Groovy:</strong> 
  Pros: default BigDecimal means no visible typing, least surprising BigDecimal support for all operations (division included)<br>
  Cons: another language to learn</p>
  
  <p><strong>Scala:</strong>
  Pros: has operator overloading for BigDecimal<br>
  Cons: some surprising behaviour with division (fixed with Decimal128), another language to learn</p>