SlideShare a Scribd company logo
Introduction to
meta-programming in Scala
Alessandro Marrella
About me
● Software Engineer
● Working with Scala professionally for 3
years
● ♡ automating stuff
● ♡ functional programming
● github.com/amarrella
● linkedin.com/in/alessandromarrella
CREDITS
● Ólafur Páll Geirsson (@olafurpg)
● Scala Center / EPFL (scala.epfl.ch)
● Twitter
+ many other contributors in the Scala
community
Meta-programming
● Treating other programs as Data
● Ability to
○ Read
○ Generate
other programs
WHY?
● Reduce lines of code & dev time
● Reduce boilerplate, errors and boring stuff
○ Transform
○ Analyze
Scalameta
● Library to read, analyze, transform and generate Scala
programs
○ Syntactic API: parse, transform & prettyprint
○ Semantic API: understand symbols and types
● Ecosystem
○ Scalameta (Trees & SemanticDB)
○ Scalafmt: code formatting
○ Scalafix: code linting & rewriting
○ Metals: language server
& more( scalameta.org/docs/misc/built-with-scalameta.html )
Syntax trees
Syntax trees
1
Lit.Int(1)
Syntax trees
1+1
Lit.Int(1)Lit.Int(1)
Term.ApplyInfix
Term.Name("+")
Syntax trees
val x: Int = 1+1
Lit.Int(1)Lit.Int(1)
Term.ApplyInfix
Term.Name("+")
Defn.Val
Patn.Var
Term.Name(“x”)
Type.Name
Syntax trees
object Main { val x: Int = 1+1 }
Lit.Int(1)Lit.Int(1)
Term.ApplyInfix
Term.Name("+")
Defn.Val
Patn.Var
Term.Name(“x”)
TemplateTerm.Name(“Main”)
Defn.Object
Type.Name
Syntax trees: from tree to code
object Main { }
Lit.Int(1)Lit.Int(1)
Term.ApplyInfix
Term.Name("+")
Defn.Val
Patn.Var
Term.Name(“x”)
TemplateTerm.Name(“Main”)
Defn.Object
Type.Name
Syntax trees: from tree to code
object Main { val x: Int }
Lit.Int(1)Lit.Int(1)
Term.ApplyInfix
Term.Name("+")
Defn.Val
Patn.Var
Term.Name(“x”)
TemplateTerm.Name(“Main”)
Defn.Object
Type.Name
Syntax trees: from tree to code
object Main { val x: Int = 1 + 1 }
Lit.Int(1)Lit.Int(1)
Term.ApplyInfix
Term.Name("+")
Defn.Val
Patn.Var
Term.Name(“x”)
TemplateTerm.Name(“Main”)
Defn.Object
Type.Name
Scalameta
● Scalameta Trees are lossless
● Scalafmt: uses trees to figure out how to
format
● Scalafix: uses trees to apply syntactic
rules (more later)
● Explicit syntax or quasiquotes
q”object $name { val $val: $t = $expr }”
https://scalameta.org/docs/trees/guide.html
SemanticDB
● Compiles scala
programs to
semantic
information
● Decouples producing
and consuming
semantic
information
SemanticDB
package com.alessandromarrella.presentation
import cats.effect.IO
object IOExample {
val x = IO(println("Hello world"))
}
SemanticDB Summary:
Schema => SemanticDB v4
Uri =>
src/main/scala/com/alessandro
marrella/presentation/IOExamp
le.scala
Text => empty
Language => Scala
Symbols => 2 entries
Occurrences => 11 entries
package com.alessandromarrella.presentation
import cats.effect.IO
object IOExample {
val x = IO(println("Hello world"))
}
SemanticDB
Symbols:
com/alessandromarrella/presen
tation/IOExample. => final
object IOExample extends
AnyRef { +1 decls }
com/alessandromarrella/presen
tation/IOExample.x. => val
method x: IO[Unit]
package com.alessandromarrella.presentation
import cats.effect.IO
object IOExample {
val x = IO(println("Hello world"))
}
SemanticDB
Occurrences:
[0:8..0:11) => com/
[0:12..0:30) =>
com/alessandromarrella/
[0:31..0:43) =>
com/alessandromarrella/presen
tation/
package com.alessandromarrella.presentation
import cats.effect.IO
object IOExample {
val x = IO(println("Hello world"))
}
position
SemanticDB
Occurrences:
[2:7..2:11) => cats/
[2:12..2:18) => cats/effect/
[2:19..2:21) =>
cats/effect/IO#
[2:19..2:21) =>
cats/effect/IO.
package com.alessandromarrella.presentation
import cats.effect.IO
object IOExample {
val x = IO(println("Hello world"))
}
<- class
<- object
SemanticDB Occurrences:
[4:7..4:16) <=
com/alessandromarrella/presen
tation/IOExample.
[6:8..6:9) <=
com/alessandromarrella/presen
tation/IOExample.x.
[6:12..6:14) =>
cats/effect/IO.
[6:15..6:22) =>
scala/Predef.println(+1).
package com.alessandromarrella.presentation
import cats.effect.IO
object IOExample {
val x = IO(println("Hello world"))
}
It “knows”
Method overload
SemanticDB
● Compiles the program to a SemanticDB file
● Symbol information
● Disambiguation
● Scalafix can use it for semantic rules
(more later)
● Metals uses it for code navigation
https://scalameta.org/docs/semanticdb/guide.html
Scalafix
● Refactoring and linting tool
● Syntactic and semantic rules
● As a user:
○ Apply rules
○ Integrate with your CI
● As a dev:
○ Create & publish rules
Applying rules
Add scalafix dependency
project/plugins.sbt
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.1")
Run the rule (e.g. http4s 0.18 to 0.20 upgrade)
$ sbt ";scalafixEnable; scalafix github:http4s/http4s/v0_20"
Creating new rules
Create a new project with the Giter8 template
$ sbt new scalacenter/scalafix.g8
You get a new directory with:
build.sbt readme.md input output rules test
Example: No return Unit rule
def foo(x: Int): Unit
What does calling foo(42) do?
Example: No return Unit rule
def foo(x: Int): Unit
What does calling foo(42) do?
● Nothing
● Performs a side effect
Example: No return Unit rule
def foo(x: Int): Unit
What does calling foo(42) do?
● Nothing
● Performs a side effect
We won’t consider:
● Throwing exceptions
● Returning null
We don’t want the user to be able to return Unit.
Example: No return Unit rule
Demo
https://github.com/amarrella/noreturnunit
Thank you!
hello@alessandromarrella.com
linkedin.com/in/alessandromarrella
twitter.com/amarrella

More Related Content

What's hot

Scala.js: Next generation front end development in Scala
Scala.js:  Next generation front end development in ScalaScala.js:  Next generation front end development in Scala
Scala.js: Next generation front end development in Scala
Otto Chrons
 
Scala cheatsheet
Scala cheatsheetScala cheatsheet
Scala cheatsheet
Arduino Aficionado
 
Be a 10x android developer
Be a 10x android developer Be a 10x android developer
Be a 10x android developer
Shadaï ALI
 
Counters with Riak on Amazon EC2 at Hackover
Counters with Riak on Amazon EC2 at HackoverCounters with Riak on Amazon EC2 at Hackover
Counters with Riak on Amazon EC2 at HackoverAndrei Savu
 
Jug Marche: Meeting June 2014. Java 8 hands on
Jug Marche: Meeting June 2014. Java 8 hands onJug Marche: Meeting June 2014. Java 8 hands on
Jug Marche: Meeting June 2014. Java 8 hands on
Onofrio Panzarino
 
Scala Refactoring for Fun and Profit
Scala Refactoring for Fun and ProfitScala Refactoring for Fun and Profit
Scala Refactoring for Fun and Profit
Tomer Gabel
 
Onyx
OnyxOnyx
Using akka streams to access s3 objects
Using akka streams to access s3 objectsUsing akka streams to access s3 objects
Using akka streams to access s3 objects
Mikhail Girkin
 
Scala on-android
Scala on-androidScala on-android
Scala on-android
lifecoder
 
Presentation on functional data mining at the IGT Cloud meet up at eBay Netanya
Presentation on functional data mining at the IGT Cloud meet up at eBay NetanyaPresentation on functional data mining at the IGT Cloud meet up at eBay Netanya
Presentation on functional data mining at the IGT Cloud meet up at eBay NetanyaChristopher Severs
 
Streams or Loops? Java 8 Stream API by Niki Petkov - Proxiad Bulgaria
Streams or Loops? Java 8 Stream API by Niki Petkov - Proxiad BulgariaStreams or Loops? Java 8 Stream API by Niki Petkov - Proxiad Bulgaria
Streams or Loops? Java 8 Stream API by Niki Petkov - Proxiad Bulgaria
HackBulgaria
 
Haskell for Scala-ists
Haskell for Scala-istsHaskell for Scala-ists
Haskell for Scala-ists
chriseidhof
 
Educational slides by venay magen
Educational slides by venay magenEducational slides by venay magen
Educational slides by venay magen
venaymagen19
 
Collections Framework Begineers guide 2
Collections Framework Begineers guide 2Collections Framework Begineers guide 2
Collections Framework Begineers guide 2
Kenji HASUNUMA
 
ECMAScript 6: A Better JavaScript for the Ambient Computing Era
ECMAScript 6: A Better JavaScript for the Ambient Computing EraECMAScript 6: A Better JavaScript for the Ambient Computing Era
ECMAScript 6: A Better JavaScript for the Ambient Computing Era
Allen Wirfs-Brock
 
Using Onyx in anger
Using Onyx in angerUsing Onyx in anger
Using Onyx in anger
Simon Belak
 
Building Mobile Apps with Android
Building Mobile Apps with AndroidBuilding Mobile Apps with Android
Building Mobile Apps with Android
Kurt Renzo Acosta
 
LINEデリマでのElasticsearchの運用と監視の話
LINEデリマでのElasticsearchの運用と監視の話LINEデリマでのElasticsearchの運用と監視の話
LINEデリマでのElasticsearchの運用と監視の話
LINE Corporation
 
Luis Atencio on RxJS
Luis Atencio on RxJSLuis Atencio on RxJS
Luis Atencio on RxJS
Luis Atencio
 
Introduction To Scala
Introduction To ScalaIntroduction To Scala
Introduction To Scala
Basuk
 

What's hot (20)

Scala.js: Next generation front end development in Scala
Scala.js:  Next generation front end development in ScalaScala.js:  Next generation front end development in Scala
Scala.js: Next generation front end development in Scala
 
Scala cheatsheet
Scala cheatsheetScala cheatsheet
Scala cheatsheet
 
Be a 10x android developer
Be a 10x android developer Be a 10x android developer
Be a 10x android developer
 
Counters with Riak on Amazon EC2 at Hackover
Counters with Riak on Amazon EC2 at HackoverCounters with Riak on Amazon EC2 at Hackover
Counters with Riak on Amazon EC2 at Hackover
 
Jug Marche: Meeting June 2014. Java 8 hands on
Jug Marche: Meeting June 2014. Java 8 hands onJug Marche: Meeting June 2014. Java 8 hands on
Jug Marche: Meeting June 2014. Java 8 hands on
 
Scala Refactoring for Fun and Profit
Scala Refactoring for Fun and ProfitScala Refactoring for Fun and Profit
Scala Refactoring for Fun and Profit
 
Onyx
OnyxOnyx
Onyx
 
Using akka streams to access s3 objects
Using akka streams to access s3 objectsUsing akka streams to access s3 objects
Using akka streams to access s3 objects
 
Scala on-android
Scala on-androidScala on-android
Scala on-android
 
Presentation on functional data mining at the IGT Cloud meet up at eBay Netanya
Presentation on functional data mining at the IGT Cloud meet up at eBay NetanyaPresentation on functional data mining at the IGT Cloud meet up at eBay Netanya
Presentation on functional data mining at the IGT Cloud meet up at eBay Netanya
 
Streams or Loops? Java 8 Stream API by Niki Petkov - Proxiad Bulgaria
Streams or Loops? Java 8 Stream API by Niki Petkov - Proxiad BulgariaStreams or Loops? Java 8 Stream API by Niki Petkov - Proxiad Bulgaria
Streams or Loops? Java 8 Stream API by Niki Petkov - Proxiad Bulgaria
 
Haskell for Scala-ists
Haskell for Scala-istsHaskell for Scala-ists
Haskell for Scala-ists
 
Educational slides by venay magen
Educational slides by venay magenEducational slides by venay magen
Educational slides by venay magen
 
Collections Framework Begineers guide 2
Collections Framework Begineers guide 2Collections Framework Begineers guide 2
Collections Framework Begineers guide 2
 
ECMAScript 6: A Better JavaScript for the Ambient Computing Era
ECMAScript 6: A Better JavaScript for the Ambient Computing EraECMAScript 6: A Better JavaScript for the Ambient Computing Era
ECMAScript 6: A Better JavaScript for the Ambient Computing Era
 
Using Onyx in anger
Using Onyx in angerUsing Onyx in anger
Using Onyx in anger
 
Building Mobile Apps with Android
Building Mobile Apps with AndroidBuilding Mobile Apps with Android
Building Mobile Apps with Android
 
LINEデリマでのElasticsearchの運用と監視の話
LINEデリマでのElasticsearchの運用と監視の話LINEデリマでのElasticsearchの運用と監視の話
LINEデリマでのElasticsearchの運用と監視の話
 
Luis Atencio on RxJS
Luis Atencio on RxJSLuis Atencio on RxJS
Luis Atencio on RxJS
 
Introduction To Scala
Introduction To ScalaIntroduction To Scala
Introduction To Scala
 

Similar to Introduction to meta-programming in scala

What`s New in Java 8
What`s New in Java 8What`s New in Java 8
What`s New in Java 8
Mohsen Zainalpour
 
BASE Meetup: "Analysing Scala Puzzlers: Essential and Accidental Complexity i...
BASE Meetup: "Analysing Scala Puzzlers: Essential and Accidental Complexity i...BASE Meetup: "Analysing Scala Puzzlers: Essential and Accidental Complexity i...
BASE Meetup: "Analysing Scala Puzzlers: Essential and Accidental Complexity i...
Andrew Phillips
 
Scala Up North: "Analysing Scala Puzzlers: Essential and Accidental Complexit...
Scala Up North: "Analysing Scala Puzzlers: Essential and Accidental Complexit...Scala Up North: "Analysing Scala Puzzlers: Essential and Accidental Complexit...
Scala Up North: "Analysing Scala Puzzlers: Essential and Accidental Complexit...
Andrew Phillips
 
New features in jdk8 iti
New features in jdk8 itiNew features in jdk8 iti
New features in jdk8 iti
Ahmed mar3y
 
SCALA - Functional domain
SCALA -  Functional domainSCALA -  Functional domain
SCALA - Functional domain
Bartosz Kosarzycki
 
From Java to Scala - advantages and possible risks
From Java to Scala - advantages and possible risksFrom Java to Scala - advantages and possible risks
From Java to Scala - advantages and possible risks
SeniorDevOnly
 
Kotlin boost yourproductivity
Kotlin boost yourproductivityKotlin boost yourproductivity
Kotlin boost yourproductivity
nklmish
 
Scala coated JVM
Scala coated JVMScala coated JVM
Scala coated JVM
Stuart Roebuck
 
Develop realtime web with Scala and Xitrum
Develop realtime web with Scala and XitrumDevelop realtime web with Scala and Xitrum
Develop realtime web with Scala and Xitrum
Ngoc Dao
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
Martin Odersky
 
Dax Declarative Api For Xml
Dax   Declarative Api For XmlDax   Declarative Api For Xml
Dax Declarative Api For Xml
Lars Trieloff
 
Introduction to clojure
Introduction to clojureIntroduction to clojure
Introduction to clojure
Abbas Raza
 
Scala final ppt vinay
Scala final ppt vinayScala final ppt vinay
Scala final ppt vinay
Viplav Jain
 
What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)
Pavlo Baron
 
Dart the Better JavaScript
Dart the Better JavaScriptDart the Better JavaScript
Dart the Better JavaScript
Jorg Janke
 
Scala is java8.next()
Scala is java8.next()Scala is java8.next()
Scala is java8.next()
daewon jeong
 
Hierarchical free monads and software design in fp
Hierarchical free monads and software design in fpHierarchical free monads and software design in fp
Hierarchical free monads and software design in fp
Alexander Granin
 
Logstash-Elasticsearch-Kibana
Logstash-Elasticsearch-KibanaLogstash-Elasticsearch-Kibana
Logstash-Elasticsearch-Kibana
dknx01
 

Similar to Introduction to meta-programming in scala (20)

What`s New in Java 8
What`s New in Java 8What`s New in Java 8
What`s New in Java 8
 
BASE Meetup: "Analysing Scala Puzzlers: Essential and Accidental Complexity i...
BASE Meetup: "Analysing Scala Puzzlers: Essential and Accidental Complexity i...BASE Meetup: "Analysing Scala Puzzlers: Essential and Accidental Complexity i...
BASE Meetup: "Analysing Scala Puzzlers: Essential and Accidental Complexity i...
 
Scala Up North: "Analysing Scala Puzzlers: Essential and Accidental Complexit...
Scala Up North: "Analysing Scala Puzzlers: Essential and Accidental Complexit...Scala Up North: "Analysing Scala Puzzlers: Essential and Accidental Complexit...
Scala Up North: "Analysing Scala Puzzlers: Essential and Accidental Complexit...
 
New features in jdk8 iti
New features in jdk8 itiNew features in jdk8 iti
New features in jdk8 iti
 
Scala ntnu
Scala ntnuScala ntnu
Scala ntnu
 
SCALA - Functional domain
SCALA -  Functional domainSCALA -  Functional domain
SCALA - Functional domain
 
From Java to Scala - advantages and possible risks
From Java to Scala - advantages and possible risksFrom Java to Scala - advantages and possible risks
From Java to Scala - advantages and possible risks
 
Kotlin boost yourproductivity
Kotlin boost yourproductivityKotlin boost yourproductivity
Kotlin boost yourproductivity
 
Scala coated JVM
Scala coated JVMScala coated JVM
Scala coated JVM
 
Develop realtime web with Scala and Xitrum
Develop realtime web with Scala and XitrumDevelop realtime web with Scala and Xitrum
Develop realtime web with Scala and Xitrum
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
 
Dax Declarative Api For Xml
Dax   Declarative Api For XmlDax   Declarative Api For Xml
Dax Declarative Api For Xml
 
Introduction to clojure
Introduction to clojureIntroduction to clojure
Introduction to clojure
 
Scala final ppt vinay
Scala final ppt vinayScala final ppt vinay
Scala final ppt vinay
 
What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)
 
Dart the Better JavaScript
Dart the Better JavaScriptDart the Better JavaScript
Dart the Better JavaScript
 
Flink internals web
Flink internals web Flink internals web
Flink internals web
 
Scala is java8.next()
Scala is java8.next()Scala is java8.next()
Scala is java8.next()
 
Hierarchical free monads and software design in fp
Hierarchical free monads and software design in fpHierarchical free monads and software design in fp
Hierarchical free monads and software design in fp
 
Logstash-Elasticsearch-Kibana
Logstash-Elasticsearch-KibanaLogstash-Elasticsearch-Kibana
Logstash-Elasticsearch-Kibana
 

Recently uploaded

top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
vrstrong314
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Jay Das
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Anthony Dahanne
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
informapgpstrackings
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
IES VE
 

Recently uploaded (20)

top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 

Introduction to meta-programming in scala

  • 1. Introduction to meta-programming in Scala Alessandro Marrella
  • 2. About me ● Software Engineer ● Working with Scala professionally for 3 years ● ♡ automating stuff ● ♡ functional programming ● github.com/amarrella ● linkedin.com/in/alessandromarrella
  • 3. CREDITS ● Ólafur Páll Geirsson (@olafurpg) ● Scala Center / EPFL (scala.epfl.ch) ● Twitter + many other contributors in the Scala community
  • 4. Meta-programming ● Treating other programs as Data ● Ability to ○ Read ○ Generate other programs WHY? ● Reduce lines of code & dev time ● Reduce boilerplate, errors and boring stuff ○ Transform ○ Analyze
  • 5. Scalameta ● Library to read, analyze, transform and generate Scala programs ○ Syntactic API: parse, transform & prettyprint ○ Semantic API: understand symbols and types ● Ecosystem ○ Scalameta (Trees & SemanticDB) ○ Scalafmt: code formatting ○ Scalafix: code linting & rewriting ○ Metals: language server & more( scalameta.org/docs/misc/built-with-scalameta.html )
  • 9. Syntax trees val x: Int = 1+1 Lit.Int(1)Lit.Int(1) Term.ApplyInfix Term.Name("+") Defn.Val Patn.Var Term.Name(“x”) Type.Name
  • 10. Syntax trees object Main { val x: Int = 1+1 } Lit.Int(1)Lit.Int(1) Term.ApplyInfix Term.Name("+") Defn.Val Patn.Var Term.Name(“x”) TemplateTerm.Name(“Main”) Defn.Object Type.Name
  • 11. Syntax trees: from tree to code object Main { } Lit.Int(1)Lit.Int(1) Term.ApplyInfix Term.Name("+") Defn.Val Patn.Var Term.Name(“x”) TemplateTerm.Name(“Main”) Defn.Object Type.Name
  • 12. Syntax trees: from tree to code object Main { val x: Int } Lit.Int(1)Lit.Int(1) Term.ApplyInfix Term.Name("+") Defn.Val Patn.Var Term.Name(“x”) TemplateTerm.Name(“Main”) Defn.Object Type.Name
  • 13. Syntax trees: from tree to code object Main { val x: Int = 1 + 1 } Lit.Int(1)Lit.Int(1) Term.ApplyInfix Term.Name("+") Defn.Val Patn.Var Term.Name(“x”) TemplateTerm.Name(“Main”) Defn.Object Type.Name
  • 14. Scalameta ● Scalameta Trees are lossless ● Scalafmt: uses trees to figure out how to format ● Scalafix: uses trees to apply syntactic rules (more later) ● Explicit syntax or quasiquotes q”object $name { val $val: $t = $expr }” https://scalameta.org/docs/trees/guide.html
  • 15. SemanticDB ● Compiles scala programs to semantic information ● Decouples producing and consuming semantic information
  • 17. SemanticDB Summary: Schema => SemanticDB v4 Uri => src/main/scala/com/alessandro marrella/presentation/IOExamp le.scala Text => empty Language => Scala Symbols => 2 entries Occurrences => 11 entries package com.alessandromarrella.presentation import cats.effect.IO object IOExample { val x = IO(println("Hello world")) }
  • 18. SemanticDB Symbols: com/alessandromarrella/presen tation/IOExample. => final object IOExample extends AnyRef { +1 decls } com/alessandromarrella/presen tation/IOExample.x. => val method x: IO[Unit] package com.alessandromarrella.presentation import cats.effect.IO object IOExample { val x = IO(println("Hello world")) }
  • 19. SemanticDB Occurrences: [0:8..0:11) => com/ [0:12..0:30) => com/alessandromarrella/ [0:31..0:43) => com/alessandromarrella/presen tation/ package com.alessandromarrella.presentation import cats.effect.IO object IOExample { val x = IO(println("Hello world")) } position
  • 20. SemanticDB Occurrences: [2:7..2:11) => cats/ [2:12..2:18) => cats/effect/ [2:19..2:21) => cats/effect/IO# [2:19..2:21) => cats/effect/IO. package com.alessandromarrella.presentation import cats.effect.IO object IOExample { val x = IO(println("Hello world")) } <- class <- object
  • 21. SemanticDB Occurrences: [4:7..4:16) <= com/alessandromarrella/presen tation/IOExample. [6:8..6:9) <= com/alessandromarrella/presen tation/IOExample.x. [6:12..6:14) => cats/effect/IO. [6:15..6:22) => scala/Predef.println(+1). package com.alessandromarrella.presentation import cats.effect.IO object IOExample { val x = IO(println("Hello world")) } It “knows” Method overload
  • 22. SemanticDB ● Compiles the program to a SemanticDB file ● Symbol information ● Disambiguation ● Scalafix can use it for semantic rules (more later) ● Metals uses it for code navigation https://scalameta.org/docs/semanticdb/guide.html
  • 23. Scalafix ● Refactoring and linting tool ● Syntactic and semantic rules ● As a user: ○ Apply rules ○ Integrate with your CI ● As a dev: ○ Create & publish rules
  • 24. Applying rules Add scalafix dependency project/plugins.sbt addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.1") Run the rule (e.g. http4s 0.18 to 0.20 upgrade) $ sbt ";scalafixEnable; scalafix github:http4s/http4s/v0_20"
  • 25. Creating new rules Create a new project with the Giter8 template $ sbt new scalacenter/scalafix.g8 You get a new directory with: build.sbt readme.md input output rules test
  • 26. Example: No return Unit rule def foo(x: Int): Unit What does calling foo(42) do?
  • 27. Example: No return Unit rule def foo(x: Int): Unit What does calling foo(42) do? ● Nothing ● Performs a side effect
  • 28. Example: No return Unit rule def foo(x: Int): Unit What does calling foo(42) do? ● Nothing ● Performs a side effect We won’t consider: ● Throwing exceptions ● Returning null We don’t want the user to be able to return Unit.
  • 29. Example: No return Unit rule Demo https://github.com/amarrella/noreturnunit