Questions tagged [scala]
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.
240 questions
23
votes
2
answers
15k
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 exceptions)...
1
vote
1
answer
826
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.
My ...
2
votes
2
answers
2k
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
0
answers
1k
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
0
answers
81
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 ...
4
votes
3
answers
4k
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 ...
41
votes
12
answers
9k
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 ...
12
votes
3
answers
5k
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 ...
3
votes
0
answers
1k
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? ...
3
votes
3
answers
476
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 ...
1
vote
1
answer
788
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 ...
1
vote
2
answers
217
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 ...
15
votes
1
answer
3k
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
2
answers
611
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
1
answer
160
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. M ...
5
votes
5
answers
3k
views
I have generally read that having many (>4) arguments to a function/constructor is a bad practice. Is this still considered a bad practice? [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 ...
8
votes
1
answer
3k
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 ...
2
votes
2
answers
678
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
1
answer
457
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 ...
9
votes
3
answers
1k
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
1
answer
248
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 ...
0
votes
1
answer
403
views
Should we push for more JavaScript on the JVM, alongside Java and Scala? Or, if not, why? [closed]
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
1
answer
402
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 ...
6
votes
3
answers
2k
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
4
answers
4k
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 ...
20
votes
2
answers
20k
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 ...
12
votes
1
answer
8k
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 ...
12
votes
2
answers
5k
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 ...
18
votes
4
answers
3k
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
1
answer
159
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 ...
20
votes
1
answer
14k
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 java.util.function.Function[Int,...
6
votes
5
answers
2k
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 ...
3
votes
1
answer
6k
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
1
answer
167
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 ...
9
votes
2
answers
6k
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
1
answer
479
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
6
answers
687
views
How do you move beyond code examples without a project? [closed]
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
2
answers
2k
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, ...
11
votes
4
answers
11k
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 ...
3
votes
1
answer
2k
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 ...
9
votes
2
answers
4k
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, ...
15
votes
1
answer
5k
views
Why does appending to a List in Scala have O(n) time complexity?
I just read that the execution time of the append operation for a List (:+) grows linearly with the size of the List.
Appending to a List seems like a pretty common operation. Why should the ...
5
votes
2
answers
3k
views
Is there a representation for mixins or traits on UML?
Is there a representation for modern programming constructs that are becoming common in modern OOP/hybrid languages like mixins/traits/categories/partial classes ?
5
votes
1
answer
493
views
What kind of problems is an Android beginner likely to encounter in using Scala?
I am a hobbyist programmer who makes and maintains one production system, largely coded in Python, which now has to be ported to Android. I don't know Java at all. However, SL4A in Android makes ...
68
votes
5
answers
28k
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 ...
7
votes
2
answers
6k
views
How to name nested function? [closed]
When you have a function that wraps another one in Scala. What do you call the nested function?
I found this :
def factorial(i: Int): Int = {
def fact(i: Int, accumulator: Int): Int = {
if (...
3
votes
3
answers
2k
views
Does macros support make Scala a Lisp dialect?
I've read recently that macro support in Scala is now official. I checked the documentation page and they are reminiscent to the LISP ones. In one of his essays Paul Graham writes that when "you add ...
2
votes
4
answers
340
views
How to promote Scala to the management?
As a developer I like Scala and could tell the management about technical benefits of the language. But even if management understands that a superior technology has business impact, I fear that they ...
4
votes
4
answers
491
views
Big switching from one platform to another [closed]
As an example I want to switch from C#/.NET to Scala/Jvm. I'm working as a self-employed and I'm free to choose my favorite language/platform. Having more than 8 years of experience in C#/.NET leads ...
15
votes
2
answers
7k
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 ...