A great article has been published at ZeroTurnaround's blog: Scala 2013: A Pragmatic Guide to Scala Adoption in Your Java Organization. You can download it as a PDF (which looks really cool!). The nice part is that it includes an interview with Martin Odersky and quotes by Josh Suereth.
Pages
Showing posts with label scala. Show all posts
Showing posts with label scala. Show all posts
Tuesday, September 18, 2012
Sunday, January 17, 2010
Continuing the BigDecimal's Game: Scala vs Clojure
After studying the issues with decimal types in Groovy and JRuby, with lafy, we discovered some funny things in Scala and Clojure as well.
Consider, if you need to accumulate 0.1 until the result is one. Groovy does it as expected
0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 = 1.0
Just because 0.1 is BigDecimal in Groovy.
In Clojure, the example is not that nice:
(+ 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1) results in 0.9999999999999999.
Basically, the problem is solved when you add the M qualifier to each of the numbers in the expression, like
(+ 0.1M 0.1M 0.1M 0.1M 0.1M 0.1M 0.1M 0.1M 0.1M 0.1M) = 1.0
Or use rational numbers:
(+ 1/10 1/10 1/10 1/10 1/10 1/10 1/10 1/10 1/10 1/10) = 1.0
The hypothetical problem is that, if a number (say, some money amount) is stored in the database, and the calculation is configured by the user in business rules via some DSL, then a user could create a calculation that could lead to a loss of precision. For instance:
The question is what is the rationale behind such behavior and which result is correct? To me, when writing an application which operates with monetary amounts, it is the Scala which is correct.
Consider, if you need to accumulate 0.1 until the result is one. Groovy does it as expected
0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 = 1.0
Just because 0.1 is BigDecimal in Groovy.
In Clojure, the example is not that nice:
(+ 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1) results in 0.9999999999999999.
Basically, the problem is solved when you add the M qualifier to each of the numbers in the expression, like
(+ 0.1M 0.1M 0.1M 0.1M 0.1M 0.1M 0.1M 0.1M 0.1M 0.1M) = 1.0
Or use rational numbers:
(+ 1/10 1/10 1/10 1/10 1/10 1/10 1/10 1/10 1/10 1/10) = 1.0
The hypothetical problem is that, if a number (say, some money amount) is stored in the database, and the calculation is configured by the user in business rules via some DSL, then a user could create a calculation that could lead to a loss of precision. For instance:
(* 100M 1.1) = 110.00000000000001
(class (* 100M 1.1)) = java.lang.Double
Double there is!!!
The same kind calculation gives BigDecimal as a result in Scala:
scala.BigDecimal(1.5) * 1.5
BigDecimal = 2.25
The question is what is the rationale behind such behavior and which result is correct? To me, when writing an application which operates with monetary amounts, it is the Scala which is correct.
Tuesday, June 24, 2008
JAZOON 2008, Day 1
The first day @ JAZOON is complete!
The opening session.
Against all odds - efficient Rich GUI development in Java. This was a talk about the rich UI development for a company called APG that is dealing with billboarding. The current solution was implementing Oracle Forms technology and as Forms is being deprecated, they decided to implement the rich client in Java with Swing.
So basically they were talking about the rewrite of UI without touching the back-end. As the result there's the direct connection from client to the database. I'm not sure how scalable new solution is, but the technology used for implementation is what amazed me the most. The UI is being generated based on meta-data described with some DSL. The framework used for this is the openArchitectureWare. The guys were claiming that this way they increased the development speed compared to the Oracle Forms. I think that the complete solution is a real crap. I can tell why. First, while the demo failed, they showed us the code - it was half-german, half-english code there, i.e. some methods were named in German which I think is a rally bad practice. Secondly, the technology stack which lead from the specification to the implementation is very unclear: if there will be an error, the application developer will be seeking for the problem all the day long instead of writing the real code. And last but not least, they did not finalize the project yet, so it was a little bit too early to talk about its success. I think even if the project gets finalized, if future the cost of maintaining this piece of software will be inadequate.
Perhaps I'm too rude in expressing my opinion to the solution some people may think is really good. May be it is just that I do not understand the MDA really well. So probably I'll take a look at it if it happens that I have nothing else to do :)
AJAX Push for Revolutionary Enterprise Applications presented by Micha Kiener (mimacom ag) and Ted Goddard (ICEsoft Technologies Inc.) was a nice presentation I enjoyed. The technology presented is quite innovative and it looks like pushing a new wave in the area of Web 2.0 application development. The keywords: Ajax Push, Comet, "Reverse Ajax", ICEFaces, Edoras, Servlet 3.0.
The opening session.
- At the talk called The Challenge of Scalable Languages, Martin Odersky (the creator of Scala) was talking mainly about Scala language and how does it relates to Java. Explaining some of the design decisions for Scala (at last, I've got the answer for the silly declaration construct in Scala, i.e. var x: Int). There are many nice features in Scala I think. But I do not really understand why the operator overloading is brought in again?! Operator overloading was the feature that Java designers wanted to get rid of after C++, because when you read the A+B you cannot be sure weather the operands are really numbers.
- Simon Phipps was talking about The Adoption-Led Market. He started with Sun's relation to open-source, continuing with open-source history and licensing. This was a good talk with a lot of funny stuff in it. The only question to Sun is that if Sun is so opened to open-source software, why did to closed the source of MySQL engine??
- Next, Rod Johnson expressed a lot of criticism in respect to J2EE, JCP, etc in his talk Where will Tomorrow's Innovation Come From in Enterprise Java. For sure, he didn't forget to mention the Spring Application Platform :)
Against all odds - efficient Rich GUI development in Java. This was a talk about the rich UI development for a company called APG that is dealing with billboarding. The current solution was implementing Oracle Forms technology and as Forms is being deprecated, they decided to implement the rich client in Java with Swing.
So basically they were talking about the rewrite of UI without touching the back-end. As the result there's the direct connection from client to the database. I'm not sure how scalable new solution is, but the technology used for implementation is what amazed me the most. The UI is being generated based on meta-data described with some DSL. The framework used for this is the openArchitectureWare. The guys were claiming that this way they increased the development speed compared to the Oracle Forms. I think that the complete solution is a real crap. I can tell why. First, while the demo failed, they showed us the code - it was half-german, half-english code there, i.e. some methods were named in German which I think is a rally bad practice. Secondly, the technology stack which lead from the specification to the implementation is very unclear: if there will be an error, the application developer will be seeking for the problem all the day long instead of writing the real code. And last but not least, they did not finalize the project yet, so it was a little bit too early to talk about its success. I think even if the project gets finalized, if future the cost of maintaining this piece of software will be inadequate.
Perhaps I'm too rude in expressing my opinion to the solution some people may think is really good. May be it is just that I do not understand the MDA really well. So probably I'll take a look at it if it happens that I have nothing else to do :)
AJAX Push for Revolutionary Enterprise Applications presented by Micha Kiener (mimacom ag) and Ted Goddard (ICEsoft Technologies Inc.) was a nice presentation I enjoyed. The technology presented is quite innovative and it looks like pushing a new wave in the area of Web 2.0 application development. The keywords: Ajax Push, Comet, "Reverse Ajax", ICEFaces, Edoras, Servlet 3.0.
Subscribe to:
Posts (Atom)