
Hands-on Scala Programming - jvican
https://www.handsonscala.com
======
lihaoyi
I didn't post this, but cool to see this up here!

The full book is ~400 pages and will be released Summer 2020 (i.e. soon!). If
you're interested in being notified when it comes out, there's a mailing list
link on the page and I'll let you know when it's out. There will be both
E-Books as well as paperbacks & hardcovers (assuming the supply-chains are
still open in this COVID-19 global environment...)

The first 5 chapters are already online, for free now and forever. These form
a self-contained introduction to the Scala language: setup, basic syntax,
collections, and a notable language features. If you're looking for a quick
introduction to Scala, this is it.

The rest of the book goes heavily into use cases and projects in a way that
few other programming books do: interactive websites, network file
synchronizers, programming language interpreters, migration tools, parallel
web scrapers, and much more. The book intentionally skips a lot of language
esoterica in favor of showing how to use Scala to do things someone might pay
you a salary for.

You will learn Scala by building a breadth of useful experience, rather than a
depth of knowledge in language minutiae.

The chapters in the book are all based on real projects I have worked on. Most
projects take <100 lines of code (i.e ~2 printed pages), and it is a testament
to the Scala language that we can build working prototypes of all these things
in a single 400-page book!

If this interests you, feel free to leave your email on the website, and
browse through the free chapters already available.

~~~
nafizh
Will this be a good book to learn your first functional language?

~~~
throwaway_pdp09
Functional programming is a style or pattern. If a language gives you basic
stuff, you can do that pattern.

I learned a bit of haskell a long time ago - mind blown kind of time - then
found javascript had closures (erm, kind of a way of turning functions into
objects-with-state-that-still-look-like-functions) and functions as first
class objects (meaning a function can be passed around exactly like and
integer or a string) and so I used it in javascript. Google up "javascript
functional" and see what happens. Do some exercises.

Beware there are libraries out there that make simple functional Jscript stuff
look entirely unnecessarily complicated.

And when you're ready, pick up this guy's book!

Edit: that may have come across a bit insulting towards the author. All I'm
saying is you can learn the functional stuff while you wait for the book to
come out. And when you have the functional stuff under your belt, get the book
and you'll be one large step better prepared to dive into it - scala has a lot
more to offer than just functional programming, and the book will surely cover
a lot of ground.

~~~
codygman
> Functional programming is a style or pattern. If a language gives you basic
> stuff, you can do that pattern.

Kind of... correctness isn't as guaranteed though. Having a hard time putting
it into words at the moment, maybe I just need some holes poked into it to
draw out the rest of my view (or change it).

------
dr0l3
Some context for people who have limited knowledge of Scala.

Lihaoyi is one of the most prolific coder's, not just in Scala, but in any
language. He looks like he is much to humble and modest to claim so himself,
so I will do it for him.

Here is a by no means exhaustive list of projects

\- A buildtool

\- A bash replacement that speaks Scala

\- A test framework

\- A parsing library

\- Ports of several python libraries in Scala

\- Several libraries in the scala.js ecosystem

For the full list see
[https://github.com/lihaoyi?tab=repositories](https://github.com/lihaoyi?tab=repositories)

Discussions on Scala on HN tends to contain a somewhat large volume of
comments that explicitly or implicitly tries to communicate that Scala is a
language that is much to complicated to really be productive in. Lihaoyi is a
rather clear example of why this is not true. If this random internet citizens
endorsement doesn't convince you maybe the book will :)

~~~
christiansakai
I think your argument here is counterproductive. Lihaoyi is a prolific coder
but most coder like me are average Joe. How can Scala be useful and make
average Joe like me productive. The fact that Lihaoyi is a prolific coder in
any language does not help selling Scala.

~~~
justinhj
Haoyi makes libraries that are very easy to use, modelling them after popular
Python libraries. If you're interested he recently wrote a long blog about the
future of Scala being exactly this approach; make easy to use libraries for
people like yourself interested in being productive in Scala quickly.
[https://www.lihaoyi.com/post/TheDeathofHypeWhatsNextforScala...](https://www.lihaoyi.com/post/TheDeathofHypeWhatsNextforScala.html)

------
yingliu4203
Haoyi is an amazing guy. Last night at 8pm and 2pm this morning I submitted
two PR to the Mill, he merged within one hour. In about 7 years, he helped to
create an eco-system around Scala:

\- REPL (ammonite)

\- build tool (mill)

\- JSON serializer(uPickle)

\- web framework (cask)

\- test framework(uTest)

\- http client lib (requests-scala)

\- HTML tag lib (scalatags)

\- parser(fast parse)

Scala development and tool can be divided into four categories

\- Java (OO): wrong idea for many developers. Use Kotlin if you like OO.

\- Haskell (pure FP, even HKT): good for fun but not for profit. Use Haskell
for pure FP.

\- Erlang (Actors): fibers are better. Use Clojure if you like Actors.

\- Easy: practical FP, the above tools from Haoyi. Use them if you program in
Scala

I'd guess all is done after work. Please support him to make Scala better:
[https://www.patreon.com/join/lihaoyi](https://www.patreon.com/join/lihaoyi)

~~~
codygman
> \- Haskell (pure FP, even HKT): good for fun but not for profit. Use Haskell
> for pure FP.

My day job disagrees Haskell isn't good for profit ;)

~~~
yingliu4203
Haskell is not for every Joe working on ERP projects

~~~
codygman
I argue after the initial learning curve every Joe would find it easier to
avoid bugs in Haskell.

[https://www.simplehaskell.org/](https://www.simplehaskell.org/)

Then if you use simple Haskell for a year and want more type safety, you can
fearlessly refactor to get that.

------
christiansakai
I work JavaScript/TypeScript day to day, but I like Python syntax and easiness
but also like Go's concurrency. Having learned Haskell and Rust in the past,
these days I appreciate simpler language.

In what way does Scala have Python's convenience and Go's concurrency? Based
on talking to a few people that used Scala in the past they said they wouldn't
use it again and they said I probably wouldn't like it.

~~~
nicoburns
If you like simpler languages, you'll probably hate Scala. It's one of the
most complex out there.

~~~
vips7L
Kotlin is probably a better route if you're considering a non-Java JVM
language. Its simple, has easy access to the Java ecosystem, and avoids the
complexities of the scala FP purists.

~~~
9q9

       avoids the complexities 
       of the scala FP purists.
    

Are you sure? Have a look at Arrow [1] and similar! I am glad that languages
offer pure FP frameworks, so I can use them if I think they are the right tool
for the job, and can avoid them otherwise. It's an important software
engineering choice which style of programming to use, especially with multi-
paradigm languages. But the language should not enforce them!

[1] [https://arrow-kt.io/](https://arrow-kt.io/)

~~~
vips7L
While Arrow exists I don't think its representative of the community overall.

~~~
Psyonic
Neither is cats in Scala.

Most Scala programmers are probably just maintaining Play apps or using Apache
Spark, with no pure FP in sight. The pure FP contingent is just very active
and vocal online.

~~~
uDontKnowMe
Unfortunately like you say the pure FP crowd are extremely vocal online and
that seeps into the culture of any company that uses Scala. Most of the
visible members of the community value and advocate for fp purity and 100%
type-safety at any cost, and that has a large effect on who gets attracted to
learn Scala in the first place, what they consider to be good or bad code,
etc. The resulting culture of firms using Scala ends up being one of pure-fp
aspirational, if not pure-fp outright. Anyone who denies the superiority of a
pure fp approach is constantly brow-beaten for being such a simpleton.

Every time you dare use something as impure as a mutable object, or a non-
const reference (so var instead of val), or even want to look up an item in a
collection by index (unsafe operation since it will throw exception if index
>= length) you'll have to prepare for a heckling from your team mates. Anyone
you might ask help from online will first look down their nose at you for even
wanting to do something so despicable, and you'll have to humour them with
"well yes oh great FP lords, I know that this is really really bad I know, but
I have to for .... reason, please help me anyways!".

~~~
Psyonic
There is definitely some truth in what you’re saying —- especially at startups
without a strongly developed internal Scala culture.

I think it’s less of an issue at large companies like Twitter, Asana,
Databricks, etc, which overall probably employ most working Scala programmers
but not the most vocal.

~~~
hocuspocus
Zalando has probably surpassed Twitter as the biggest Scala shop for a few
years now. If you look at Twitter's ecosystem you'll see that while it's
mature, the style is very good overall and not so different from modern and
opinionated FP libraries. Twitter used to employ people like Travis Brown for
instance.

Spark (and Kafka too maybe) are outliers here.

------
petilon
This book has a section on "Why Scala" but not on "Why Functional
Programming". What is interesting about Scala, if you already know Java (and
most CS grads already do), is that Scala is a functional language.

Anyone know of a good book or article that gives an overview of functional
programming and answers the question of "Why Functional Programming", without
going into details any one functional language?

~~~
noelwelsh
As someone who has been in the functional programming world for a long time I
don't think you can _really_ understand it without some time using it.
Beginners tend to focus on language features (immutability, first class
functions, map instead of loop, etc.) but it's really a completely different
approach to programming than imperative programming. A paradigm shift, in the
original sense of the word.

It is also difficult to talk about concepts without some notation, and a
notation is exactly what a programming provides (as well as other things)!

That said, several people have attempted to write about it. John Hughes' "Why
Functional Programming Matters" is one that often comes up. There are a
million versions of this floating around the web. Here is one:
[https://www.youtube.com/watch?v=bL-
CcjKW1lw](https://www.youtube.com/watch?v=bL-CcjKW1lw)

I gave a talk on this topic, with examples in Scala:
[https://www.youtube.com/watch?v=bL-
CcjKW1lw](https://www.youtube.com/watch?v=bL-CcjKW1lw)

This paper is about the idea of paradigm shifts in programming, and is
beautiful and profound, though not about functional programming:
[https://www.dreamsongs.com/Files/Incommensurability.pdf](https://www.dreamsongs.com/Files/Incommensurability.pdf)

------
airstrike
> Knowing the language alone isn't enough to go to production: Hands-on Scala
> introduces the reader to the ecosystem of editors, build tools, web
> frameworks, database libraries, everything necessary to do real work using
> Scala. You will finish this book having all the necessary building blocks to
> be productive using Scala in production.

We definitely need more books to include this by default. Kudos!

I only wish a book like this existed for F#! If anyone has any
recommendations, I'm all ears

~~~
InnerGargoyle
my wish too..

------
submeta
Honestly interested to know: Is there any added value for a Python developer
in learning and using Scala? I love Python, especially because of its
ecosystem, its widespreadedness, and of course because of Pandas, Numpy,
Matplotlib. But I miss functional constructs from Mathematica or Scheme. Scala
seems to be much more systematic and profound, but again: For everyday usage,
is it overkill?

~~~
justinhj
It depends on your needs. Scala has some advantages over Python when you want
high performance, or if you want to build large programs, or if you're
interested in building principled or robust programs using functional
programming. Netflix machine learning seem to be leaning towards using both
Python and Scala together to take advantage of both. See this project:
[https://netflixtechblog.com/open-sourcing-polynote-an-ide-
in...](https://netflixtechblog.com/open-sourcing-polynote-an-ide-inspired-
polyglot-notebook-7f929d3f447)

------
spiderjerusalem
Tangential but I just found out that the author is the son of Singapore's PM
Lee Hsien Loong.

------
bogomipz
Both the content and layout looks really fantastic!

I wanted to ask any experienced Scala folks if its possible become really
proficient without a solid background in Java. I understand that its only JVM
hosted language so I guess my concern is how much Java you need to know when
things go sideways - stack traces, low level debugging etc?

~~~
philipkglass
I learned Scala on the job with no previous Java or JVM experience. At the
time I had been writing software professionally for 8 years. Before Scala I
had professionally written C, Fortran, and Python.

You will inevitably have to learn about the Java ecosystem when things go
sideways.

One example that comes to mind is problems with dependency resolution. SBT,
the most common Scala build tool, allows you to add libraries to your project
easily with notation like this:

libraryDependencies += "com.lihaoyi" %% "upickle" % "1.0.0"

Normally that is fine.

But when things go awry, sbt may provide unhelpful messages. You actually end
up having to learn about how Java's Maven (or Ivy) and its repositories work.

A couple of instances I recall:

\- SBT repositories were configured to look for dependencies on site A. A was
redirecting downloads to site B. Site B was configured with an expired TLS
certificate. The error message reported from sbt only mentioned site A. I only
figured out what was going on by tracing the network activity.

\- Maven central disabled insecure (HTTP) access earlier this year and started
requiring HTTPS. Some of our build configurations still referenced
repositories via HTTP URLs. I don't remember what the SBT error message was,
but it was again cryptic and unhelpful. Other developers who mostly work with
Go had to enlist my help in diagnosing the problem and fixing it.

A lot of Scala teaching material also assumes familiarity with Java. "Scala's
Traits are like Java Interfaces, but with these improvements: ...."

That didn't help when I hadn't used Java Interfaces before.

Fortunately, it looks like Hands-On Scala Programming doesn't assume a Java
background.

It also took me longer than it should have to understand the deep stack traces
you often run into. The key: look for lines that reference your own
application code, and focus there. (But this doesn't work if you are really
encountering library bugs or infrastructure flakiness.) The traces can be very
deep and a lot of the lines are not really relevant to solving your problem. I
was accustomed to reading shallower Python traces.

Learn to use a debugger early on. JVM code debugging with an IDE is powerful
and easy to use. Plus you can't just monkey-patch your dependencies on the fly
to add more diagnostics, the way I had done in Python.

------
truelaurel
great action to make scala more accessible to developers. this should be a
concrete answer to
[https://www.lihaoyi.com/post/TheDeathofHypeWhatsNextforScala...](https://www.lihaoyi.com/post/TheDeathofHypeWhatsNextforScala.html)

~~~
hackerm0nkey
I think they are both from the same author.

~~~
truelaurel
yes haoyi is taking concrete action to move scala forward

------
dionian
Haoyi's libraries (e.g. ujson) are great - and perfect for beginners to learn
Scala with, very idiomatic scala without the Haskell-style overhead.

~~~
codygman
I agree about Haoyi's libraries, but you're mention of overhead reminds me of
the overhead you run into trying to be purely functional in Scala.

If you're sold on benefits of purely functional programming, I think it's good
to know (at least as of a few years ago) Scala makes that more painful than
Haskell if you have even a little Haskell experience.

------
sscarduzio
Great book! Scala really needed some pragmatic programming resources! And I
really like the website, is it open source?

------
cmollis
awesome.. your blog has been extremely helpful to me.. looking forward to the
book.

------
ggregoire
I guess this question pops up every time… what are some good reasons to choose
Scala over Haskell or F# if you are interested in the FP part of Scala?

~~~
Sunscratch
When you’re choosing Scala you have all the perks of JVM platform. You can
reuse Java libraries if needed. Scala has pretty powerful type system. JVM in
turn is a pretty good platform, with decades of effort, which can tolerate
high load, make different optimizations in runtime, tolerate large heaps if
needed, GC story in Haskell runtime is not even close to JVM.

------
z3phyr
A little off topic: Are there similar hands on books for high performance
systems programming in C, C++ or Rust?

~~~
Kydlaw
There is Rust by example [1]. Maybe it is close to what you look for?

[1] [https://doc.rust-lang.org/rust-by-example](https://doc.rust-
lang.org/rust-by-example)

------
amdelamar
This book looks great, and I can't wait to pick up a physical copy. Thank you
lihaoyi!

------
nullobject
This looks great, looking forward to reading it.

------
sparklepwny
scala blows, use kotlin

~~~
dang
Please don't do this here.

------
brentonator
In light of social distancing can we get a not-so-hands-on version?

