Hot answers tagged

86

The reason people say functional languages are better for parallel processing is due to the fact that they usually avoid mutable state. Mutable state is the "root of all evil" in the context of parallel processing; they make it really easy to run into race conditions when they are shared between concurrent processes. The solution to the race conditions then ...


70

This should not be equality because it breaks transitivity. Consider these two expressions: new Point3D(10, 20, 50).equals(new Point2D(10, 20)) // true new Point2D(10, 20).equals(new Point3D(10, 20, 60)) // true Since equality is transitive, this should mean that the following expression is also true: new Point3D(10, 20, 50).equals(new Point3D(10, 20, ...


57

It's because it's important for humans to recognize that functions are not just "another named entity". Sometimes it makes sense to manipulate them as such, but they are still able to be recognized at a glance. It doesn't really matter what the computer thinks about the syntax, as an incomprehensible blob of characters is fine for a machine to interpret, ...


56

Major Differences: Both Scala and F# combine OO-imperative programming and functional programming into one language. Their approach towards unification of paradigms is vastly different though. Scala tries to fuse the two paradigms into one (we call it object-functional paradigm), whereas F# provides the two paradigms side by side. For example, algebraic ...


44

I think the reason is that most popular languages either come from or were influenced by the C family of languages as opposed to functional languages and their root, the lambda calculus. And in these languages, functions are not just another value: In C++, C# and Java, you can overload functions: you can have two functions with the same name, but ...


43

The question is confusing, as C and C++ are languages, while JVM is a virtual machine and .Net is a platform. Scala could be implemented in C or C++, and it could generate machine code instead of bytecode for a virtual machine. Answering the question that was asked: Scala was not implemented in C or C++ because Scala, the language in which it is actually ...


39

Here are a few reasons, which might be more or less compelling for you, depending on your own preferences: Do not simply discount it for being "syntactic sugar". While you may say that something is just syntactic sugar, it is after all the sugar that sweetens your life - as a programmer just as well as a coffee or tea drinker. Singletons - every Scala ...


38

I'll talk about Akka/Scala, because I'm not familiar with Gpars nor with Akka/Java. In Scala 2.10, which includes the relevant part of Akka in the standard distribution, a Future is essentially a read-only reference to a yet-to-be-computed value. A Promise is a pretty much the same except that you can write to it as well. In other words, you can read from ...


35

This has nothing to do with functional programming - you can find this kind of situation in context of any other programming language - developers who love the advanced constructs of "their" language so much that they ignore any common sense about readability and keeping things simple. I have encountered such a situation in C, C++, Perl, Java, C#, Basic, and ...


33

There is an easy, but boilerplate heavy way to seal classes in Java. You put a private constructor in the base class then make subclasses inner classes of it. public abstract class List<A> { // private constructor is uncallable by any sublclasses except inner classes private List() { } public static final class Nil<A> extends ...


32

IMHO from somebody programming in Java for the last 7 years and being my strongest language, I find Scala quite alien and am having a hard time getting used to it. Xtend feels more like Java and was able to write a simple application with it much quicker. Granted I didn't give myself enough time with Scala, but I certainly understand why some may be turned ...


32

There's one thing that you can do concisely and efficiently in Java that you can't in Scala: enumerations. For everything else, even for constructs that are slow in Scala's library, you can get efficient versions working in Scala. So, for the most part, you don't need to add Java to your code. Even for code that uses enumeration in Java, there's often a ...


28

Memory management is utterly relevant since it governs how fast something appears even if that something has a great deal of memory. The best and most canonical example are AAA-title games like Call of Duty or Bioshock. These are effectively real-time applications that require massive amounts of control in terms of optimization and usage. It's not the usage ...


27

One of the big hurdles languages face when being introduced to the world at large is library availability. The traditional response to this has been to provide a C-based FFI (foreign function interface) to permit you access to C-based libraries. This is not ideal for a variety of reasons, chief among them: There's a lot of different ways that libraries ...


27

"All" programming languages run on x86, so how can they be much different from each other? Brainfuck and Haskell are both Turing complete, so they can both do the exact same tasks. There's a bit of room for syntax changes, syntax sugar and compiler magic in between. You can do quite a lot in there, but there is always a limit. In your case, it's JVM byte ...


26

The real brick was the memory allocation - at worst, Java allocated a whopping 52x more memory than C, and 25x more than C++. Do you understand the numbers you base your question upon? How much memory was allocated? What were the programs doing? When there's a big disparity between those Java and C programs, it's mostly the default JVM memory ...


26

I'll give a short answer due to my lack of time at the moment, but I'm currently working on two big projects (> 100.000 LOC in Haskell) - flowbox.io and luna-lang.org. We use Haskell for all the parts, including the backend, compiler of our programming language and even the webGL based GUI. I have to admit that the strong type system and the "dependent ...


24

In Scala, the * is a valid identifier. One could write: val * = "trollin'" println(*) With the result being: trollin' One could write a class named * as such: class * { def test():String = { "trollin'" } } So with that being the case, when I have a class * in the package us.hexcoder and I write: import us.hexcoder.* You would be saying ...


23

All programming is related to mathematics. Indeed many universities still place their computer science programs under the purview of the mathematics department. As for learning functional programming, you do not need to have a strong base in mathematics to learn it. I've learnt three different functional languages now to reasonable proficiency (Haskell, ...


23

Now, I don't know much about Clojure and little about Scala, but I'll give it a shot. First off, we need to differentiate between tail-CALLs and tail-RECURSION. Tail recursion is indeed rather easy to transform into a loop. With tail calls, it's much harder to impossible in the general case. You need to know what is being called, but with polymorphism ...


23

According the Great Benchmarks Game, ATS is faster than the rest with Haskell, Scala, and one of the variants of Common Lisp in a rough tie for speed close behind that. After that Ocaml and F# are in roughly the same speed category with Racket and Clojure lagging behind... However, almost none of this means anything at all really. It's all a question of ...


22

I can advise Programming in Scala because it's from the creator of the Scala language: Martin Odersky. He describes most of the features of Scala very detailedly and explains, why he chose this feature instead of an other one. Therefore, the reader gets a deep insight into Scala. The book is fantastic. It is one of the best programming books I've ever ...


22

Well, one thing that's important to do whenever we have a discussion like this is to clearly distinguish between object relational mappers ("ORM") and database abstraction layers. An ORM is a kind of database abstraction layer, but not all database abstraction layers are ORMs. One good tool to study to grasp this is Python's popular SQLAlchemy library, ...


21

While it is true that Scala has been used in the wild at the Guardian and at Twitter, there is one fundamental concern. Much of Java's popularity comes from the fact that it is relatively easy to read and maintain. Scala has an problem here as it can be written in many different styles. OO style vs functional style is the obvious split here, but it gets ...


21

What Odersky says is (Slide 11, http://www.slideshare.net/rawwell/scalaliftoff2009pdf): "Scala is deep where other languages are broad." This means, scalable is meant in terms of flexibility and expressiveness. You can create your own control structures. E.g. the actors frameworks is a library, but it looks like it uses language features. This means ...


21

One more benefit is that objects can implement interfaces/traits, unlike static methods.


21

Subtyping and inheritance are two different things! Nothing doesn't extend everything, it's a subtype, it only extends Any. The specification[§3.5.2] has a special case governing the subtyping-relationship of Nothing: §3.5.2 Conformance [...] For every value type T , scala.Nothing <: T <:scala.Any For every type constructor T (with ...


20

Well, I think Scala is too complex. It feels like C++ in that it has a myriad of different ways of doing things. Some would call this "richness", "expressiveness" or "power", but your mileage may vary. In many real world projects you would have to artificially limit what language features you're going to use and what not, so that all developers involved ...


20

I don't think Groovy is going to disappear, it is a self sustained entity now. Grails framework is built around Groovy language, which it is a good reason to stay alive. Groovy got its killer application. I'm not saying Grails is the only vital Groovy project, Gradle is also pretty good. GORM is really handy. Gant is a nice improvement over Ant. Not ...


20

According to the Benchmarks Game for a single core, 32 bit system, Scala is at a median 80% as fast as Java. The performance is approximately the same for a Quad Core x64 computer. Even memory usage and code density are very similar in most cases. I would say based on these (rather unscientific) analyses that you are correct in asserting that Scala adds some ...



Only top voted, non community-wiki answers of a minimum length are eligible