Disclaimer: this article is a translation. Original post was published in June, 2015. The first part is here. Let’s go on. For seven f*cking years, I’ve been waiting for a programming language that would meet my requirements. During this time, I’ve tested everything. Everything means all the general-purpose crap and all the not-quite-general-purpose crap. You can’t feel a language only by reading about it and writing “Hello, World!”. To understand the language, you should write at least something with it.
Since I’m going to provoke trolls on the subject of programming languages, and even name the best one in the world (I mean absolutely the best, for sure), I recommend all of them to check out my previous post “Choosing a Programming Language”. Everything mentioned there is still up-to-date, and I wouldn’t’ like to repeat myself here. Read it? Good. Today I am going to talk about the best programming language in the world, and I’ll name it closer to the end of this post.
In the previous article about constructing types in Scala we’ve reviewed the idea of constructing types that are similar to classes. This allows to separate stored data from meta-information and emphasize representation of entities properties. But the mentioned approach turns out to be quite difficult due to HList type usage. Thus, we realized that for most practical tasks a linear ordered sequence of properties, as well as completeness of a property set, is not necessary.
I was really glad to find out that my presentation about Scala and Java 8 was retweeted more than other similar content. That’s why I decided to make some notes and tell you about it. We are going to talk about the difference between Scala and Java and say why each of them is important. There are mutual innovations. Each language has borrowed something from each other. The question is: do you have to learn Scala if there is Java available?
This article may be considered as a continuation of Introduction to Writing Tests with ScalaTest. In this post I would like to talk about ScalaMock. Mocking is a technique by which you can test code without requiring all of its dependencies in place. Java offers several frameworks for mocking objects when writing tests. The most well known are JMock, EasyMock, and Mockito. As the Scala language introduces new elements such as traits and functions, the Java-based mocking frameworks are not enough, and this is where ScalaMock comes into play.
When constructing “enterprise” systems it often turns out that ValueObjects (or case classes) are created. They store information about some instance of entity that is processed by the system. For example: case class Person(name: String, address: Address) This way of data representation in the system has two major strengths: Strictly typed access to the data; Capability of meta information binding to features with the help of annotations. And drawbacks: - If there are many entities, the number of such classes also increases and their processing requires a lot of code of the same type (copy-paste); - Meta information can be represented by annotations to the object features.
To be able to quickly start visualizing some of the tests that can be written with ScalaTest, we can take advantage of the test-patterns-scala template from the Typesafe Activator. It consists of a number of examples that essentially target the ScalaTest framework. The easiest way to get the code is to download the template bundle for test-patterns-scala. An archive contains a bootstrap script that can simplify our life’s by starting Activator automatically.