Scala Frustrationsin Real DevelopmentNaoki Takezoe@takezoenNTT-DATA INTELLILINK
Abstract• Scala is pretty good for real development.• However Scala has also some bad points.• Please note for these point...
Scala 300 Recipes from Shoeisha• Includes 300 Practical Scala  Recipes.• from Basic Scala topics to  frameworks and tools....
Why we are using Scala?• Decrease costs of system development.• We felt the limit of Java several years ago.• Scala might ...
About Our Project• Porting Java based web application to Scala.• Over 170 HTMLs and 40,000 lines.• 5 members on 6 months.B...
Benefits of Scala• Decrease amount of source code ▫ 40%-50% OFF ▫ Better abstraction techniques• Decrease bugs ▫ More type...
Benefits of Scala• Decrease amount of source code ▫ 40%-50% OFF ▫ Better abstraction techniques Flexibility and Safety• De...
Long compilation time• Compilation is so much heavy.• Painful for large application development.
Solution Buy high spec machines Asynchronous and automated build
ScalaIDE is heavy• We meet a sandglass frequently.
Solution 1. Turn off the incremental builder 2. Turn off the code completion 3. Try other IDE or text editor
sbt is NOT Simple Build Tool• When we get a trouble, difficult to find a reason.• Rapid version up causes compatibility pr...
Solution We really need SBT in Action!
Long compilation time• Many code generation and template compilation.• Development mode is slow also.
Solution Buy high spec machines Divide large project play2-fastassets decreases request
Inflexible Validation• Client-side validation is not provided.• Error Message can’t be contained field name.
Solution Original client-side validation framework based on Play2’s form definition Original helper to display error messa...
Anorm is too simple•   We have to write all SQL.•   Magic does not already exist.•   SQL is not type safe.•   No support f...
Solution Use other ORMs such as ScalaQuery. We used a combination of scalaquery-magic scalagen and mirage-scala.
Function22 Problem in form definition• a.k.a. Tuple22 Problem• Form can not have over 18 properties. val userForm = Form( ...
Solution Nested definition, BUT it’s not expectable.   val userForm = Form(     mapping(      "firstName"      -> text,   ...
No Servlet and HttpSession• Hard to port existing Java based web apps.• We want to run Play2 on the servlet container by  ...
Solution play2-war-plugin packs Play2 apps to war. play2-httpsession provides HttpSession by using with play2-war-plugin.
solr-scala-clienthttps://github.com/takezoe/solr-scala-client• Simple wrapper of SolrJ for Scala.• Query converter using p...
scalagenhttps://github.com/takezoe/scalagen•   Code Generator from RDBMS.•   Supports Anorm and ScalaQuery in the current ...
scalaquery-magichttps://github.com/shimamoto/scalaquery-magic• Extends ScalaQuery.• Make a Magic (like old Anorm’s Magic) ...
mirage-scalahttps://github.com/takezoe/mirage-scala• SQL Centric ORM similar to Anorm.• Executable SQL template called 2wa...
play2-httpsessionhttps://github.com/takezoe/play2-httpsession• Provide HttpSession for Play2 applications.• Work with play...
play2-fastassetshttps://github.com/takezoe/play2-fastassets• Decrease amount of request to external CSS,  JavaScript and i...
Scala is practical• You are evangelists of Scala.• Please introduce Scala in your work.• But so carefully, especially in t...
Scala is now glowing up!• This way along which Java passed.• Time will solve these problems.• We can contribute Scala glow...
Scala Frustrations
Scala Frustrations
Scala Frustrations
Scala Frustrations
Scala Frustrations
Upcoming SlideShare
Loading in …5
×

Scala Frustrations

4,699 views

Published on

at Scala Conference in Japan 2013

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
4,699
On SlideShare
0
From Embeds
0
Number of Embeds
1,709
Actions
Shares
0
Downloads
18
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Scala Frustrations

  1. 1. Scala Frustrationsin Real DevelopmentNaoki Takezoe@takezoenNTT-DATA INTELLILINK
  2. 2. Abstract• Scala is pretty good for real development.• However Scala has also some bad points.• Please note for these points when you introduce Scala into real development.
  3. 3. Scala 300 Recipes from Shoeisha• Includes 300 Practical Scala Recipes.• from Basic Scala topics to frameworks and tools.Covers Play2, Akka, sbt, scaladoc, ScalaIDE,ScalaTest, Specs2, Scalatra, ScalaQuery,Anorm, Casbah, spray, scala-io, scala-time,sjson, util-eval, scalaxb, Dispatch and more.
  4. 4. Why we are using Scala?• Decrease costs of system development.• We felt the limit of Java several years ago.• Scala might be a breakthrough?
  5. 5. About Our Project• Porting Java based web application to Scala.• Over 170 HTMLs and 40,000 lines.• 5 members on 6 months.Before After Seasar2  Play2 (Customized) Apache Click  ScalaQuery (Cuztomized) S2JDBC  PostgreSQL PostgreSQL + Tsearch  Apache Solr Raw JavaScript  jQuery + jQuery UI
  6. 6. Benefits of Scala• Decrease amount of source code ▫ 40%-50% OFF ▫ Better abstraction techniques• Decrease bugs ▫ More type safe ▫ Immutable data types• Java Interoperability ▫ Many Java based Frameworks and Libraries are available ▫ Easy to port existing Java software
  7. 7. Benefits of Scala• Decrease amount of source code ▫ 40%-50% OFF ▫ Better abstraction techniques Flexibility and Safety• Decrease bugs ▫ More type safe ▫ Immutable data types• Java Interoperability ▫ Many Java based Frameworks and Libraries are available ▫ Easy to port existing Java software
  8. 8. Long compilation time• Compilation is so much heavy.• Painful for large application development.
  9. 9. Solution Buy high spec machines Asynchronous and automated build
  10. 10. ScalaIDE is heavy• We meet a sandglass frequently.
  11. 11. Solution 1. Turn off the incremental builder 2. Turn off the code completion 3. Try other IDE or text editor
  12. 12. sbt is NOT Simple Build Tool• When we get a trouble, difficult to find a reason.• Rapid version up causes compatibility problem of sbt plugins.
  13. 13. Solution We really need SBT in Action!
  14. 14. Long compilation time• Many code generation and template compilation.• Development mode is slow also.
  15. 15. Solution Buy high spec machines Divide large project play2-fastassets decreases request
  16. 16. Inflexible Validation• Client-side validation is not provided.• Error Message can’t be contained field name.
  17. 17. Solution Original client-side validation framework based on Play2’s form definition Original helper to display error messages
  18. 18. Anorm is too simple• We have to write all SQL.• Magic does not already exist.• SQL is not type safe.• No support for dynamic SQL.
  19. 19. Solution Use other ORMs such as ScalaQuery. We used a combination of scalaquery-magic scalagen and mirage-scala.
  20. 20. Function22 Problem in form definition• a.k.a. Tuple22 Problem• Form can not have over 18 properties. val userForm = Form( mapping( "firstName“ -> text, "lastName“ -> text, "mailAddress“ -> email, "password“ -> text, ... Max 18 properties "tel“ -> text, "mobile“ -> text, "company“ -> text, "department“ -> text )(UserInfo.apply)(UserInfo.unapply) )
  21. 21. Solution Nested definition, BUT it’s not expectable. val userForm = Form( mapping( "firstName" -> text, "lastName" -> text, "mailAddress" -> email, "password" -> text, "companyInfo" -> mapping( "company" -> text, "department" -> text )(CompanyInfo.apply)(CompanyInfo.unapply) )(UserInfo.apply)(UserInfo.unapply) )
  22. 22. No Servlet and HttpSession• Hard to port existing Java based web apps.• We want to run Play2 on the servlet container by un-technical reasons.
  23. 23. Solution play2-war-plugin packs Play2 apps to war. play2-httpsession provides HttpSession by using with play2-war-plugin.
  24. 24. solr-scala-clienthttps://github.com/takezoe/solr-scala-client• Simple wrapper of SolrJ for Scala.• Query converter using parser combinator.import jp.sf.amateras.solr.scala._val client = new SolrClient("http://localhost:8983/solr")val result = client.query("name: ?name?") .getResultAsMap(Map("name" -> "ThinkPad & X201s")) // => name:("ThinkPad" AND "X201s")result.documents.foreach { doc: Map[String, Any] => ...}
  25. 25. scalagenhttps://github.com/takezoe/scalagen• Code Generator from RDBMS.• Supports Anorm and ScalaQuery in the current version.• Easy to add support for other ORMs.• Work as CLI and sbt plugin.seq(jp.sf.amateras.scalagen.ScalagenPlugin.scalagenSettings: _*)scalagenConfiguration := jp.sf.amateras.scalagen.Settings( // for ScalaQuery generator = new jp.sf.amateras.scalagen.ScalaQueryGenerator(), // for Anorm //generator = new jp.sf.amateras.scalagen.ScalaQueryGenerator(), driver = "org.hsqldb.jdbcDriver", url = "jdbc:hsqldb:hsql://localhost/", username = "sa", password = "")
  26. 26. scalaquery-magichttps://github.com/shimamoto/scalaquery-magic• Extends ScalaQuery.• Make a Magic (like old Anorm’s Magic) by code generation using scalagen. val userInfoDao = new UserInfoDao() // SELECT by ID val userInfo = userInfoDao.selectById(1) // INSERT userInfoDao.insert(UserInfo(DEFAULT[Int], userName, password)) // UPDATE userInfoDao.update(userInfo.copy(userName = newName)) // DELETE by ID userInfoDao.deleteById(1)
  27. 27. mirage-scalahttps://github.com/takezoe/mirage-scala• SQL Centric ORM similar to Anorm.• Executable SQL template called 2waySQL.SLEECT USER_ID, USER_NAME, PASSWORDFROM USER_INFO/*BEGIN*/WHERE /*IF userId != null*/ USER_ID = /*userId*/1 /*END*/ /*IF userId != null*/ USER_NAME = /*userName*/ takezoe /*END*//*END*/
  28. 28. play2-httpsessionhttps://github.com/takezoe/play2-httpsession• Provide HttpSession for Play2 applications.• Work with play2-war-plugin.import jp.sf.amateras.play2.httpsession.HttpSessionSupport._def index = Action { implicit request => // retrieve the object from HttpSession val value: Option[String] = HttpSession[String]("key") Ok(value).withHttpSession { // store objects into HttpSession "key" -> "value" }}
  29. 29. play2-fastassetshttps://github.com/takezoe/play2-fastassets• Decrease amount of request to external CSS, JavaScript and images by browser cache.@(title: String)(content: Html)@import jp.sf.amateras.play2.fastassets.FastAssets<!DOCTYPE html><html> <head> <title>@title</title> <link rel="stylesheet" media="screen" href="@FastAssets.at("stylesheets/main.css")"> <link rel="shortcut icon" type="image/png" href="@FastAssets.at("images/favicon.png")"> <script src="@FastAssets.at("javascripts/jquery-1.7.1.min.js")" type="text/javascript"></script> </head> <body> @content </body></html>
  30. 30. Scala is practical• You are evangelists of Scala.• Please introduce Scala in your work.• But so carefully, especially in the large project.
  31. 31. Scala is now glowing up!• This way along which Java passed.• Time will solve these problems.• We can contribute Scala glowing.

×