[En][Scala] First Scala project
Posted by Rizn on 16/01/2016
Blog or CMS in Play might not be the best example to show benefits of functional language, but definitely I would recommend for anyone wanting to dive into scala who comes from a typical OOP / MVC background just to get familiar with scala syntax and some concepts such as "futures".
Here's the project on github. If you have any comments or wish to create pull request I'd really appreciate it.
I personally found that Play framework is very accessible and easy to use. In fact it seems simpler than symfony2 - a major php framework.
The same applies to Slick - a functional relational mapper. Much lighter solution than php's doctrine2 ORM, which IMO is quite "fat" and clunky.
When it comes to database I decided to use PostgreSQL (however it should work with database of your choice - a matter of changing settings and driver in conf/application.conf). There are two reasons for that. The first one is this awesome article, which was initial inspiration for my project. The second one is easy PostgreSQL support on Heroku, where this blog is hosted (by the way, Heroku has a great Scala support in general).
One of major things which is worth to get used to (if you come from single threaded language such as php) is concurrency. All controller's actions are asynchronous and expect "Future[Result]" (apparently even normal Actions in Play are async, but I need to learn more about it). In php, there's library called ReactPHP, which gives some taste of concurrency, but it's not the same as in scala, where concurrency is default behaviour.
Authentication and security is always paramount for any application. However instead of using an existing authentication module such as Deadbolt I decided to write something simpler and easier to understand. Reading The Tunnel Bear's authentication article was a big help to get some idea how to write auth system in scala. It's also worth to look at Play's example of auth controller. Also scala's new pattern "action composition" is a great tool for controller authentication.
Last, but not least - the blog uses a simplified version of a nice Clean Blog bootstrap template.
There are still plenty improvements to do, but as they say it's "better done than perfect".