Scala is a general purpose programming language principally targeting the Java Virtual Machine. Designed to express common programming patterns in a concise, elegant, and type-safe way, it fuses both imperative and functional programming styles.

learn more… | top users | synonyms

13
votes
2answers
4k views

Is there a canonical book on Scala? [closed]

I'm interested in learning Scala, but due to is relative newness, I can't seem to find a whole lot of books about it. Is there a book out there that's the de-facto standard for describing best ...
-1
votes
0answers
39 views

How should I use POJO in Scala?

I have created a Scala project that has Java dependencies at very low level (model, repository, etc.). Should I create implicit conversions to decouple it from POJO?
1
vote
1answer
165 views

When to use trait components, objects, package objects in Scala

When I am adding dependencies in Scala, I tend to use mixin trait components for those that are inherit to the class itself. For example, DaoGenerator extends Generator However, for trait components ...
4
votes
1answer
202 views

Migrating a Grails application to Scala Play/Spray

We have a moderately sized Grails web application using GORM/Hibernate over PostgreSQL and GSPs serving HTML, and also a few REST APIs. We are standardising on Scala, and would like to migrate this ...
12
votes
4answers
2k views

Why does Scala use the '_' operator for package import instead of '*' as in Java?

In my opinion, one of the greatest things about Scala is its interoperability with Java and its similar syntax. One thing that I found strange is the use of the _ operator for package wilcard imports ...
0
votes
1answer
69 views

Future and Try duality [closed]

I was looking at this lecture, https://class.coursera.org/reactive-002/lecture/135 at 2:15. The lecturer talks about the duality of Future and Try in Scala. For his demonstration he changes the type: ...
1
vote
2answers
46 views

Type of map for Try[T]

I was looking at the type of map for Try[T] in Scala, which is: def map[S](f: T=>S): Try[S] From Haskell, I am used to the type of map being: map :: (a->b)->[a]->[b] This seems very ...
3
votes
2answers
123 views

Designing a centralised command api

I'm working on a personal project that has a fairly complex UI. As much as possible I would like to remove mouse interaction. To help with that I am working on a kind of in app command line, where you ...
3
votes
1answer
45 views

Code style for parse-methods in Scala?

Say I have a class with multiple parameters: case class Foo(a: String, b: String, c: String, d: String, ... ) Now say I want to parse an instance of Foo from a Map[String, String]: // returns ...
4
votes
1answer
68 views

Right way to read from token list to implement parse tree

I'm trying to tackle the While Language problem on HackerRank using Scala. I've been given a set of grammar rules and have to implement the actual interpreter underlying it. I've decided to approach ...
57
votes
4answers
7k views

Is functional programming faster in multithreading because I write things differently or because things are compiled differently?

I'm diving into the world of functional programming and I keep reading everywhere that functional languages are better for multithreading/multicore programs. I understand how functional languages do a ...
0
votes
1answer
47 views

Determine execution order based on declarative definition?

We want to create a DSL in Scala where you can declaratively list the ingredients that a product consist of. These ingredients can consist of for example "Create product a", "Create product b", "Send ...
2
votes
1answer
52 views

When to use Future[T] vs. Future[Try[T]] when the call might fail

I am slightly confused when to use which because futures are allowed to fail. If futures are allowed to fail, then to me, that sounds like a Try[] in itself. And if the Try[] is wrapped inside a ...
52
votes
3answers
8k views

What are the biggest differences between F# and Scala?

F# and Scala are both functional programming langugages that don't force the developer to only use immutable datatypes. They both have support for objects, can use libraries written in other languages ...
37
votes
4answers
13k views

When is it NOT good to use actors in akka/erlang?

I've been working with akka for 7-8 months now daily. When I started, I would be working on applications and notice that actors would be used basically anywhere once inside the actor system for ...
4
votes
1answer
53 views

What is the best pattern to define own type with definitive collection of values?

I want to define own data type, say a Digit, which would have definite type of values ( 0 to 9 ) and I'm struggling with defining this in a way it's practical. What's the best way (design pattern) to ...
0
votes
0answers
101 views

SQL/HQL in a Play framework controller and Service Layer pattern

I started using the Play Framework a couple of months ago. It "redefines" many conventions from the traditional Java world (like the way of using static methods among other things). I was browsing the ...
5
votes
3answers
226 views

Should databases be viewed as Monads?

Because any kind of persistence updates/inserts/deletes represents in some sense a kind of state change in a database, it makes me wonder whether databases can be considered monads. We say the same ...
24
votes
8answers
4k views

Using a “strong” type system in the real world, say, for large-scale web-apps?

I know this is a very broad, ambiguous, and possibly philosophical question. To an extent, that the most important keyword in the question - "strong" type system - itself, is ill-defined. So, let me ...
2
votes
1answer
94 views

How to represent data objects gradually getting augmented in a pipeline [closed]

I'm working on a Scala data-processing program. Essentially we start with a collection of many small data objects, say, (eventId: String, basicInfo: Basic) and gradually filter out some objects and ...
1
vote
1answer
142 views

Why use tuples as function parameters in languages that support currying?

In languages that support currying, I can't think of many cases where using a tuple as function input parameters would be better than breaking the tuple apart into multiple parameters, which then ...
-1
votes
1answer
124 views

What is the session about simplicity that Martin Odersky suggested during the “Scala with style” talk? [closed]

The video of Scala with style is here: http://parleys.com/play/51c1994ae4b0d38b54f4621b/chapter21/about It's around 41:10 that he suggested another talk. I can not hear the name of speaker or the ...
1
vote
2answers
227 views

Why does Scala name monadic composition as “for comprehension”?

Not sure if it's an appropriate question, but here it goes. I know Haskell's do notation pretty well. And I realized that Scala's "for comprehension" really is just mostly the same as do notation in ...
6
votes
1answer
310 views

Is it good practice to use NoStackTrace in scala?

I came across the NoStackTrace mixin for Exceptions in scala. Is it good practice to use it, or should it be considered "internal" to scala and left alone?
23
votes
9answers
17k views

Why was Scala not implemented with C or C++

Does anybody know why was Scala implemented in Java and .NET instead of C or C++? Most languages are implemented with Cor C++ [i.e Erlang, Python, PHP, Ruby, Perl]. What are the advantages for Scala ...
2
votes
2answers
167 views

Why does an immutable object in Scala need less memory than a mutable one?

In Programming in Scala, there is this statement: For instance an empty mutable map in its default representation of HashMap takes up about 80 bytes and about 16 more are added for each entry that’...
1
vote
1answer
86 views

Scala, checking for type and then cast to it

I have sometimes the usecase that I need to check if a variable is of a specific type and if so cast to it to access a property/function of it. Example: if (state.isInstanceOf[StateA] && ...
0
votes
1answer
839 views

akka and futures, which ExecutionContext should be used

Following this blog by @Tomasz Nurkiewicz we can see that 4 different approaches are available for picking the ExecutionContext, when interacting with akka actors, for scala futures to run on. import ...
5
votes
1answer
76 views

Why would you document a return type using scaladoc?

The following is snippet of an example from page 240 of the book Programming Scala (Wampler & Payne, 2009; O'Reilly Media): /** @return Parser[Money] */ def deductItem = deductKind ~> ...
1
vote
2answers
362 views

best practices for packaging in Scala projects?

Scala runs on the JVM, but that doesn't mean we have to write it like Java. Eclipse discourages use of the default package. What are some considerations (e.g. size of project) that determine how ...
19
votes
3answers
6k views

Why would I not need an ORM in a functional language like Scala?

I'm wondering if I can switch from Java to Scala in a Spring + Hibernate project to take advantage of some Scala features such as pattern matching, Option and what it seems to me a cleaner syntax in ...
1
vote
1answer
96 views

Scala: DSL for repetitive algroritms

So, very often in your code you have statements/algorithms like this one: if (!myCollection.contains(unit)) throw new IllegalArgumentException(s"$unit is not available") The issue which I have ...
25
votes
5answers
2k views

Could an instance be equal to some other instance of a more specific type?

I've read this article: How to Write an Equality Method in Java. Basically, it provides a solution for an equals() method that supports inheritance: Point2D twoD = new Point2D(10, 20); Point3D ...
42
votes
7answers
7k views

How do you encode Algebraic Data Types in a C#- or Java-like language?

There are some problems which are easily solved by Algebraic Data Types, for example a List type can be very succinctly expressed as: data ConsList a = Empty | ConsCell a (ConsList a) consmap f ...
3
votes
1answer
99 views

Including a library to use one function / utility classes

At my place of employment I have noticed a weird thing where developers will include largish libraries to do simple things. To be clear we're a Scala shop. Here are two examples that occured : 1) In ...
0
votes
0answers
67 views

Add-on hot deployable modules for Akka actors?

I'm trying to build a small spray io - akka distributed application targeted towards smaller devices like the Raspberry Pi and BeagleBone Black. The aim is to be able to talk to other devices that ...
1
vote
1answer
222 views

Best way to separate public API from internal implementation [closed]

I'm developing a little framework (in Scala) where I want to define clean and simple interface for the users of the framework. Some of theses interfaces have to be implemented by the framework itself, ...
3
votes
2answers
226 views

How to use scala case classes when delegation is needed

Let's assume in our application we want to model cars. We also want to model a car repository where we store some registered cars. How should that be modeled in scala? Here comes my approach: First, ...
10
votes
2answers
2k views

Why is the Scala Option type not called Maybe, just as in Haskell? [closed]

Why is the Scala Option type not called Maybe, just as in Haskell? Maybe makes a lot more "semantic sense" to me, but maybe Option has different behaviour I am not aware of. Is there any particular ...
10
votes
3answers
3k views

Decision for Unchecked Exceptions in Scala

As a java programmer, I have always been critical of Unchecked Exceptions. Mostly programmers use it as an en-route to coding easiness only to create trouble later. Also the programs (though untidy) ...
3
votes
2answers
1k views

Why Java does not have a framework like Rails? [closed]

I am a Ruby on Rails developer and I like its simplicity and rapidness. On the other hand we need to use Java for some projects that we develop for our clients. My question is why (pure) Java does ...
2
votes
1answer
56 views

Transform Either types in Scala

I have an Either type e.g. Either[A, B] but I want an Either[X, Y] by using two functions A => X and B => Y. I can do that with fold: val myEither: Either[A, B] = ... myEither.fold( a => ...
1
vote
1answer
75 views

Send signal to a scala process

I have a cron job running that is a Scala application. I want another job, that runs forever, to do something when this one finishes. It seems to me some kind of signal (Unix/Linux signal?) has to be ...
1
vote
1answer
489 views

Polyglot Node.js with Typesafe Akka for Actor Model

I have a case that needs to manipulate a large stream of JSON and inject it into Apache HBase. Our system works on Node.js with Mongo then, since we need to enhance performance, so HBase is choosen to ...
1
vote
3answers
236 views

Why does scala require parenthesis around the condition of an if statement

Just curious, from a syntax parsing perspective, why does Scala actually require parentheses around the condition of an if statement, given that the only thing allowed after if is (?
34
votes
3answers
13k views

What are the advantages of Scala's companion objects vs static methods?

Scala has no static-keyword, but instead has similar functionality through companion objects. Behind the scenes the companion objects are compiled to classes that have static methods, so all this is ...
52
votes
5answers
19k views

What is the difference between a Future and a Promise?

What is the difference between a Future and a promise? (In Akka and Gpars.) They look the same to me as both block and return the value of the future when get is called and a promise is to get the ...
24
votes
6answers
5k views

Why these attempts to water down Scala with Xtend and Kotlin? [closed]

So now Eclipse has offered Xtend and JetBrains is offering Kotlin - both of which seem to be watered down versions of Scala. My question is why? I've played with Scala a bit and it's not that hard. ...
5
votes
1answer
159 views

Use StringLike instead of String in Scala?

Scala has the StringLike trait. Let's say I want to create a case class Name and internally it should save the name with some characters. Should I use case class Name(name: StringLike) or case class ...
2
votes
1answer
78 views

Is there a way to make the default way a class is accessed a field within the class?

I'm trying to write a wrapper for the following bit of scala code: val vertBuffer: FloatBuffer = createFloatBuffer(vertex_positions.length) vertBuffer.put(vertex_positions) vertBuffer.flip() ...