Ask HN: What are the best resources to properly learn Scala?
Hello, I've started to work with scala and I think it's a beautiful language. that said, I'd like to be better at it. What are some good books to get thst teach about the nitty gritty details of the language and it's use in production?
59 comments
[ 3.9 ms ] story [ 117 ms ] threadI think the answer to this question really depends on where you're coming from. An experienced Java developer will need to focus on different things than someone who has spent the last decade hacking Common Lisp or OCaml.
The first course is the one that's dedicated to Scala the language, whereas the rest are more focused on reactive/parallel programming that happens to be in Scala.
The first course is good, and acts as a good introduction if you've encountered functional programming before.
e.g: Futures used in there are from Finagle rather than scala.concurrent.Future
I found those books very good resources. The Scala website lists a few others (https://www.scala-lang.org/documentation/books.html)
Aprt from that I found Daniel Westheides blog a very good starting point (http://danielwestheide.com/scala/neophytes.html)
Once you are done with this, you can pretty much pick any of the projects here and start reading the source code:
https://github.com/lauris/awesome-scala https://github.com/adamw/awesome-scala
Reading code is the probably the best way to learn any programming language IMO
It's a bit dated, mostly targetting Scala 2.8. Current version is 2.12. But should not be fundamentally different.
[1]: http://danielwestheide.com/scala/neophytes.html
If OP already knows Scala and would like to get better at it and one assumes that "Scala as Haskell in the JVM" is more desirable than "Scala as a better Java", then yes, that's a great suggestion.
If OP wants to learn Scala from the ground up, I disagree pretty strongly with starting there. It's a great book, well written, with a wealth of challenging and mind-opening exercises, but I wouldn't recommend that as anyone's first exposure to the language. The second or third, sure, but it purposefully restricts itself to what its authors consider a sane subset of the language.
I happen to agree with their definition, but, in my experience, knowing a programming language is about reading it as well as writing it, and by restricting your learning to a subset of the language, you'll find yourself unable to understand perfectly valid, normal code - code that is part of the standard library, for instance.
I would rather suggest reading Odersky's book while allowing oneself to skip large chunks that go rather in too much details about fairly useless things like the XML API. Or going through scala-exercises (https://www.scala-exercises.org). Or the coursera class - its first incarnation was pretty good, I assume the new one is at least of the same caliber. They might not make you an expert overnight, but they'll get you to know most of the Scala features you're likely to encounter in the wild, and to be able to read and learn from most Scala OSS projects.
Of course, if you just read one book and stop there, I'd agree. But most people will continue learning from tutorials, videos, stackoverflow, etc.
I've also seen several other people learn Scala this way, usually without knowing any functional programming before, and really haven't seen any signs of issues wrt not understanding code written in other styles.
This blog has some good articles on how to work with Futures properly as well as some Akka stuff.
https://mitpress.mit.edu/sicp/full-text/book/book.html
Would you recommend any particular sections for someone who's looking to only understand the functional parts?
Just give it a try. I was hooked after first chapter!
Depending on what your background and what you want to learn, different books will be appropriate:
- Our books are focused on what we consider the most important concepts for functional programming and how they are implemented in Scala. If you want to know about algebraic data types, type classes, and so on, and how to implement them in Scala or use the implementations in the Cats library our books are a good choice. We emphatically do not teach all the language. If you want to know about OO features like self types and trait mixins don't turn to our books.
- Odersky's book has a lot of detail. It does a good job of presenting all of the language but doesn't IMO do a good job of showing you how to use the language.
- FPiS is a very good book that does what the title suggests. My main criticism is it can take a bit long to get to the point and it doesn't talk about libraries you might use in practice like Cats or Scalaz.
- The Coursera courses I have taken are fairly good, but don't do a great job of talking about the higher-level design concepts.
I haven't read other books, so can't comment on them.
Finally, if you don't have a background in formal CS our free book Creative Scala might be useful. The current draft is at https://dl.dropboxusercontent.com/u/8669329/creative-scala.p... and the source is at https://github.com/underscoreio/creative-scala/
Diversity discount ... I don't think we have a policy for books, but for training we offer 50% off to people who are under-represented in tech and I'm happy to offer the same for books.
Email me (noel at underscore.io) to arrange either.
I see from browsing the TOC that some topics are out-of-date (Xor.)
Final version should be out last half of this year.
Clojure only for fun, I need types. But lisps sounds fun. Can't comment more. Prehaps you're right ;)
Id also be careful with your 2nd statement. Scala has macros.
Im happy clojure is on the block, dont get me wrong :) each to their own. Type system is incredibly important to me and my productivity.
Why is writing functional code in scala not effective? How would one go about understanding 'for comprehensions' in scala without understanding what flatMap/map is used for in lieu if exception. Or why pattern matching is used.
1. The LISP family of languages encourages a style of functional programming that eschews static type systems, relies heavily on macros and algorithms involving singly-linked lists, and doesn't mind exposing the ability to mutate state.
2. The ML family of languages, of which I am the least familiar, are statically typed, but are also OK exposing mutable state and do not track any effects in their type systems.
3. Haskell heavily pushes reliance on Monads, monad transformers, and effects/state tracking through the above.
4. Proof assistants and similar languages like Coq go beyond tracking effects in the type system; they track values themselves, and essentially require you to prove mathematically that your program is correct.
So, given the above, what do you mean by functional programming? From the talks I've seen given by the creator of Scala itself, I believe he sees Scala as fitting in with the ML family languages moreso than Haskell.
Also, the way Scala's type system and runtime currently work, I don't think it's a good fit for Haskell-style programming. I tend to find monad transformer-based code in Scala exceedingly ugly and difficult to read compared to Haskell. The underlying runtime itself also has little mechanism for optimizing monad-based code, whereas the GHC compiler has probably man-years of effort spent into optimizing code using monads.
For example...
If you live in Dallas/Fort Worth and would like to learn Scala then you should know that the local Scala Enthusiasts group is hosting a Scala Essentials workshop on April 7th, 2017. This will be an all-day, hands-on event for Scala beginners. We will start with a language intro and finish up coding a REST server. More details can be found here: https://www.scala-enthusiasts.com/scala-essentials-workshop-...
For reference, I like http://naildrivin5.com/scalatour although it's 2.8 rather than the current 2.12.
For style guide, I'd go with Li Hiayo's blog, notably the Strategic Style series: http://www.lihaoyi.com/post/StrategicScalaStylePracticalType...
It's very practical, however it approaches the language from a completely novice perspective. If you have years of programming experience, it may be a little redundant for you.
Your best bet is to visit opensource projects and look into their build.sbt's, how they do things -they're usually not big enterprise projects and you can quickly 'get' how they setup what.
Always feel free to visir /r/scala and ask sbt-related question there, there is active community happy to answer both sbt/scala/fp related questions.
It's archived in SafariBooksOnline: check https://conferences.oreilly.com/strata/strata-ny-2016/public... before applying to Safari just in case.