SlideShare a Scribd company logo
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

More Related Content

PPTX
Android Malware 2020 (CCCS-CIC-AndMal-2020)
PPTX
GoogLeNet.pptx
PPTX
Ai chatbot ppt.pptx
PDF
Deep Learning and CNN Architectures
PPTX
CAPTCHA and Convolutional neural network
PDF
Introduction to Deep Learning (NVIDIA)
PPT
Cognitive architecture
DOCX
Case study on deep learning
Android Malware 2020 (CCCS-CIC-AndMal-2020)
GoogLeNet.pptx
Ai chatbot ppt.pptx
Deep Learning and CNN Architectures
CAPTCHA and Convolutional neural network
Introduction to Deep Learning (NVIDIA)
Cognitive architecture
Case study on deep learning

What's hot (20)

PPTX
Convolutional neural network from VGG to DenseNet
PPTX
[AIoTLab]attention mechanism.pptx
PDF
ROCm and Distributed Deep Learning on Spark and TensorFlow
PDF
Machine Learning and its types - Internship Presentation - week 8
PDF
Python in Computer Vision
PPTX
Android Battery optimization Android Apps
PDF
Understanding Convolutional Neural Networks
PDF
Introduction to Deep Learning
PPTX
Resnet.pptx
PPTX
Credit card fraud detection using machine learning Algorithms
PDF
Zero shot-learning: paper presentation
PPTX
TOWARDS DETECTION CYBER ATTACKS PPT 1.pptx
PDF
[232] TensorRT를 활용한 딥러닝 Inference 최적화
PDF
3D 딥러닝 동향
PPTX
Virtual mouse
PDF
強化學習 Reinforcement Learning
PPTX
Introduction to PyTorch
PDF
Introduction to TensorFlow
PPTX
Graph Representation Learning
PPTX
Object detection presentation
Convolutional neural network from VGG to DenseNet
[AIoTLab]attention mechanism.pptx
ROCm and Distributed Deep Learning on Spark and TensorFlow
Machine Learning and its types - Internship Presentation - week 8
Python in Computer Vision
Android Battery optimization Android Apps
Understanding Convolutional Neural Networks
Introduction to Deep Learning
Resnet.pptx
Credit card fraud detection using machine learning Algorithms
Zero shot-learning: paper presentation
TOWARDS DETECTION CYBER ATTACKS PPT 1.pptx
[232] TensorRT를 활용한 딥러닝 Inference 최적화
3D 딥러닝 동향
Virtual mouse
強化學習 Reinforcement Learning
Introduction to PyTorch
Introduction to TensorFlow
Graph Representation Learning
Object detection presentation
Ad

Viewers also liked (17)

PPTX
How to build a virtual machine
PPTX
Dc machines electrical machines – i
PPTX
Dynamic analysis of dc machine
PPT
Gas turbine-power-plant[1]
ZIP
Ai Slides
PDF
Basics of Electrical Machines
PPTX
Dynamic and Static Modeling
PPT
Distributed Generation
PDF
Electrical Machines Notes
PPTX
Electric machine
PPTX
power plant engineering
PDF
Electric power transmission system engineering 2nd edition by turan gonen
PPT
Lecture 25 induction. faradays law. lenz law
PDF
Power plant engineering complete five unit vtu notes pdf download
PPTX
12.1 - Lenz's law
PPT
Powerpoint presentation about lenz's law
PPT
Data acquisition system (DAS)
How to build a virtual machine
Dc machines electrical machines – i
Dynamic analysis of dc machine
Gas turbine-power-plant[1]
Ai Slides
Basics of Electrical Machines
Dynamic and Static Modeling
Distributed Generation
Electrical Machines Notes
Electric machine
power plant engineering
Electric power transmission system engineering 2nd edition by turan gonen
Lecture 25 induction. faradays law. lenz law
Power plant engineering complete five unit vtu notes pdf download
12.1 - Lenz's law
Powerpoint presentation about lenz's law
Data acquisition system (DAS)
Ad

Similar to Static vs dynamic types (20)

PDF
Flow or Type - how to React to that?
PDF
DTS s03e04 Typing
PPTX
Modern_2.pptx for java
ODP
Introduction To Scala
PDF
From Java to Python: beating the Stockholm syndrome
PPTX
Tools for the Toolmakers
PDF
A Brief Introduction to Scala for Java Developers
PDF
Miles Sabin Introduction To Scala For Java Developers
PPTX
Functions, List and String methods
PPTX
UNIT 1 .pptx
PDF
Unsafe to typesafe
PPTX
Integrating Python with SQL (12345).pptx
PPTX
Typescript: Beginner to Advanced
ODP
Programming Under Linux In Python
ODP
Dynamic Python
PPT
Introduction to phython programming
PDF
Milano JS Meetup - Gabriele Petronella - Codemotion Milan 2016
PDF
BCS SPA 2010 - An Introduction to Scala for Java Developers
PDF
An Introduction to Scala for Java Developers
PPTX
Full CSE 310 Unit 1 PPT.pptx for java language
Flow or Type - how to React to that?
DTS s03e04 Typing
Modern_2.pptx for java
Introduction To Scala
From Java to Python: beating the Stockholm syndrome
Tools for the Toolmakers
A Brief Introduction to Scala for Java Developers
Miles Sabin Introduction To Scala For Java Developers
Functions, List and String methods
UNIT 1 .pptx
Unsafe to typesafe
Integrating Python with SQL (12345).pptx
Typescript: Beginner to Advanced
Programming Under Linux In Python
Dynamic Python
Introduction to phython programming
Milano JS Meetup - Gabriele Petronella - Codemotion Milan 2016
BCS SPA 2010 - An Introduction to Scala for Java Developers
An Introduction to Scala for Java Developers
Full CSE 310 Unit 1 PPT.pptx for java language

Recently uploaded (20)

PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
MYSQL Presentation for SQL database connectivity
PPT
Teaching material agriculture food technology
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Approach and Philosophy of On baking technology
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
KodekX | Application Modernization Development
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
MIND Revenue Release Quarter 2 2025 Press Release
MYSQL Presentation for SQL database connectivity
Teaching material agriculture food technology
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
The AUB Centre for AI in Media Proposal.docx
Approach and Philosophy of On baking technology
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Understanding_Digital_Forensics_Presentation.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
Unlocking AI with Model Context Protocol (MCP)
KodekX | Application Modernization Development
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Encapsulation_ Review paper, used for researhc scholars
Chapter 3 Spatial Domain Image Processing.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?

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