
Hands-On Scala Programming - lihaoyi
http://handsonscala.com
======
lihaoyi
This was posted once before when it was work in progress, I thought it would
be nice to put it up again now that it is complete :)

In one 400 page book, Hands-on Scala takes you from from FizzBuzz, to Sudoku
solving, to Websites and API servers, all the way to implementing programming
languages, actor-based concurrent architectures, and massively-parallel web
crawling with futures. Every chapter has multiple multiple self-contained
executable examples, and multiple exercises with full executable solutions.

It’s a paid book, but the first 5/20 chapters (~100 pages) are free to read
online or download in PDF/Epub/Mobi formats, as is the github repo of 125
executable examples.

Whether you are a Scala newbie or an experienced Scala programmer, there’s
something for everyone in this book. The chapters on Actors and Futures in
particular are the best explanations for the concepts you will find in any
language, and would be useful even for people not using Scala.

Feel free to check it out!

~~~
dang
The previous discussion:
[https://news.ycombinator.com/item?id=22914610](https://news.ycombinator.com/item?id=22914610)

------
philipkglass
I bought Hands-On Scala Programming as soon as it became available. I bought
it on the strength of Li Haoyi's blog posts about Scala, which I have enjoyed
for years: [https://www.lihaoyi.com/](https://www.lihaoyi.com/)

This book is an excellent way to dive in to Scala for application development,
even though at this point it is more of a refresher than an introduction for
me personally.

I started using Scala at a new job in 2014 with no prior Java/JVM experience.
I bought Functional Programming in Scala, followed by Programming in Scala.
FPiS was completely the wrong choice for getting up to speed in my new role,
though it was academically interesting. Programming in Scala was closer to
what I needed although it didn't deal with larger ecosystem issues. Hands-On
Scala Programming feels like the book I should have started reading the first
day I started working in Scala development.

6 years later, I no longer have the new-user perspective on Scala and the JVM
ecosystem. Does Hands-On Scala adequately prepare someone for the JVM/Java
quirks that leak through into the Scala environment? I can't tell now. I've
internalized too much of that knowledge.

Assumed Java knowledge was a rough point for me in the first year or so using
Scala. If something goes wrong when you're fetching Maven dependencies in an
SBT based project, and you have never used Maven-as-Maven because you never
used Java before, you may encounter some baffling error messages and lack the
context to understand where you go next to fix it. I also encountered a lot of
"Like Java's Foo, but with X" explanations of Scala features that didn't help
because I never used Java. In the case of the problem with Maven dependency
failures and baffling error messages from SBT, I had to resort to running SBT
under strace before I found the root cause.

~~~
7thaccount
Same thing happened to me when trying to learn Clojure without Java knowledge
or F# without C#. It's a big hurdle.

~~~
sideeffffect
I did F# without having any deep knowledge of C#. I'm doing Scala without
being a Java expert. It is all quite possible and a lovely experience.
Moreover, the benefits that F# brings over C# and especially Scala over Java
are enormous.

------
wait_a_minute
Easily one of the best technical books I've read. I really enjoyed the clear
examples and clear writing. Making something extremely simple is super
important for understanding.

And the lovely typesetting is a huge plus when reading this on my laptop.
Looks great even when viewing in two-page mode.

Only complaint I can think of is that I'd have liked more exercises at the end
of each chapter. Ideally with less Sudoku as I don't want to have to dive into
the rules of a game in order to practice the collections programming. But this
is really a minor nitpick, 5/5 book in general.

~~~
lihaoyi
Glad you like the typesetting! I’m a professional web developer, among other
things, and the typesetting is just HTML + Bootstrap CSS 4.4.1, rendered into
PDFs using Puppeteer. Turned out looking much better than I had hoped!

~~~
krat0sprakhar
Oh wow, I didn't realize that this bootstrap! Do you mind documenting your
typesetting process? Would be a fun read!

~~~
lihaoyi
I'm planning on open sourcing the build pipeline soon, but it's basically a
Mill ([http://lihaoyi.com/mill](http://lihaoyi.com/mill)) build pipeline which
uses Scalatags + CommonMark-Java + Puppeteer + ApachePDFBox + EPubLib +
kindlegen to transform Markdown into HTML and then into {Web, PDF, EPub,
Kindle} X {sample, full} versions

Updating a single chapter and re-rendering the PDF takes less than 1 second,
and re-rendering the entire book in one format takes about 30s running
parallel on my 4 core macbook.

------
oytis
Hm... Was this posted seven times?

[https://news.ycombinator.com/from?site=handsonscala.com](https://news.ycombinator.com/from?site=handsonscala.com)

~~~
melling
Yes, he finally got traction.

------
p33p
Scala is a language I find interesting. Between Spark, Akka, and all of the
FP, it seems like it has most of the boxes I’d want. I have read mixed things
about the language though, specifically with respect to its future viability
and development. Is Scala worth learning in 2020?

Are there other languages with a well developed actor model that is also
performant with numerical computing? That seems like a deal breaker with
respect to a language like Elixir.

~~~
rb808
I'm in this boat too. If you look at lot of the Scala talks from 5-8 years ago
it talks a lot about why Scala is better than Java, but since then Java has
copied a bunch. Now Kotlin is taking over and Scala seems like yesterday's
language. I've heard its really slow to compile too which makes it
frustrating.

~~~
lihaoyi
The book's web page makes this pitch: Python-like convenience with Go-like
performance, easy safety and correctness via compiler checks, and a huge
ecosystem of tools and libraries. Compilation time is definitely a tradeoff,
but if any of those bullet points seem interesting to you then you should
definitely give Scala a serious look

~~~
ghj
I think a better way to sell a language is to name a few concrete niches that
they are amazing at. For example: C for low level systems, javascript for
browser apps, bash for shell scripts, java/swift for mobile, erlang for actor
models, haskell for compilers, python for ml, go for distributed systems, etc
etc.

To me, scala used to own the niche of "if you must use a jvm language but
don't want to use java". But now kotlin is the first language that springs to
mind. What would you say scala is best in class for now?

~~~
dropofwill
I’d argue Scala still owns that niche. Kotlin is nice if you’re stuck on
Android, but with the speed Java is progressing I don’t see a huge difference.
Especially in 2-3 years.

Also with Scala you get a best in class JS compile target, a great scripting
platform in Ammonite, and Graal native image for binaries with fast startup.

~~~
RhodesianHunter
> I don’t see a huge difference. Especially in 2-3 years.

There is a huge difference now. Maybe 50% of that difference could be made up
by what Java has in the planning stage.

Even if it was 100%, I'm writing code right now.

~~~
dropofwill
What's the huge difference? Coroutines? Boilerplate reduction? I guess there
are some minor type system improvements, but its not like you're getting
dependent types or anything like that.

~~~
RhodesianHunter
It is the sum-total of all of the little things. I could write out a list but
it would end up looking like the official site's sidebar.

It all adds up to making me far more productive and more sure of my code.

------
victor106
Just used Gatling which is based on Scala for performance testing on one of my
projects, it's the best performance testing frameworks I have ever used.
highly recommend

------
totorovirus
Scala has a really steep learning curve when you encounter user libraries.
Though I am moderately experienced in functional programming, I still have
difficulties understanding scala libraries from very experienced users. It
almost feels as if I didn't understand the language at all.

It is true that you can use the JVM ecosystem, but you'll see that your code
doesn't look like scala at all. Then you look for scala ported version of java
libraries (some essential but boring libraries like xls read/write) that isn't
likely to be maintained actively

~~~
mcintyre1994
I'd agree with this. I think it's because if you're writing a web server then
you're probably settled on one way you're going to deal with say asynchrony -
plain futures or cats or whatever. But Scala has this level of abstraction
above that where you can write a library that doesn't care which of those
you're using and just slot in around your choice. What it can't avoid is that
as soon as you jump into the source code of that library you see all these
type classes everywhere and have to mentally fit your concrete use case into
those complex looking function signatures that probably use concepts you're
not using much in your actual application code.

For better or worse it's super easy to write application code in Scala without
going to a very abstract level, particularly in an ecosystem like Play. And
that does make library code feel less familiar because it's using features
that you just don't necessarily use very much in your application code.

~~~
totorovirus
Play is very well documented (compared to other libraries) but some of scala
libraries are not very well documented that I had to actively dive into source
code level. Reading and understanding it wasn't easy at all.

Scala seems to have many black magics under the hood and this is one of
biggest drawback of using scala

------
namelosw
I just bought it. It looks beautiful and the topics are very practical.

With Scala 3 almost in sight, will this book update to Scala 3?

~~~
lihaoyi
It will, but the Scala3 launch date is still up in the air so I can’t give any
concrete promises as to when

~~~
namelosw
That makes sense. Thank you for your response!

------
stephen123
Haoyi has written some excellent libraries and tools for scala. I use ammonite
daily. Im sure this book is great!

~~~
theCodeStig
Ammonite is great! I think it could use more exposure, especially the REPL.

------
xgdgsc
Great book I can tell from the Contents. I used Scala for interactively
inspect functions in jar you don't have source code. In most of other domains
I tend to use other languages with a less powerful syntax to collaborate
easier with other people.

~~~
ducklord
> I used Scala for interactively inspect functions in jar you don't have
> source code.

How do you do that? I've only used javap on the command line for this.

~~~
xgdgsc
Of course I first decompile using cfr. And then use scala REPL to load the jar
and call functions to see the effect and find the parts interesting for
further analysis.

------
sireat
Fantastic book from the sample chapters!

Any plans to offering a printed version using one of the print-on-demand
services(Leanpub etc)?

I'd gladly pay the full $75 for such an offering.

I plan on using the book for a practical Scala course that I will be teaching
in the fall.(Programming in Scala is fine but not as practical).

------
jyriand
I would love to buy this books, but the price seems way too high. I would pay
~$20 without thinking, but seeing that bundle costs $78 I don't feel
comfortable anymore. I start to second guess if I really need this book right
now etc.

------
RyanDeLap
Fantastic book by a fantastic OSS engineer. Keep up the good work Li Haoyi!

------
counter2015
Thanks for great work!

I just bought a PDF version. It looks nice at the first glance.

Do you plan to keep updating the book's content and code in the future? I'm
really looking forward to your views about Scala 3.

~~~
lihaoyi
The book is basically done for now. I will likely update it for Scala 3, but
that's still a moving target, so I'll wait for the dust to settle before
considering it.

I don't expect the code to need to change too much to support Scala 3: Scala 3
is likely going to be backwards compatible to a large degree, and the code
you'll be writing in Hands-on Scala is pretty simple Scala that doesn't touch
the more advanced features that might be affected by the upgrade

------
Sevaris
Oh, wow. This looks fantastic. Unfortunately far beyond my current budget, but
definitely going to keep it in mind. I've been wanting to learn Scala for a
while now.

------
Swinx43
This looks absolutely fantastic! Does anyone know or have recommendations for
a book similar to this but for Golang?

------
bra-ket
thanks for the book and blog!

what do you think of Scala adoption and prospects these days

~~~
lihaoyi
I think Scala adoption is doing great.

A lot of the initial hype around things like Akka and Pure Functional
Programming has died down since the frothy excitement of 2015-2016, but
honestly I think a lot of that hype was oversold and many of these things
never quite lived up to their original excitement.

Right now, the level of hype has fallen back to where the _real_ value is: a
solid language allowing flexible styles to suite a wide range of use cases, as
concise and convenient as any scripting language, with excellent performance,
tooling, and static checking to prevent defects.

With this book, I'm obviously hoping to drive adoption and prospects up, and
I'm doing so by trying to sell the value prop above rather than the value
props that were (over-)hyped in the 2015-2016 era

~~~
theCodeStig
I agree that Akka was over-hyped, and over-used. I don't think that pure FP is
or was over-hyped. It is, however a large reward for a large time investment
to learn. Many simply don't have the time capacity or motivation to completely
change their mindset from imperative programming.

