Scala is smooth idiomatic and beats the table.

While Scala is designed to unwind Java boilerplate practices (and some other things like immutability, first-class functional programming, etc.), this slick library tutorial suggests a lot of patterns around a simple table definition:

  class MyTable(tag: Tag) extends Table[(String, String, String)](tag, "MyTable") {
    def Col1 = column[String]("Col1")
    def Col2 = column[String]("Col2")
    def Col3 = column[String]("Col3")
    def * = (Col1, Col2, Col3)


I could hardly name this example of api usage anywhere near idiomatic; It's easy to list all the duplicates in the above working code - for table name, column types, column names. I find it hard to imagine using this style to define a larger schema with any elegance in my codebase.

What's your favorite way to reduce this into something where all that duplication and verbosity is no longer needed? Is smooth code generation the only antidote?

I found this , but sometimes I prefer to focus more on the logic of the application than to dive into the dumps of the mind of the library creators, as generous as their contributions can be. Don't get me wrong, I think the slick is very cool, it's just that this number of patterns should be a naive example that could be greatly simplified ...


source to share

All Articles