SlideShare une entreprise Scribd logo
1  sur  14
Télécharger pour lire hors ligne
Computer Language Design and
Implementation meetup March 6, 2014

Cat people vs dog people
The great static vs dynamic typing debate
Terence Parr
University of San Francisco
(You’re all wrong, I’m right)
Definitions

(strong vs weak vs untyped)

● Static typing: compiler knows the type of
every expression (using type inference here)
var i = 3; var j = [“parrt”,”ollie”,”kay”];

● Explicit static typing: coder gives type
int i;
List<String> a = new ArrayList<String>();
Explicit doesn’t
mean “dirty”
var dog : shit
yes, a puppy dies every time you type this
Definitions Cont’d
● Dynamic typing: compiler ignores types,
values’ types known only at runtime
● “Duck typing”: structural dynamic typing; i.e.,
the name (nominative) doesn’t matter, only
the member list (Java uses interfaces)
class A: {var name}
class B: {var name}
def f(x): {print x.name}

f(new A())
f(new B())
Eric Lippert from stackoverflow
● “it is hard to maintain a large codebase, period”
● “there is a strong correlation between a language
being dynamically typed and a language also lacking
all the other facilities that make lowering the cost of
maintaining a large codebase easier”

● So, to focus on static versus dynamic
argument, let’s assume...
Assumptions
● Comparing two identical languages, one with
and one w/o static typing
● Language has modern facilities to support
large projects: modules, perhaps objects,
encapsulation, data hiding, etc…
○ E.g., javascript missing lots of that

● Large projects not small scripts
Can we agree...
● Coder must know (partial) types statically or
(s)he can’t access appropriate fields, funcs:
o.name, o.save()
● With perfect human memory of your own
code, no explicit types needed...
● ...but what if we call foreign library function
or work on a team (i.e., all of us)?
● Must read lib code or doc to learn types
Reality
● Can’t remember type of all vars/funcs in
large project (even solo project)
● We have to read lots of code every day
○ We work in teams
○ We use lots of libraries
○ Either we compute type or we read annotation

● Code always morphs over time
○ Explicit type info identifies key variable constraints
○ Code changes but do we update doc always?
Static typing burdens
1. Much faster to physically enter code w/o annotating
variables with type info (don’t overestimate this cost)
2. Type annotations can clutter code
3. Harder for newbies to get rolling?
4. Type systems can add a lot of complexity to the
language: Java’s generics, Scala, ...
5. Python (others) has structural type equivalence (duck
typing) vs nominative (naming) for most static
languages
○ Convenient if we care just that obj answers size()
○ Java requires creation of an interface
Dynamic typing burdens
● We exchange type annotation in code with
unit/functional testing just to catch typos o.
feild, o.methud(). More tests in general
● Should informally add type info in doc, a 2nd
spec we must keep in sync
● Lippert: Need “good discipline about naming
conventions, about division of responsibilities, about
what the public surface of a given object is, and so on.”
Dynamic typing collateral damage
● Often less efficient
● Re-factoring challenging, dangerous, or
impossible; can’t even rename safely
● Can’t do auto-completion, find
usages/implementations, …
● Changes to type assumptions (in libs, code)
introduce hidden landmines
● Can be more effort to read (computing
A compromise
● Annotate: fields (unless initialized), args,
return values
● Generics only on built-in types?
● At the very least, use runtime generic type
parameters to allow covariance
List<? extends Animal> d=...;
d.add(new Dog());

● Type inference inside method bodies
● Allow plausible downcasting
Jesus cries every time javac disallows this
Sample compromise class
class Person { … }
class User : Person {
val BADID = 0
var id : string
def permissions(name : string) : int {
val m = Services.getFileManager()
val f = m.getFile(name)
return f.permissions(this.id)
}
}
var p : Person = new User()
var mask = p.permissions(new file(“...”)) // downcast
Speculation
● Static typing is seen as old-school. Younger
programmers are always excited by the latest
languages and these languages happen to be
dynamically typed: JavaScript, Python, Ruby. Scala
is the counterexample (others?)
● With experience, comes the pain of maintenance
which motivates static typing
● I.e., there is a strong correlation between dynamic
typing and youth
Summary
● Static + inferred typing is good, umkay?
● Dynamic typing is great for scripts but not
large programs, umkay?
● Yes, we old farts rely more and more on
static typing as our brains disintegrate
● People study this empirically
see e.g., Andreas Stefik

Contenu connexe

Tendances

New c sharp4_features_part_v
New c sharp4_features_part_vNew c sharp4_features_part_v
New c sharp4_features_part_vNico Ludwig
 
My 10 favorite Haxe language features - Francis Bourre - Codemotion Rome 2017
My 10 favorite Haxe language features - Francis Bourre - Codemotion Rome 2017My 10 favorite Haxe language features - Francis Bourre - Codemotion Rome 2017
My 10 favorite Haxe language features - Francis Bourre - Codemotion Rome 2017Codemotion
 
Python-00 | Introduction and installing
Python-00 | Introduction and installingPython-00 | Introduction and installing
Python-00 | Introduction and installingMohd Sajjad
 
java in Aartificial intelligent by virat andodariya
java in Aartificial intelligent by virat andodariyajava in Aartificial intelligent by virat andodariya
java in Aartificial intelligent by virat andodariyaviratandodariya
 
Grooming with Groovy
Grooming with GroovyGrooming with Groovy
Grooming with GroovyDhaval Dalal
 
Daniele Esposti - Evolution or stagnation programming languages - Codemotion ...
Daniele Esposti - Evolution or stagnation programming languages - Codemotion ...Daniele Esposti - Evolution or stagnation programming languages - Codemotion ...
Daniele Esposti - Evolution or stagnation programming languages - Codemotion ...Codemotion
 
Daniele Esposti - Evolution or stagnation programming languages - Codemotion ...
Daniele Esposti - Evolution or stagnation programming languages - Codemotion ...Daniele Esposti - Evolution or stagnation programming languages - Codemotion ...
Daniele Esposti - Evolution or stagnation programming languages - Codemotion ...Codemotion
 
Python final presentation kirti ppt1
Python final presentation kirti ppt1Python final presentation kirti ppt1
Python final presentation kirti ppt1Kirti Verma
 
Typescript: enjoying large scale browser development
Typescript: enjoying large scale browser developmentTypescript: enjoying large scale browser development
Typescript: enjoying large scale browser developmentJoost de Vries
 
Not Everything Is An Object
Not Everything Is An ObjectNot Everything Is An Object
Not Everything Is An ObjectGary Short
 
Number of Computer Languages = 3
Number of Computer Languages = 3Number of Computer Languages = 3
Number of Computer Languages = 3Ram Sekhar
 
Elixir Brasil 2019 - Quality: A Panacéia para seu código Elixir
Elixir Brasil 2019 - Quality:  A Panacéia para seu código ElixirElixir Brasil 2019 - Quality:  A Panacéia para seu código Elixir
Elixir Brasil 2019 - Quality: A Panacéia para seu código ElixirWeverton Timoteo
 
An Introduction to Python Programming
An Introduction to Python ProgrammingAn Introduction to Python Programming
An Introduction to Python ProgrammingMorteza Zakeri
 
Packer Genetics: The selfish code
Packer Genetics: The selfish codePacker Genetics: The selfish code
Packer Genetics: The selfish codejduart
 

Tendances (20)

New c sharp4_features_part_v
New c sharp4_features_part_vNew c sharp4_features_part_v
New c sharp4_features_part_v
 
My 10 favorite Haxe language features - Francis Bourre - Codemotion Rome 2017
My 10 favorite Haxe language features - Francis Bourre - Codemotion Rome 2017My 10 favorite Haxe language features - Francis Bourre - Codemotion Rome 2017
My 10 favorite Haxe language features - Francis Bourre - Codemotion Rome 2017
 
Programming
ProgrammingProgramming
Programming
 
Python for All
Python for All Python for All
Python for All
 
Python-00 | Introduction and installing
Python-00 | Introduction and installingPython-00 | Introduction and installing
Python-00 | Introduction and installing
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
ANTLR4 in depth
ANTLR4 in depthANTLR4 in depth
ANTLR4 in depth
 
java in Aartificial intelligent by virat andodariya
java in Aartificial intelligent by virat andodariyajava in Aartificial intelligent by virat andodariya
java in Aartificial intelligent by virat andodariya
 
Grooming with Groovy
Grooming with GroovyGrooming with Groovy
Grooming with Groovy
 
Daniele Esposti - Evolution or stagnation programming languages - Codemotion ...
Daniele Esposti - Evolution or stagnation programming languages - Codemotion ...Daniele Esposti - Evolution or stagnation programming languages - Codemotion ...
Daniele Esposti - Evolution or stagnation programming languages - Codemotion ...
 
Daniele Esposti - Evolution or stagnation programming languages - Codemotion ...
Daniele Esposti - Evolution or stagnation programming languages - Codemotion ...Daniele Esposti - Evolution or stagnation programming languages - Codemotion ...
Daniele Esposti - Evolution or stagnation programming languages - Codemotion ...
 
Python final presentation kirti ppt1
Python final presentation kirti ppt1Python final presentation kirti ppt1
Python final presentation kirti ppt1
 
Typescript: enjoying large scale browser development
Typescript: enjoying large scale browser developmentTypescript: enjoying large scale browser development
Typescript: enjoying large scale browser development
 
Not Everything Is An Object
Not Everything Is An ObjectNot Everything Is An Object
Not Everything Is An Object
 
Number of Computer Languages = 3
Number of Computer Languages = 3Number of Computer Languages = 3
Number of Computer Languages = 3
 
C Course Material0209
C Course Material0209C Course Material0209
C Course Material0209
 
Elixir Brasil 2019 - Quality: A Panacéia para seu código Elixir
Elixir Brasil 2019 - Quality:  A Panacéia para seu código ElixirElixir Brasil 2019 - Quality:  A Panacéia para seu código Elixir
Elixir Brasil 2019 - Quality: A Panacéia para seu código Elixir
 
An Introduction to Python Programming
An Introduction to Python ProgrammingAn Introduction to Python Programming
An Introduction to Python Programming
 
Python master class 2
Python master class 2Python master class 2
Python master class 2
 
Packer Genetics: The selfish code
Packer Genetics: The selfish codePacker Genetics: The selfish code
Packer Genetics: The selfish code
 

En vedette

How to build a virtual machine
How to build a virtual machineHow to build a virtual machine
How to build a virtual machineTerence Parr
 
Dc machines electrical machines – i
Dc machines   electrical machines – iDc machines   electrical machines – i
Dc machines electrical machines – iSoumyadeep Nag
 
Dynamic analysis of dc machine
Dynamic analysis of dc machineDynamic analysis of dc machine
Dynamic analysis of dc machineRamesh Babu
 
Gas turbine-power-plant[1]
Gas turbine-power-plant[1]Gas turbine-power-plant[1]
Gas turbine-power-plant[1]Manish Sadhu
 
Basics of Electrical Machines
Basics of Electrical MachinesBasics of Electrical Machines
Basics of Electrical Machinesmaneesh001
 
Dynamic and Static Modeling
Dynamic and Static ModelingDynamic and Static Modeling
Dynamic and Static ModelingSaurabh Kumar
 
Electric machine
Electric machineElectric machine
Electric machineashok261084
 
power plant engineering
power plant engineeringpower plant engineering
power plant engineeringGulfaraz alam
 
Electric power transmission system engineering 2nd edition by turan gonen
Electric power transmission system engineering  2nd edition by turan gonenElectric power transmission system engineering  2nd edition by turan gonen
Electric power transmission system engineering 2nd edition by turan gonenUmmi Robbania Mushthofa
 
Power plant engineering complete five unit vtu notes pdf download
Power plant engineering complete five unit vtu notes pdf downloadPower plant engineering complete five unit vtu notes pdf download
Power plant engineering complete five unit vtu notes pdf downloadkiran555555
 
12.1 - Lenz's law
12.1  - Lenz's law12.1  - Lenz's law
12.1 - Lenz's lawsimonandisa
 
Powerpoint presentation about lenz's law
Powerpoint presentation about lenz's lawPowerpoint presentation about lenz's law
Powerpoint presentation about lenz's lawrdelizoneyou
 
Data acquisition system (DAS)
Data acquisition system (DAS)Data acquisition system (DAS)
Data acquisition system (DAS)Sumeet Patel
 

En vedette (17)

How to build a virtual machine
How to build a virtual machineHow to build a virtual machine
How to build a virtual machine
 
Dc machines electrical machines – i
Dc machines   electrical machines – iDc machines   electrical machines – i
Dc machines electrical machines – i
 
Dynamic analysis of dc machine
Dynamic analysis of dc machineDynamic analysis of dc machine
Dynamic analysis of dc machine
 
Gas turbine-power-plant[1]
Gas turbine-power-plant[1]Gas turbine-power-plant[1]
Gas turbine-power-plant[1]
 
Ai Slides
Ai SlidesAi Slides
Ai Slides
 
Basics of Electrical Machines
Basics of Electrical MachinesBasics of Electrical Machines
Basics of Electrical Machines
 
Dynamic and Static Modeling
Dynamic and Static ModelingDynamic and Static Modeling
Dynamic and Static Modeling
 
Distributed Generation
Distributed Generation Distributed Generation
Distributed Generation
 
Electrical Machines Notes
Electrical Machines NotesElectrical Machines Notes
Electrical Machines Notes
 
Electric machine
Electric machineElectric machine
Electric machine
 
power plant engineering
power plant engineeringpower plant engineering
power plant engineering
 
Electric power transmission system engineering 2nd edition by turan gonen
Electric power transmission system engineering  2nd edition by turan gonenElectric power transmission system engineering  2nd edition by turan gonen
Electric power transmission system engineering 2nd edition by turan gonen
 
Lecture 25 induction. faradays law. lenz law
Lecture 25   induction. faradays law. lenz lawLecture 25   induction. faradays law. lenz law
Lecture 25 induction. faradays law. lenz law
 
Power plant engineering complete five unit vtu notes pdf download
Power plant engineering complete five unit vtu notes pdf downloadPower plant engineering complete five unit vtu notes pdf download
Power plant engineering complete five unit vtu notes pdf download
 
12.1 - Lenz's law
12.1  - Lenz's law12.1  - Lenz's law
12.1 - Lenz's law
 
Powerpoint presentation about lenz's law
Powerpoint presentation about lenz's lawPowerpoint presentation about lenz's law
Powerpoint presentation about lenz's law
 
Data acquisition system (DAS)
Data acquisition system (DAS)Data acquisition system (DAS)
Data acquisition system (DAS)
 

Similaire à Static vs dynamic types

Flow or Type - how to React to that?
Flow or Type - how to React to that?Flow or Type - how to React to that?
Flow or Type - how to React to that?Krešimir Antolić
 
Modern_2.pptx for java
Modern_2.pptx for java Modern_2.pptx for java
Modern_2.pptx for java MayaTofik
 
Introduction To Scala
Introduction To ScalaIntroduction To Scala
Introduction To ScalaBasuk
 
From Java to Python: beating the Stockholm syndrome
From Java to Python: beating the Stockholm syndromeFrom Java to Python: beating the Stockholm syndrome
From Java to Python: beating the Stockholm syndromeJavier Arias Losada
 
Tools for the Toolmakers
Tools for the ToolmakersTools for the Toolmakers
Tools for the ToolmakersCaleb Callaway
 
A Brief Introduction to Scala for Java Developers
A Brief Introduction to Scala for Java DevelopersA Brief Introduction to Scala for Java Developers
A Brief Introduction to Scala for Java DevelopersMiles Sabin
 
Miles Sabin Introduction To Scala For Java Developers
Miles Sabin Introduction To Scala For Java DevelopersMiles Sabin Introduction To Scala For Java Developers
Miles Sabin Introduction To Scala For Java DevelopersSkills Matter
 
Functions, List and String methods
Functions, List and String methodsFunctions, List and String methods
Functions, List and String methodsPranavSB
 
Unsafe to typesafe
Unsafe to typesafeUnsafe to typesafe
Unsafe to typesaferegisleray
 
Typescript: Beginner to Advanced
Typescript: Beginner to AdvancedTypescript: Beginner to Advanced
Typescript: Beginner to AdvancedTalentica Software
 
Programming Under Linux In Python
Programming Under Linux In PythonProgramming Under Linux In Python
Programming Under Linux In PythonMarwan Osman
 
Introduction to phython programming
Introduction to phython programmingIntroduction to phython programming
Introduction to phython programmingASIT Education
 
Milano JS Meetup - Gabriele Petronella - Codemotion Milan 2016
Milano JS Meetup -  Gabriele Petronella - Codemotion Milan 2016Milano JS Meetup -  Gabriele Petronella - Codemotion Milan 2016
Milano JS Meetup - Gabriele Petronella - Codemotion Milan 2016Codemotion
 
BCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java DevelopersBCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java DevelopersMiles Sabin
 
An Introduction to Scala for Java Developers
An Introduction to Scala for Java DevelopersAn Introduction to Scala for Java Developers
An Introduction to Scala for Java DevelopersMiles Sabin
 
Full CSE 310 Unit 1 PPT.pptx for java language
Full CSE 310 Unit 1 PPT.pptx for java languageFull CSE 310 Unit 1 PPT.pptx for java language
Full CSE 310 Unit 1 PPT.pptx for java languagessuser2963071
 
Python (3).pdf
Python (3).pdfPython (3).pdf
Python (3).pdfsamiwaris2
 
Static types on javascript?! Type checking approaches to ensure healthy appli...
Static types on javascript?! Type checking approaches to ensure healthy appli...Static types on javascript?! Type checking approaches to ensure healthy appli...
Static types on javascript?! Type checking approaches to ensure healthy appli...Arthur Puthin
 
Python: an introduction for PHP webdevelopers
Python: an introduction for PHP webdevelopersPython: an introduction for PHP webdevelopers
Python: an introduction for PHP webdevelopersGlenn De Backer
 

Similaire à Static vs dynamic types (20)

Flow or Type - how to React to that?
Flow or Type - how to React to that?Flow or Type - how to React to that?
Flow or Type - how to React to that?
 
Modern_2.pptx for java
Modern_2.pptx for java Modern_2.pptx for java
Modern_2.pptx for java
 
Introduction To Scala
Introduction To ScalaIntroduction To Scala
Introduction To Scala
 
From Java to Python: beating the Stockholm syndrome
From Java to Python: beating the Stockholm syndromeFrom Java to Python: beating the Stockholm syndrome
From Java to Python: beating the Stockholm syndrome
 
Tools for the Toolmakers
Tools for the ToolmakersTools for the Toolmakers
Tools for the Toolmakers
 
A Brief Introduction to Scala for Java Developers
A Brief Introduction to Scala for Java DevelopersA Brief Introduction to Scala for Java Developers
A Brief Introduction to Scala for Java Developers
 
Miles Sabin Introduction To Scala For Java Developers
Miles Sabin Introduction To Scala For Java DevelopersMiles Sabin Introduction To Scala For Java Developers
Miles Sabin Introduction To Scala For Java Developers
 
Functions, List and String methods
Functions, List and String methodsFunctions, List and String methods
Functions, List and String methods
 
Unsafe to typesafe
Unsafe to typesafeUnsafe to typesafe
Unsafe to typesafe
 
Typescript: Beginner to Advanced
Typescript: Beginner to AdvancedTypescript: Beginner to Advanced
Typescript: Beginner to Advanced
 
Programming Under Linux In Python
Programming Under Linux In PythonProgramming Under Linux In Python
Programming Under Linux In Python
 
Dynamic Python
Dynamic PythonDynamic Python
Dynamic Python
 
Introduction to phython programming
Introduction to phython programmingIntroduction to phython programming
Introduction to phython programming
 
Milano JS Meetup - Gabriele Petronella - Codemotion Milan 2016
Milano JS Meetup -  Gabriele Petronella - Codemotion Milan 2016Milano JS Meetup -  Gabriele Petronella - Codemotion Milan 2016
Milano JS Meetup - Gabriele Petronella - Codemotion Milan 2016
 
BCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java DevelopersBCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java Developers
 
An Introduction to Scala for Java Developers
An Introduction to Scala for Java DevelopersAn Introduction to Scala for Java Developers
An Introduction to Scala for Java Developers
 
Full CSE 310 Unit 1 PPT.pptx for java language
Full CSE 310 Unit 1 PPT.pptx for java languageFull CSE 310 Unit 1 PPT.pptx for java language
Full CSE 310 Unit 1 PPT.pptx for java language
 
Python (3).pdf
Python (3).pdfPython (3).pdf
Python (3).pdf
 
Static types on javascript?! Type checking approaches to ensure healthy appli...
Static types on javascript?! Type checking approaches to ensure healthy appli...Static types on javascript?! Type checking approaches to ensure healthy appli...
Static types on javascript?! Type checking approaches to ensure healthy appli...
 
Python: an introduction for PHP webdevelopers
Python: an introduction for PHP webdevelopersPython: an introduction for PHP webdevelopers
Python: an introduction for PHP webdevelopers
 

Dernier

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 

Dernier (20)

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 

Static vs dynamic types

  • 1. Computer Language Design and Implementation meetup March 6, 2014 Cat people vs dog people The great static vs dynamic typing debate Terence Parr University of San Francisco (You’re all wrong, I’m right)
  • 2. Definitions (strong vs weak vs untyped) ● Static typing: compiler knows the type of every expression (using type inference here) var i = 3; var j = [“parrt”,”ollie”,”kay”]; ● Explicit static typing: coder gives type int i; List<String> a = new ArrayList<String>(); Explicit doesn’t mean “dirty” var dog : shit yes, a puppy dies every time you type this
  • 3. Definitions Cont’d ● Dynamic typing: compiler ignores types, values’ types known only at runtime ● “Duck typing”: structural dynamic typing; i.e., the name (nominative) doesn’t matter, only the member list (Java uses interfaces) class A: {var name} class B: {var name} def f(x): {print x.name} f(new A()) f(new B())
  • 4. Eric Lippert from stackoverflow ● “it is hard to maintain a large codebase, period” ● “there is a strong correlation between a language being dynamically typed and a language also lacking all the other facilities that make lowering the cost of maintaining a large codebase easier” ● So, to focus on static versus dynamic argument, let’s assume...
  • 5. Assumptions ● Comparing two identical languages, one with and one w/o static typing ● Language has modern facilities to support large projects: modules, perhaps objects, encapsulation, data hiding, etc… ○ E.g., javascript missing lots of that ● Large projects not small scripts
  • 6. Can we agree... ● Coder must know (partial) types statically or (s)he can’t access appropriate fields, funcs: o.name, o.save() ● With perfect human memory of your own code, no explicit types needed... ● ...but what if we call foreign library function or work on a team (i.e., all of us)? ● Must read lib code or doc to learn types
  • 7. Reality ● Can’t remember type of all vars/funcs in large project (even solo project) ● We have to read lots of code every day ○ We work in teams ○ We use lots of libraries ○ Either we compute type or we read annotation ● Code always morphs over time ○ Explicit type info identifies key variable constraints ○ Code changes but do we update doc always?
  • 8. Static typing burdens 1. Much faster to physically enter code w/o annotating variables with type info (don’t overestimate this cost) 2. Type annotations can clutter code 3. Harder for newbies to get rolling? 4. Type systems can add a lot of complexity to the language: Java’s generics, Scala, ... 5. Python (others) has structural type equivalence (duck typing) vs nominative (naming) for most static languages ○ Convenient if we care just that obj answers size() ○ Java requires creation of an interface
  • 9. Dynamic typing burdens ● We exchange type annotation in code with unit/functional testing just to catch typos o. feild, o.methud(). More tests in general ● Should informally add type info in doc, a 2nd spec we must keep in sync ● Lippert: Need “good discipline about naming conventions, about division of responsibilities, about what the public surface of a given object is, and so on.”
  • 10. Dynamic typing collateral damage ● Often less efficient ● Re-factoring challenging, dangerous, or impossible; can’t even rename safely ● Can’t do auto-completion, find usages/implementations, … ● Changes to type assumptions (in libs, code) introduce hidden landmines ● Can be more effort to read (computing
  • 11. A compromise ● Annotate: fields (unless initialized), args, return values ● Generics only on built-in types? ● At the very least, use runtime generic type parameters to allow covariance List<? extends Animal> d=...; d.add(new Dog()); ● Type inference inside method bodies ● Allow plausible downcasting Jesus cries every time javac disallows this
  • 12. Sample compromise class class Person { … } class User : Person { val BADID = 0 var id : string def permissions(name : string) : int { val m = Services.getFileManager() val f = m.getFile(name) return f.permissions(this.id) } } var p : Person = new User() var mask = p.permissions(new file(“...”)) // downcast
  • 13. Speculation ● Static typing is seen as old-school. Younger programmers are always excited by the latest languages and these languages happen to be dynamically typed: JavaScript, Python, Ruby. Scala is the counterexample (others?) ● With experience, comes the pain of maintenance which motivates static typing ● I.e., there is a strong correlation between dynamic typing and youth
  • 14. Summary ● Static + inferred typing is good, umkay? ● Dynamic typing is great for scripts but not large programs, umkay? ● Yes, we old farts rely more and more on static typing as our brains disintegrate ● People study this empirically see e.g., Andreas Stefik