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

0
votes
1answer
26 views

Scala and exception handling

I am curious why exception handling is a topic often ignored in Scala. Is it the goal of the language (or the style) to not rely on exception handling except for external input/code? I was hoping ...
8
votes
2answers
300 views

Why can't the Scala compiler give pattern matching warning for nonsealed classes/traits?

If I use an unsealed trait or abstract class in Scala and then use pattern matching, I wonder, does the compiler not know at compile time for this particular patternmatch what possible implementations ...
7
votes
1answer
82 views

Why are Scala's Either and Option types not interfaces/traits but classes?

I wanted to create a class CompileResult, that can be treated like an Either type but has some additional useful methods. It should be a CompileSuccess or a CompileFailure (which, too, has some ...
2
votes
0answers
38 views

Is there a way shortcut type bounds in Scala? [migrated]

When defining a covariant class, all the method declarations need to contain something along the lines of: [B >: A] //A is the main type variable Is there a way to declare something at the class ...
0
votes
1answer
27 views

Actors in a sequential protocol handshake

I am new to actors and trying to implement a very sequential protocol handshake (over websockets). This is in Scala/Akka. It goes something like this: HTTPs connection is established then upgraded ...
1
vote
2answers
50 views

Scala infix notation

Is it possible to call a method using infix notation? For example, in Haskell, I could write the following fucntion: x `isAFactorOf` y = x % y == 0 and then use it like: if 2 `isAFactorOf` 10 ... ...
3
votes
2answers
78 views

What's the rationale behind the ordering of Scala's value/variable declaration when including a type identifier?

I'm trying to wrap my head around Scala, and one thing that keeps throwing me is the ordering of a variable/value declaration when specifying the type. val a = 0 makes perfect sense. This looks ...
0
votes
1answer
49 views

in scala type linearization explain first step in algorithm [closed]

I saw this explanation Where first step is: "start building a list of types, the first element is the type we’re linearizing right now," however the result of this is: // start with D1: B ...
7
votes
1answer
419 views

Why does Scala have return but not break and continue

Scala does not have break or continue, so some loop behavior takes a bit more of thinking. Ending a loop early requires tail recursion, exceptions, or scala.util.control.Breaks (which uses ...
1
vote
1answer
139 views

What was the influence of Chris Okasaki's data structures on Scala? [closed]

I heard a friend say: The first real use of Chris Okasaki's book was in Clojure's data structures I heard another friend say: No, they influenced the design of Scala in quite a subtle way. ...
2
votes
2answers
102 views

Is it possible to have Ad-Hoc polymorphism with runtime dispatch?

As I did understand, and as it's described here, ad-hoc polymorphism is limited to compile-time dispatch. That is, if we have a function that expects an argument that belongs to a typeclass, we must ...
0
votes
0answers
48 views

Controllers passing Request objects to backend logic that forward Request data: Good or Bad?

Currently working on a server-side front-end Scala Play app that does a lot of grabbing of HTML snippets and JSON from many other web apps before piecing everything together and sending it in a ...
0
votes
0answers
44 views

Is there a pattern for deserialization involving repository access? Or what is wrong with my design?

Let us have case class Money(amount: BigDecimal, currency: Currency) case class Currency(code: String, alpha3: String) Money is a value object and Currency is an entity. When transforming Money to ...
1
vote
3answers
190 views

Help me to understand 'stateless' software in functional programming

I'm an experienced software engineer, and have experience in a range of languages from PHP, Ruby, C#, Java - the last few years I've primarily worked in Java. I'm now learning Scala, and it's my ...
35
votes
12answers
4k views

Why do most programming languages have special keyword or syntax for declaring functions? [closed]

Most programming languages (both dynamically and statically typed languages) have special keyword and/or syntax that looks much different than declaring variables for declaring functions. I see ...
8
votes
3answers
1k views

What is a “lifted representation”?

Just ran across this term here: http://www.codemesh.io/codemesh2014/viktor-klang "We'll demonstrate the Flow API—a lifted representation—as well as a pluggable way of transforming the lifted ...
0
votes
0answers
107 views

ZeroMQ and Majordomo protocol

I am learning ZeroMQ and came across the Majordomo Protocol. I am wondering if I'm understanding this correctly, is the use case the same as.. for example.. the Microsoft Azure AppFabric service? ...
2
votes
3answers
199 views

Is 'design with types first' ultimately the same as 'design with interfaces first'?

In Object Oriented Programming, we're taught to think in terms of Polymorphism (the idea that the implementation is decoupled from the interface - and that it makes sense to think of the interface ...
0
votes
1answer
35 views

Where to put sample data in project structure

I am working on a Scala project and I want to include some sample data somewhere in the project. Specifically, my Scala project includes code that performs various natural language processing tasks ...
0
votes
2answers
65 views

Map multiple functions over a single data item [closed]

I'm in the process of learning Scala and I came across a scenario today where I need to map multiple functions over a single piece of data and wondered if there was a formal name for this. It sort of ...
1
vote
2answers
164 views

If there's no problem treating a statement as an expression, why was there a distinction in the first place in some programming languages? [duplicate]

Why do we have the distinction between statements and expressions in most programming languages? For example, in Java, assuming f and g return ints, this still won't compile because it's a statement ...
2
votes
1answer
62 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?
2
votes
2answers
192 views

Java: method takes varargs of unrelated types

I have a Java factory method with a varargs array of Objects at the end. The array can contain any combination of Strings and ScaledJpegs. The theory being that an HTML table cell can contain any ...
5
votes
1answer
64 views

Coping with build order requirements in automated builds

I have three Scala packages being built as separate sbt projects in separate repos with a dependency graph like this: M---->D ^ ^ | | +--+--+ ^ | S S is a service. ...
1
vote
5answers
186 views

Many Arguments in Case Classes [closed]

I have generally read that having many (>4) arguments to a function/constructor is a bad practice. Is this still considered a bad practice? And is there a non-obvious reason? In something like a ...
3
votes
1answer
134 views

When to declare @throws with a Scala annotation - abstract parent or concrete implementation?

In this StackOverflow question I asked about the behavior of the @throws annotation in Scala. Now that I understand how it works I want to ask about best practices with using it. Here's a repost of my ...
0
votes
2answers
123 views

SOAP message testing

I am working in Scala/Java. I'm testing the messaging infrastructure of a part of my system that I did several years ago with CXF and Java. More specifically, I'm re-writing the specification of the ...
3
votes
1answer
85 views

Why is subclassing TraversableOnce not recommended

Reading http://www.scala-lang.org/api/2.11.1/index.html#scala.collection.TraversableOnce: Directly subclassing TraversableOnce is not recommended - instead, consider declaring an Iterator with a ...
8
votes
3answers
988 views

Is duplicate syntax for defining named functions a bad language design decision?

I am modelling a programming language for fun, and the syntax is heavily influenced by Scala - specifically function definitions. I have encountered a design problem because my language does not ...
-1
votes
1answer
77 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
1answer
304 views

Should we push for more JavaScript on the JVM, alongside Java and Scala? Or, if not, why?

With JavaScript becoming one of the most widely used languages around, I began asking myself why people do not find ways to use it extensively on the JVM. As a programmer who spends half day writing ...
1
vote
1answer
191 views

Type Safety of Spray.io

Yesterday I read a tweet disparaging Jersey with JAX-RS due to run-time errors. Spray.io was mentioned in the tweet: Not even 5 minutes using Jersey / JAX-RS and already a runtime error due to a ...
5
votes
3answers
226 views

Decreasing vars in Scala programs

I have been studying scala for the past week or so and the ideologies associated with it and functional programming in general. As expected, the leap from imperative to functional programming is not ...
1
vote
4answers
302 views

Alternatives to null values and option-like types

Related to this question i want to know if there is a concise way to eleminate null values out of code in general or if there is not. E.g. imagine a class that represents a user with birthday as ...
2
votes
2answers
411 views

How do Traits in Scala avoid the “diamond error”?

(Note: I used 'error' instead of 'problem' in the title for obvious reasons.. ;) ). I did some basic reading on Traits in Scala. They're similar to Interfaces in Java or C#, but they do allow for ...
6
votes
1answer
1k views

Pattern matching in Clojure vs Scala

What are the key differences between pattern matching in these two languages? I am not referring to syntax, but capability, implementation details, range of use cases and necessity. Scala ...
0
votes
2answers
159 views

Parameterless & Empty-Paren methods in Scala

I'm learning Scala at the moment via Odersky's Programming Scala (2nd). I'm upto chapter 10 where he starts introducing parameterless and empty-paren methods. I just can't get my head around it. So ...
13
votes
4answers
2k views

Does functional programming add complexity in code? [closed]

For the entire past year I've been written Scala code (coming from a Java background). I really liked how you could create simpler and cleaner code, with vals, case classes, map/filter/lambda ...
0
votes
1answer
70 views

Preferred Scala code style for several embedded brace sets

I was wondering the correct way to format a situation such as this, where I have a def, a foreach and an if clause all nested, requiring braces. Currently I find it hard to read, and there is no ...
6
votes
1answer
386 views

Passing a Scala function to a Java 8 method

The following Scala code works and can be passed to a Java method expecting a function. Is there a cleaner way to do this? Here's my first pass: val plusOne = new ...
5
votes
5answers
1k views

What negative consequences can arise from this language design rule?

Clarification: the rule is meant to prevent accessing variables that are not declared yet. Clarification 2: the rule mandates that the compiler follows calls to functions which are defined in the ...
1
vote
1answer
2k views

JSON Library - Jackson or Play Framework? [closed]

Working on a Java and Scala code-base, there's a debate about whether to use Java's Jackson JSON or the Play Framework's JSON Library. After reading the Play JSON Docs, as well as Chapter 9 (JSON) of ...
3
votes
1answer
113 views

Understanding special Scala syntax

I can understand this: List("one word", "another word") unzip (_ span (_ != ' ')) But don't get what's happening here below in the span. span takes a predicate and I think the braces can be omitted ...
3
votes
2answers
1k views

Learning Scala, feeling discouraged [closed]

I'm coming from a Java background and trying to learn Scala. At the moment I'm feeling pretty overwhelmed, there seems to be so much more to learn with Scala, so many different ways of doing the same ...
0
votes
1answer
181 views

Scala class with constructor requiring parameter of the same Class type

I can't remember but recently in one of the APIs I saw something like this class A (member:A){}. Scala does support it and there is no problem creating such a class but how do we initiate it and what ...
2
votes
6answers
504 views

How do you move beyond code examples without a project?

I am currently learning Scala and I find a mental blog of how to proceed to a degree where I can use Scala daily beyond the normal examples. I just do not have a particular project in mind of what I ...
1
vote
2answers
250 views

Is short-circuit evaluation a consequence of call-by-name?

If the boolean operators &&, || are implemented as infix methods, then isn't short-circuit evaluation just a consequence of being implemented using call-by-name semantics, since, for example, ...
7
votes
3answers
3k views

Why Big Data Needs To Be Functional?

I started working on a new project lately related to Big Data for my internship. My managers recommended to start learning functional programming (They highly recommended Scala). I had a humbled ...
0
votes
1answer
561 views

Why the Scala fascination with flatmap? (This doesn't seem to be the same for mapcat in the Clojure world) [closed]

In the Scala community - there is an apparent fascination with the FlatMap function. Now I understand that FlatMap is significant because it is used for the bind part of a Monad. (and that the ...
7
votes
2answers
944 views

What is the difference between self-types and trait inheritance in Scala?

When Googled, many responses for this topic come up. However, I don't feel like any of them do a good job of illustrating the difference between these two features. So I'd like to try one more time, ...