Advertisement
mitrakov

Golden Rules

Sep 17th, 2018
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.78 KB | None | 0 0
  1. 1. Add '' or "" to interpolated values in a logger message. It will help to avoid confusing with spaces (" ")
  2.   // incorrect:
  3.   Logger.info("Received treatment: $treatment")
  4.   // correct:
  5.   Logger.info("Received treatment: '$treatment'")
  6. 2. in build.sbt use '%%' pattern instead of '%'. It will help with upgrading in the future
  7.   // incorrect:
  8.   "com.typesafe.play" % "play-slick_2.11" % "3.0.1"
  9.   // correct:
  10.   "com.typesafe.play" %% "play-slick" % "3.0.1"
  11. 3. Use Seq instead of List in case classes to avoid problems with Json (de)-serializing:
  12.   // incorrect
  13.   case class Images(userId: Long, images: List[String])
  14.   implicit val jsonFormat = Json.format[Images]
  15.   // correct
  16.   case class Images(userId: Long, images: Seq[String])
  17.   implicit val jsonFormat = Json.format[Images]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement