12 ms·
Hands-On Scala Programming
- lihaoyi 6y agoThis 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 6y agoThe previous discussion: https://news.ycombinator.com/item?id=22914610 https://news.ycombinator.com/item?id=22914610
- wait_a_minute 6y agoEasily 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 6y agoGlad 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 6y agoOh wow, I didn't realize that this bootstrap! Do you mind documenting your typesetting process? Would be a fun read!
- lihaoyi 6y agoI'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.
- p33p 6y agoScala 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.
- nicoburns 6y agoRust and Actix? I'm not familiar with what other Actor frameworks provide though, so Actix may well not count as "well developed".
- Cyph0n 6y agoI don’t have much experience with either, but Akka is probably way more mature than Actix.
- marcinzm 6y agoDidn't the Actix creator say "fuck open source, fuck all of you" due to the amount of hate he got from the Rust community for overusing unsafe? That doesn't seem a stable foundation on top of which to build something no matter which side of the argument you fall on.
- deleted 6y ago[deleted]
- lmm 6y ago> 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? Scala has always attracted an outsized amount of hate and FUD. That said, Scala 3 has taken a long time to arrive, costing the language a lot of momentum, and makes some fairly radical changes. I'm a huge fan of Scala and I really want it to succeed. Haskell's laziness is a dealbreaker IMO (it makes it impossible to reason about performance), and no other language offers the combination of: 1. A type system powerful enough to replace all your uses of reflection/AOP/metaclassing/etc.. No more magic frameworks to learn; write real-world business applications using nothing but plain old functions and values that follow the normal rules of the language (e.g. your web routes can be literally a function from request to response; they don't look quite as nice as a dedicated routing config file would, but they're normal code that automated refactoring etc. will work normally on). Concretely, what makes this possible is the combination of higher-kinded types (letting you represent any custom effect, e.g. a database transaction, as an F[_] type, and then use the language's for/yield syntax to compose those effects in a way that makes them visible but not overly verbose/intrusive), and records (letting you "walk the object graph" in a type-safe way). Scala can do all this without having to resort to general-purpose macros (there is one macro in shapeless that the whole rest of the ecosystem just reuses), so you can be confident that your IDE/debuggers/etc. will all understand your code. 2. A proper first-class IDE, and a good declarative build tool integrated fully with that IDE (maven - for some reason the Scala community pushes the incomprehensible SBT, but ignore that). 3. Completely seamless compile-to-javascript experience. You write normal code, push the button, and there it is running in your browser. When you want to use a library you import typescript type definitions with https://scalablytyped.org/ https://scalablytyped.org/ and it all just works. Combined with the previous point that means Scala is actually the best language to use for frontend development right now. Unfortunately the set of people who know about Scala and the set of people who do frontend development don't really overlap. I'm not wedded to Scala for the sake of Scala. But no other language comes close. All that said, it definitely feels like the next year or two could be a turning point (in either direction) for the popularity of the language. Scala 3 may revitalise scala or destroy it. So it's undeniably a risk. But I'd say that even if the language becomes less popular, learning it will make you a better programmer and give you an appreciation for what's possible.
- oytis 6y agoHm... Was this posted seven times? https://news.ycombinator.com/from?site=handsonscala.com https://news.ycombinator.com/from?site=handsonscala.com
- melling 6y agoYes, he finally got traction.
- philipkglass 6y agoI 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 6y agoSame thing happened to me when trying to learn Clojure without Java knowledge or F# without C#. It's a big hurdle.
- sideeffffect 6y agoI 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.
- 6y ago
- xgdgsc 6y agoGreat 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 6y ago> 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 6y agoOf 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.
- stephen123 6y agoHaoyi has written some excellent libraries and tools for scala. I use ammonite daily. Im sure this book is great!
- theCodeStig 6y agoAmmonite is great! I think it could use more exposure, especially the REPL.
- bra-ket 6y agothanks for the book and blog! what do you think of Scala adoption and prospects these days
- lihaoyi 6y agoI 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 6y agoI 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.
- Sevaris 6y agoOh, 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.
- namelosw 6y agoI 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?
- RyanDeLap 6y agoFantastic book by a fantastic OSS engineer. Keep up the good work Li Haoyi!
- totorovirus 6y agoScala 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
- matthewtovbin 6y agoI politely disagree. This is no longer true.
- mcintyre1994 6y agoI'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 6y agoPlay 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
- victor106 6y agoJust 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
- counter2015 6y agoThanks 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 6y agoThe 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
- Swinx43 6y agoThis looks absolutely fantastic! Does anyone know or have recommendations for a book similar to this but for Golang?
- jyriand 6y agoI 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.
- sireat 6y agoFantastic 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).