Why aren’t static methods considered good OO practice? [closed]

Object-orientation is about three things: messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things. Of those three, the most important one is messaging. Static methods violate at least messaging and late-binding. The idea of messaging means that in OO, computation is performed by networks of self-contained objects which send … Read more

Is it possible to have tuple assignment to variables in Scala? [duplicate]

This isn’t simply “multiple variable assignment”, it’s fully-featured pattern matching! So the following are all valid: val (a, b) = (1, 2) val Array(a, b) = Array(1, 2) val h :: t = List(1, 2) val List(a, Some(b)) = List(1, Option(2)) This is the way that pattern matching works, it’ll de-construct something into smaller parts, … Read more

The type system in Scala is Turing complete. Proof? Example? Benefits?

There is a blog post somewhere with a type-level implementation of the SKI combinator calculus, which is known to be Turing-complete. Turing-complete type systems have basically the same benefits and drawbacks that Turing-complete languages have: you can do anything, but you can prove very little. In particular, you cannot prove that you will actually eventually … Read more

In Scala, how can I subclass a Java class with multiple constructors?

It’s easy to forget that a trait may extend a class. If you use a trait, you can postpone the decision of which constructor to call, like this: trait Extended extends Base { … } object Extended { def apply(arg1: Int) = new Base(arg1) with Extended def apply(arg2: String) = new Base(arg2) with Extended def … Read more

Scala Sets contain the same elements, but sameElements() returns false

The Scala collections library provides specialised implementations for Sets of fewer than 5 values (see the source). The iterators for these implementations return elements in the order in which they were added, rather than the consistent, hash-based ordering used for larger Sets. Furthermore, sameElements (scaladoc) is defined on Iterables (it is implemented in IterableLike – … Read more

What is the differences between Int and Integer in Scala?

“What are the differences between Integer and Int?” Integer is just an alias for java.lang.Integer. Int is the Scala integer with the extra capabilities. Looking in Predef.scala you can see this the alias: /** @deprecated use <code>java.lang.Integer</code> instead */ @deprecated type Integer = java.lang.Integer However, there is an implicit conversion from Int to java.lang.Integer if … Read more

tech