Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> It turns out, this describes expert Java programmers very well, too -- so it's no surprise that Scala is a very popular language with Java programmers. I'm finding that Clojure is the more attractive language if your sensitivities lean toward the "simplicity" and "dynamism" camp. I was reading some Scala code being used in production at Twitter and found this marvel: https://twitter.com/amontalenti/status/410977749629546496 -- you would simply never see anything like this in Clojure or Python codebases.

Well done, you found some bad code written in Scala. I can assure you I've seen far worse in Python.



Out of curiosity, is that piece of code necessary? Is there no better way to condense that? I'm a beginner with Scala, so I have no clue on that front.


Well, that code exists at all for compatibility with tuples, which are a misfeature from the early days of scala. The "right" way to solve the problem is with shapeless' HLists. With HList you could write a simple generic method that would work with a HList of any length. (If you don't need to join a bunch of hetrogenously-typed futures while preserving all their type distinctions then you could just use the method that takes a Seq, above in the file)

(You could also generate exactly this code with macros, which were a new feature in scala 2.10; I imagine a newer version of the code will do that)


I'm surprised you can't map over tuple members and join. Should be a one liner, but I'm a scala newbie though. Tupled were an unnecessary choice here.

Pointing to this kind of stuff as an example of scala shows a complete misunderstanding of the language quite honestly.


There are some similar ugly workarounds of that nature in Play's JSON macros. Quite ugly but also transparent to anyone not writing library code.


That is a library code, not something you would write (or try to understand) normally.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: