Scala Macros and Metaprogramming
Become a Scala wizard. Learn how to manipulate Scala code at compile time (with Scala!) and write powerful code and tools that other developers only dream about.
- Duration
- 13h of 4K content
- Lessons
- 43 lessons
By Daniel Ciocîrlan
Money-back guarantee · Unlimited access · Free updates
Course Roadmap
Skills You'll Learn
- Read, understand and change any Scala code at any scale
- Write complex Scala code that other developers fear touching
- Build and improve tools and libraries
- Enforce best practices automatically at compile time
- Integrate with other tools in a statically-typed way
- Write custom String interpolation
- Use match types and inline and transparent inlines
- Perform compile-time operations and circumvent type erasure
- Build macros and construct expressions programmatically
- Deconstruct and match on expressions
- Synthesize types and dynamically generate values, methods, classes
- Summon givens at compile time
- Analyze ASTs and work with compile-time reflection
- Replace code at compile time
Goal
Become a Scala Wizard.
As you already know by now, Scala is the most powerful programming languages on the JVM and one of the most powerful programming languages, period. For more than 20 years, Scala has been an inspiration for other languages, starting with Java and Kotlin.
Here’s something that the other languages will never be able to match any time soon: the ability to generate, analyze, transform and manipulate code, at compile time, with the same language.
In Scala, this is possible. You can manipulate other Scala code at compile time, with Scala as the tool to do it. With this power, you can create libraries, tools and functionality that other developers can only dream about. Only a few people besides the Scala compiler team know these techniques.
This is what you’ll learn in this course.
What's a Scala Macro?
Metaprogramming in Scala = Programming on Scala Programs.
Few languages offer true metaprogramming, i.e. the ability to manipulate code as it’s being evaluated or compiled. Lisp (with its family) is the gold standard, because it’s easy to represent code as data. The dynamic type system also helps, because there is no requirement for how code should look like: it’s just a list like anything else! So how do you use it, and how can you make sure that the code you get is correct? Oh yes, you can’t.
Scala is different.
For the first time in a statically-typed language, Scala gives us the power to manipulate code at compile-time, with all the types in place, with all the regular data structures we normally use, with even more powerful pattern-matching, with the guarantee that either the code is correctly specified, or it doesn’t compile. It’s magic.
With these techniques, you can create:
- tools to analyze and auto-improve your code
- semantic linters and auto-fixers
- compile-time code optimizers
- serialization libraries, JSONs be damned
- statically-typed auto-integrations with other tools
and much more.
How This Course Works
Who is this course for?
This course is for the seasoned Scala developer. You’re probably a senior developer, a Scala expert in your team, a lead who sets the standard, a library or tooling developer, or all the above.
If you need to write:
- complex Scala code that checks or analyzes other code
- libraries
- code/productivity improvement tools
- semantic linters
- statically-typed integrations with other software
or just want to know the most powerful and rare Scala skills, this course is for you.
We write about 2600 lines of code from scratch in the course - very likely the most powerful Scala you’ve ever written so far. This picture shows you what we’ll do in the course.
100% Hands-On
You know the style of Rock the JVM: we learn best by writing code.
We do have slides, but only after we write the code. It’s mostly “flash cards” that you can refer back to after you finish the course.
There’s no substitute for hands-on practice, and in this course we have plenty of examples. This course is tough, but you’ll come out of it as one of the few people that know metaprogramming in Scala with macros.
We also have two real-life projects in the course that we’ll write from scratch, we’ll talk about them in a bit.
More than the code, though, this course will expand your mind on what’s possible in a programming language. You’ll learn about the compilation process, about what a programming language can and can’t do, and you’ll get timeless skills that you can transfer to other languages. It will be easy, since Scala has been an inspiration for other languages for decades.
If you need just a one sentence to convince you: if this course doesn’t prove to you that Scala is THE most powerful programming language you’ve ever seen, nothing will.
Scala Macros Project 1: The Wartimizer.
This is a tool we write from scratch, which is a 2-in-1: it fixes bad code, and makes okay code good.
Here’s an example. A combination of "My string" + aValue is generally considered bad practice, even though not enforced by the language. The Wartimizer is able to detect instances of this smell in your code and signal a compile error in the right place.
Another example. Juniors may not know all the standard libraries, so they may write things like aList.filter(somePredicate).headOption, where a .find(somePredicate) will do. The Wartimizer detects it, and automatically replaces the calls at compile time, without any intervention from you.
You’ll design Wartimizer so that you can add as many wart removers (signal bad code) or optimizers (improve okay code) as you want, or apply them selectively on a piece of code.
Scala Macros Project 2: Type-Safe JDBC.
This is a tool that will “talk” to a database, figure out table structures, and synthesize correct types for your data, at compile time.
Normally, we need ORM libraries or magical stuff like Doobie or Quill to be able to map database types to our data model that we write manually. This project is an experiment: what if we skipped all that and synthesized types automatically with the right fields before the code is even compiled?
This is the most black-magical examples in this course. If you finish this project, you’ll be able to build any library or tool in Scala, period.
What Our Students Say
-
My team is expanding the use of Akka in our products so I needed a quick introduction on this topic. I have tried a couple of courses but the introduction to Akka was always too abrupt, too hard to comprehend. I blamed Akka for this as being too hard to explain. This was until I was exposed to the Rock The JVM courses which were an absolute delight when it comes to presenting such complex topics in such an easy to understand way. And Daniel has not stopped at Akka but has added to his portfolio amazing courses on Scala and Spark too. It seems like he is quite enjoying taking such challenges like complex technologies and making them so simple for everyone. I have instantly recommended Daniel’s work to my team, which helped them immensely with taking their skills to a new level, and I do recommend these courses to anyone who wants to have the fastest ramp-up in these tough but popular technologies.
Mihai FecioruAdobe · California
-
From Scala, to Akka, to Spark, Daniel delivers exceptional material in each and every one of these technologies. I’ve been using them for a long time and there is always something new I will discover from him. The level of detail he gets into as well as the way he delivers material is mindblowing. I personally find his latest course Spark Optimization pure gold and one of a kind. I’ve been using Spark for a year now and I haven’t even thought how much you can leverage query plans to make such optimizations. I can’t stop thinking every time, how he manages to go so deep - because using a technology is one thing, but knowing its internals so well and how everything works behind the scenes is another story when it comes to distributed systems. Long story short Daniel is definitely the best instructor I’ve come across and each one of his courses is the best resource you can find online. Kudos for all your work and knowledge sharing.
Giannis PolyzosVerverica · Greece
-
Daniel’s courses on Scala and Big Data are the best in class. I’ve been in touch with Daniel’s teaching and courses since early 2018. The first course that I took from him was Scala & Functional Programming; I was skeptical about it because over the internet there are many courses you can find, but few really worthy. I remember the very first day when Daniel started to speak and shared his examples - I started to love Scala, and then more as we went on. I am with Scala for the last 5 years now, but never ever has anyone explained to me or gave me comparable resources to Rock the JVM. Daniel gave me a shift in life and helped me crack top tech company interviews. His courses on big data are a must for any aspiring big data developer or data enthusiast. I highly recommend Daniel as an educator both online and on campus.
Anirban GoswamiApple · California
What's Included
Inlines
Macros
Epilogue
Meet Rock the JVM
Daniel Ciocîrlan
Founder, Rock the JVM
I'm a software engineer and the founder of Rock the JVM.
I started Rock the JVM out of love for Scala and the technologies it powers. They are amazing tools, and I want to share as much of my experience with them as I can.
I've taught Java, Scala, Kotlin and related technologies such as Cats, ZIO and Spark to 100,000+ students at various levels. I've held live training sessions for companies including Adobe and Apple, taught university students who now work at Google and Facebook, run Hour of Code for 7-year-olds, and taught more than 50,000+ kids to code.
I have a Master's Degree in Computer Science and I wrote my Bachelor and Master thesis on Quantum Computation. Before learning programming, I won medals at international Physics competitions.
In collaboration with
Daniel Beskin
Daniel is a Scala developer and a frequent speaker at Scala conferences. He describes himself as a somewhat functional developer who is convinced that the best way to learn something is to teach it.
Enroll now!
All-Access Membership
Full (and growing) catalog
$195 billed yearly —Save 54%
Unlimited access to every Rock the JVM course
- 348 hours of 4K content
- All Scala courses
- All Kotlin courses
- All Typelevel courses
- All ZIO courses
- All Apache Spark courses
- All Apache Flink courses
- All Akka/Pekko courses
- Access to the private Rock the JVM community
- New courses included automatically
The Scala Bundle
9 courses, one price
$245All courses in this bundle with a one-time payment
- 9 courses included
- 104 hours of 4K content
- All PDF slides
- Free updates
- Lifetime access
- Access to the private Rock the JVM community
Scala Macros and Metaprogramming
Lifetime license
$95Just this course with a one-time payment
- 13 hours of 4K content
- All PDF slides
- Free updates
- Lifetime access
- Access to the private Rock the JVM community
100% Money Back Guarantee
If you're not happy with this course, I want you to have your money back. Contact me with a copy of your welcome email and I will refund you.
Less than 0.05% of students have ever asked for a refund — and every payment was returned in under 72 hours.