top | item 22914610

Hands-on Scala Programming

378 points| jvican | 5 years ago |handsonscala.com

103 comments

order
[+] lihaoyi|5 years ago|reply
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.

[+] taikawatiti|5 years ago|reply
I can vouch for lihaoyi. He is one of the more prolific people in the scala community writing top notch stuff. The best part about most of the stuff be writes is they are extremely ergonomic, even by scala standards. Look at either scala-tags or even better his parsing library. The parsing library is actialy so good you'll feel like finding more problems to solve. Its a breeeze to get started with (even in repl). Scala-tags also is amazing and has spawned other similar projects , one of which is laminar which is currently one of the top scala-js frameworks.

In fact I can probably say this for a lot of his work, anyone learning from him would probably learn a user centric way of library design.

[+] forty|5 years ago|reply
As someone who really like reading your blog articles, I'm super happy to see this :) I'll probably purchase it, as a part of my strategy to make my friends and colleagues start scala :) I'm looking forward to a "advanced scala programming" follow up ;)
[+] christiansakai|5 years ago|reply
Looks like Scala instead of OCaml is in my next language to learn.
[+] totalperspectiv|5 years ago|reply
Will the ebook be released before the physical version? This is EXACTLY the book on Scala I've wanted and am so excited to see this coming!
[+] mason55|5 years ago|reply
This is very cool, I love the idea. How does the book handle Scala 3?
[+] nafizh|5 years ago|reply
Will this be a good book to learn your first functional language?
[+] bigbizisverywyz|5 years ago|reply
Hiya, found a typo - couldn't see where else to mention it so adding here, maybe the author will notice.

Ch 3.

This chapter will not covering any Scala-specific

should be: This chapter will be not covering any Scala-specific

Otherwise enjoying what I've read so far. I've just been dropped in at the deep end of a project with no scala experience, so I'm trying to get off the ground asap.

[+] surroundingbox|5 years ago|reply
Could you compare your book to ``Scala for the impatient´´?,
[+] dr0l3|5 years ago|reply
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

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 :)

[+] yingliu4203|5 years ago|reply
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

[+] tunesmith|5 years ago|reply
> - Erlang (Actors): fibers are better. Use Clojure if you like Actors.

Usually the suggestion for actors is to use something else, but I think the main exception is the big one. If you have a need for horizontally scalable concurrent state and behavior, there hasn't really been a good alternative to distributed Akka Cluster Sharding. People are working on it, but I don't think we're there yet (although my opinion might be six months out of date, I haven't caught up).

[+] codygman|5 years ago|reply
> - 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 ;)

[+] acjohnson55|5 years ago|reply
I think you're missing perhaps the biggest camps in the form of the Lightbend ecosystem (very much pragmatic OO/FP hybrid) and the big data ecosystem around Spark. Even though the Lightbend stack also has Java APIs, the Scala APIs are very much their own thing.
[+] non-entity|5 years ago|reply
I don't think I've ever heard of Fibers. What's wrong with actors?
[+] christiansakai|5 years ago|reply
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.

[+] cinnamonheart|5 years ago|reply
Scala has a very wide surface area, and it can be as simple or complex as you want it to be.

Written in a certain way, it's that different from writing Python 3 with PEP-484 type annotations. You can easily write Python-like code and just get things done. :)

Concurrency-wise, you can implement any concurrency model you want on top of it, and, personally, I find immutability + Task-like implementations (Monix, ZIO, IO, etc.) easier to understand than CSP, but that's just me. There's also actors & channels & threads & anything else you could want.

What's cool, though, IMO, is that once you need more power than just Pythonic Scala gives you, it has one of the most powerful type systems in the world; you can verify as much as you need to, and refine things over time. It's not a language that hamstrings you once you do need more power.

Scala gets its bad reputation from that huge surface area and flexibility, though. There was a period (2009ish, maybe) where the Scala community was having a field day with its flexibility via custom operators like '<<++>>' and implicit conversions and untyped actors that made it impossible to figure out what was going on. It was like using the worst of Erlang with the worst of Haskell with the worst of Java. I'd say they've matured past that entirely, though; in 2020, it's one of the nicer and more practical languages, ecosystem, & communities IMO. Scala is made for getting things done.

[+] AzzieElbab|5 years ago|reply
Scalas echosystem is overloaded with overly complex libraries that take months to learn. Li Haoyi has been trying to change that for years with his to the point open source projects. In my opinion, now is a pretty good time to get into scala with projects from Haoyi, ZIO, quill, akka, and many others that are built on strength of scala itself matured way pass being carbon copies of java or Haskell's equivalents.
[+] nicoburns|5 years ago|reply
If you like simpler languages, you'll probably hate Scala. It's one of the most complex out there.
[+] therealdrag0|5 years ago|reply
My anecdote: if I were to go from Java to Go I would have been I impressed with its ease of concurrency, but going from Java to Scala to Go, I was unimpressed. I already had simplicity of concurrency with Scala without feeling primitive like I did with Go.
[+] AzzieElbab|5 years ago|reply
"In what way does Scala have Python's convenience and Go's concurrency" - I think that is exactly what the book is trying to teach you. There are some pretty good examples in the free chapters
[+] dxbydt|5 years ago|reply
I stand corrected.
[+] petilon|5 years ago|reply
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|5 years ago|reply
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

I gave a talk on this topic, with examples in Scala: 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

[+] airstrike|5 years ago|reply
> 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

[+] spiderjerusalem|5 years ago|reply
Tangential but I just found out that the author is the son of Singapore's PM Lee Hsien Loong.
[+] submeta|5 years ago|reply
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?
[+] bogomipz|5 years ago|reply
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?

[+] dionian|5 years ago|reply
Haoyi's libraries (e.g. ujson) are great - and perfect for beginners to learn Scala with, very idiomatic scala without the Haskell-style overhead.
[+] sscarduzio|5 years ago|reply
Great book! Scala really needed some pragmatic programming resources! And I really like the website, is it open source?
[+] cmollis|5 years ago|reply
awesome.. your blog has been extremely helpful to me.. looking forward to the book.
[+] ggregoire|5 years ago|reply
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?
[+] amdelamar|5 years ago|reply
This book looks great, and I can't wait to pick up a physical copy. Thank you lihaoyi!
[+] nullobject|5 years ago|reply
This looks great, looking forward to reading it.