News for hackers. Stuff that matters.
Re:In Defense of Scala. Response to “I Don’t Like Scala” by kasey_junk on Wednesday January 29, 2014 @09:25AM (#7143955)
"For sane type-level programming look at latest Scala collections"

Is this a joke? The Scala collections library are terrible. They are inconsistent, hard to reason about, suffer from scope creep, and have terrible performance characteristics.

Re:In Defense of Scala. Response to “I Don’t Like Scala” by octo_t on Wednesday January 29, 2014 @09:36AM (#7144000)
Every time I've used Scala collections, they've behaved exactly how I'd expect them to. What parts of the collections perform poorly?
Re:In Defense of Scala. Response to “I Don’t Like Scala” by kasey_junk on Wednesday January 29, 2014 @09:51AM (#7144110)
The scala collections (even the mutable ones) generate tons of garbage (e.g. getting a value out of a map automatically creates another new object). Scala hashmaps (even the mutable ones) are much slower than equivalent java collections.
Re:In Defense of Scala. Response to “I Don’t Like Scala” by sukaka on Wednesday January 29, 2014 @09:57AM (#7144150)
A recent comparison was made with scala and java collections. Lots of interesting tidbits. http://www.takipioncode.com/2014/01/23/java-scala-guava-and-...
Re:In Defense of Scala. Response to “I Don’t Like Scala” by thescrewdriver on Wednesday January 29, 2014 @09:54AM (#7144124)
It seems that the performance difference has little to do with temporary objects, but is to be fixed 2.11 anyway: https://groups.google.com/forum/#!msg/scala-internals/Fw37Nm...
Re:In Defense of Scala. Response to “I Don’t Like Scala” by ionforce on Wednesday January 29, 2014 @10:23AM (#7144322)
> getting a value out of a map automatically creates another new object

Do you have a code sample for this?

Re:In Defense of Scala. Response to “I Don’t Like Scala” by kasey_junk on Wednesday January 29, 2014 @10:30AM (#7144377)
From MapLike.scala

def apply(key: A): B = get(key) match { case None => default(key) case Some(value) => value }

From HashMap.scala

def get(key: A): Option[B] = { val e = findEntry(key) if (e eq null) None else Some(e.value) }

Re:In Defense of Scala. Response to “I Don’t Like Scala” by azth on Wednesday January 29, 2014 @06:51PM (#7148046)
Out of curiosity, how would you rather have them be implemented? You either return an Option, or you will have to deal with null pointers.
Re:In Defense of Scala. Response to “I Don’t Like Scala” by kasey_junk on Wednesday January 29, 2014 @10:30PM (#7148910)
Not sure how familiar you are with the Scala syntax, but that code actually has null pointer problems. The apply function turns Options into null pointers. They've given me the worst of both worlds, not only do I get null pointers, I get to have extra garbage created to accomplish it.
Re:In Defense of Scala. Response to “I Don’t Like Scala” by azth on Thursday January 30, 2014 @04:05PM (#7153358)
Yep I get that point. However, how would you avoid extra allocations and maintain safety (no nulls)?
Re:In Defense of Scala. Response to “I Don’t Like Scala” by kasey_junk on Thursday January 30, 2014 @10:43PM (#7155110)
I actually have no problem with the extra allocations if they maintain safety (that's not quite true, I actually need to break safety occasionally).

The problem is that the incoherent design of the collections library means that it is not clear to the programmers of the default mutable hash map lookup what they are striving for.

If they were striving for performance they would use a model that allowed for NPE against safety, that had allocation semantics that were sensible. Conversely, if safety was the overriding concern they wouldn't allow for the NPE.

Instead, in one of the most central data structures of the language we get unreasonable behavior. This is clearly a sign of bad design, thus reputing the original assertion that the Scala collections library were a good example of type programming.

PS: To trivially answer your question, they should have inverted the implementation here. A NPE throwing method for lookup wrapped with option sugar would make way more sense than the inverse.

Re:In Defense of Scala. Response to “I Don’t Like Scala” by azth on Saturday February 01, 2014 @01:58PM (#7162838)
Makes sense, thanks for your answer :)
Re:In Defense of Scala. Response to “I Don’t Like Scala” by dk8996 on Wednesday January 29, 2014 @10:03AM (#7144189)
I hate to call you out on this but look at the collection hierarchy and tell me its not complex.

http://docs.scala-lang.org/resources/images/collections.muta...

Re:In Defense of Scala. Response to “I Don’t Like Scala” by thescrewdriver on Wednesday January 29, 2014 @10:07AM (#7144210)
Doesn't look very different from the equivalent diagram for Java. Have you seen how many different collection classes and interfaces there are in the Java standard libs?

    AbstractCollection
    AbstractList
    AbstractMap
    AbstractMap.SimpleEntry
    AbstractMap.SimpleImmutableEntry
    AbstractQueue
    AbstractSequentialList
    AbstractSet
    ArrayDeque
    ArrayList
    Arrays
    BitSet
    Collections    
    Dictionary
    EnumMap
    EnumSet
    HashMap
    HashSet
    Hashtable
    IdentityHashMap
    LinkedHashMap
    LinkedHashSet
    LinkedList    
    PriorityQueue    
    Stack    
    TreeMap
    TreeSet    
    Vector
    WeakHashMap
    ArrayBlockingQueue
    ConcurrentHashMap
    ConcurrentLinkedDeque
    ConcurrentLinkedQueue
    ConcurrentSkipListMap
    ConcurrentSkipListSet
    CopyOnWriteArrayList
    CopyOnWriteArraySet
    DelayQueue
    LinkedBlockingDeque
    LinkedBlockingQueue
    LinkedTransferQueue    
    PriorityBlockingQueue
    SynchronousQueue
    BlockingDeque
    BlockingQueue
    ConcurrentMap
    ConcurrentNavigableMap
    TransferQueue
    Collection
    Deque
    Iterator
    List
    ListIterator
    Map
    Map.Entry
    NavigableMap
    NavigableSet
    Queue
    RandomAccess
    Set
    SortedMap
    SortedSet
I've worked with both Java and Scala collections classes for years and I strongly prefer the Scala collections. If you prefer the Java collections they work just fine from Scala too.
Re:In Defense of Scala. Response to “I Don’t Like Scala” by smrtinsert on Wednesday January 29, 2014 @10:53AM (#7144543)
I looked at it and understood it in a few seconds. What about it do you find complex? It looks like a well organized api to be honest.
Re:In Defense of Scala. Response to “I Don’t Like Scala” by scott_s on Wednesday January 29, 2014 @11:50AM (#7145011)
What is wrong with that? There are three core data structure types (maps, sets, sequences), and variants of those depending on need. Most of these are standard data structures you would find in an undergrad textbook.
Re:In Defense of Scala. Response to “I Don’t Like Scala” by kasey_junk on Wednesday January 29, 2014 @10:07AM (#7144211)
That is just the "published" hierarchy as well. Paul Phillips likes to pick on the ParSeqViewLike trait, and if you ever find yourself delving into it, you'll see why.
Re:In Defense of Scala. Response to “I Don’t Like Scala” by thescrewdriver on Wednesday January 29, 2014 @10:19AM (#7144291)
As someone who actually writes production code in Scala on a daily basis Paul Pillips' "concerns" have had zero practical impact on my daily use of the language. I tried to find content in his presentations that actually had any impact on me but I couldn't.
Re:In Defense of Scala. Response to “I Don’t Like Scala” by kasey_junk on Wednesday January 29, 2014 @10:28AM (#7144363)
As someone who also writes production code in Scala on a daily basis, and who took exception to the idea that the Scala collections library was a good example of type programming, Paul Phillips' concerns are spot on.

If you are using the collections library as example of how to structure your own code, you are in for a bad time. The abstractions are not right, and things like the silly ParSeqViewLike trait are an expression of that.

Re:In Defense of Scala. Response to “I Don’t Like Scala” by thescrewdriver on Thursday January 30, 2014 @04:34AM (#7149768)
In day-to-day use I haven't run into any of these issues. Your mileage may vary.