• Fantastic post and kudos to your Scala skills for working through that example!

  • Oleg Aleshko

    oh glad to see comments are now working
    Thanks for the post!
    one point i cannot agree with is  “In fact, it is impossible to insert a new method that behaves like a normal collection method. ”
    please see http://ideone.com/ePUHG

  • Anonymous

    Did you catch Daniel Sobral’s implementation of the filterMap problem you presented? (http://dcsobral.blogspot.com/2012/01/adding-methods-to-scala.html) — it is possible to implement, though I’ll agree that the collections types in Scala are complicated to understand.

    (Annoying that when I used “log in with Twitter” that my wife’s identity was used instead of mine — some kind of Disqus bug

    Brian Maso)

  • I did see that, and I replied with a comment there, which I’ll paste here:

    “Er, except this doesn’t address the issue at all. This method doesn’t work on Arrays, Strings, etc., but that’s OK, since apparently that goal is crazy.

    “Although I’m interested in all feedback, I’m saddened by this response, esp. coming from dcsobral. It epitomizes precisely the type of stubborn dismissal from the community that I was writing about.”

  • Manoj Waikar

    I’ve never studied Scala and am in love with Lisp-y languages because of their simplicity. So obviously I am learning / using Clojure these days. Since you already know Lisp, would you mind explaining why you chose Scala? Maybe I am an ignoramus but I fail to understand why would anyone pick Scala over Clojure?

  • Steve

    The solution posted on that Pastebin works. Did you have a look at it?

    Isn’t it obvious that Scala people are a bit pissed-off because 95% of the language critics don’t even get either the problem or the solution but use it as propaganda to prove their point? Just have a look at all those “it is totally easy in language A” on HN which completely missed the issue.

    Now there is another completely out-of-proportion flame bait going on for the next two weeks, probably … what a waste of time.

  • That’s definitely the closest stab I’ve seen! As you note, it still requires supplying the type inferencer with hints every time you invoke a method, but it’s probably my favorite so far.

  • Anonymous

    I read this post as “scala has limits”, so you can’t add extension methods easily in cases where generics or conversion chains are involved. ok. In contrast to C++, this happens in corner cases and are easy to side step (wraper method) where C++’s complexity manifests itself in day-to-day problems.

    Having said that, I think that implicit conversion is one of the poorest features of scala and feels like a hack thrown together quickly. I would have expected something that works better.

  • Jozef Wagner

    They were scared of parentheses and have ended up using periodic table for http requests

  • Jon-Anders Teigen

    Never say something is impossible when you have people like Miles around. 
    https://gist.github.com/f83892f65f63b14a1f75

  • Oleg Aleshko

    Imagining how this would look in C++ or any of the existingprojected JVM languages gives me creeps.
    And I have high hopes that someday even that smallish hinting would not be necessary, so long as people like Paul Phillips are working on Scala.

  • Miles Sabin

    It’d be nice to see another update acknowledging that there is a solution for filterMap of the form you want: http://goo.gl/Wx0Yy.

    I don’t think it’s existence significantly affects your argument, however it is an example of Scala’s sophistication making otherwise very difficult things possible, albeit non-trivial.

    It’s also a good example of a real world scenario where, in my opinion, a bit more sophistication (ie., the enhancement to Scala’s type inference described here: http://goo.gl/M9Tw4) would reduce complexity rather than increase it.

  • Daniel Sobral

    Right on, Steve.

  • Great post and nice “tour de force” over Scala features. I agree that the some features interact in a very complex way… it would be interesting to see a Scala 3.0 (or Scala Phoenix) streamlining the language and the compiler. 
    Still, at the end of the day, Scala is my language of choice for the JVM, it’s mix of OO, FP, and static typing is what I currently need. 
    (tying all this with seamlessly Java interop is one of the major sources of complexity) . 

  • Daniel Sobral

    It’s not the Goal that is crazy, it is wanting to have a definition for X work for Y. Let’s represent the implicit conversions:

    String => StringOps => Seq StringOps => Seq => FilterMap

    I don’t think that’s a reasonable expectation, and, yet, it actually works if you don’t need the type A to get it to work. And, yes, I agree it would be a nice-to-have.

    However, that is widely different than saying you can’t add collection-like methods to collections. You can, it just won’t be automatically added to stuff that are not collections but are convertible into one, which is a very different matter.

    See the hacker news discussion, where people not familiar with Scala have completely misunderstood your point, and they have done so because expecting the above to work is not something other languages out there make even thinkable.

    I think it is actually a credit to Scala that you expect to be able to do that at all.

  • Anonymous

    Would it be adequate to call your solution the ‘pimp-my-collection-library’ pattern?

  • andres

    I choose scala because of type safety, I need a compiler!

  • Note that it still requires per-source-type/shape boilerplate; it’s not far off from a brute force solution of an implicit per source type/shape.

  • Pingback: Scala needs terraces | /var/log/mind()

  • Miles Sabin

    Well of course it requires per-shape boilerplate for completely unrelated types! The key point is that there’s no need to copy-paste the filterMap algorithm for each shape. Asking for more than that really is a bit much.

  • Turing Eret

    Out of curiosity, how much of this is relieved if Scala didn’t have to deal with type erasure?

    Great post though.  It really does hit a lot of my frustrations with Scala in a very elegant way.

  • That would certainly change some things, such as its interaction with refinement types, but there’s still everything else.

  • I think https://issues.scala-lang.org/browse/SI-2781 is what’s keeping toFM2 from working. Tricky to fix, that one.

  • Pingback: Surprises in Scala’s “Uniform Return Type” Magic | Codes, Notes & Scribbles()

  • Great post. May I translate this post into Korean? A link to this article and a message about your orignal content will be posted on my blog. 

  • Certainly!

  • Jason Wheeler

    I read through your post, and frankly you know the Scala language better than I do.  I have conflicting internal feelings on what you wrote and haven’t worked through them all yet, but one feeling that I keep having has already been expressed as a meme:

    http://www.quickmeme.com/First-World-Problems/ 

  • Miles Sabin

    As of this (http://goo.gl/ycaMx) merge it’s a lot easier to enrich Scala collections and retain all the benefits of the framework.

  • Pingback: Why Do Some Programming Languages Live and Others Die? [Coding] ← ← TechsyndTechsynd()

  • Pingback: All About Languages » Blog Archive » Why Do Some Programming Languages Live and Others Die? [Coding]()

  • Pingback: Why Do Some Programming Languages Live and Others Die? |()

  • Pingback: ??????????????????? – WHO1753()

  • Pingback: ??????????????????? – WHO1753()

  • Pingback: ???IT??????????????????????? | ???()

  • Pingback: ???IT??????????????????????? | ???()

  • Pingback: ???IT??????????????????????? | ???()

  • Pingback: ??????????????????? « ???()

  • Pingback: ??????????????????? | ???????()

  • Pingback: Two negative views of Scala | David Ruescas()

  • Carlos Saltos

    ha ha ha ha !!

  • Great post though. It really does hit a lot of my frustrations with Scala in a very elegant way.

  • ??? ??????

    So obviously I am learning / using Clojure these days. Since you already know Lisp, would you mind explaining why you chose Scala? Maybe I am an ignoramus but I fail to understand why would anyone ???? ??? ?????? ?????? ??????? pick Scala over Clojure?