Static Typing or Dynamic Typing: A Real Issue or a Simple Case of Tribalism

Similar documents
Closing the Case for Groovy (and Ruby, and Python)

Them Threads, Them Threads, Them Useless Threads

The Great Language Debate

Topic 9: Type Checking

Topic 9: Type Checking

Tales from the Workshops

Scripted Components: Problem. Scripted Components. Problems with Components. Single-Language Assumption. Dr. James A. Bednar

Scripted Components Dr. James A. Bednar

Programming Languages 2nd edition Tucker and Noonan"

Programming Languages, Summary CSC419; Odelia Schwartz

Dynamically-typed Languages. David Miller

Lecture Overview. [Scott, chapter 7] [Sebesta, chapter 6]

Concepts of Programming Languages

New Programming Paradigms

Topics Covered Thus Far CMSC 330: Organization of Programming Languages

Chapter 9. Subprograms

Topic I. Introduction and motivation References: Chapter 1 of Concepts in programming languages by J. C. Mitchell. CUP, 2003.

CMSC 330: Organization of Programming Languages

9/7/17. Outline. Name, Scope and Binding. Names. Introduction. Names (continued) Names (continued) In Text: Chapter 5

Chapter 5. Names, Bindings, and Scopes

8/27/17. CS-3304 Introduction. What will you learn? Semester Outline. Websites INTRODUCTION TO PROGRAMMING LANGUAGES

! Broaden your language horizons! Different programming languages! Different language features and tradeoffs. ! Study how languages are implemented

Chapter 9. Subprograms

IA010: Principles of Programming Languages

Key components of a lang. Deconstructing OCaml. In OCaml. Units of computation. In Java/Python. In OCaml. Units of computation.

What is programming? Elements of Programming Languages. From machine code to programming languages. What is a programming language?

! Broaden your language horizons. ! Study how languages are implemented. ! Study how languages are described / specified

CS383 PROGRAMMING LANGUAGES. Kenny Q. Zhu Dept. of Computer Science Shanghai Jiao Tong University

Data Types. Every program uses data, either explicitly or implicitly to arrive at a result.


The Trouble with Types

Produced by. Design Patterns. MSc in Computer Science. Eamonn de Leastar

INTRODUCTION PRINCIPLES OF PROGRAMMING LANGUAGES. Norbert Zeh Winter Dalhousie University 1/10

Chapter 5 Names, Binding, Type Checking and Scopes

Type Inference. Prof. Clarkson Fall Today s music: Cool, Calm, and Collected by The Rolling Stones

Concepts in Programming Languages

Programming Languages: Concepts

Programming (ERIM) Lecture 1: Introduction to programming paradigms and typing systems. Tommi Tervonen

Introduction to Engineering Using Robotics Experiments. Dr. Yinong Chen

Smalltalk: developed at Xerox Palo Alto Research Center by the Learning Research Group in the 1970 s (Smalltalk-72, Smalltalk-76, Smalltalk-80)

CSE 341, Autumn 2015, Ruby Introduction Summary

CSE Lecture 3: Objects 2 September Nate Nystrom University of Texas at Arlington

Cunning Plan. One-Slide Summary. Functional Programming. Functional Programming. Introduction to COOL #1. Classroom Object-Oriented Language

Chapter 3.3 Programming Fundamentals. Languages Paradigms Basic Data Types Data Structures OO in Game Design Component Systems Design Patterns

CMSC 330: Organization of Programming Languages. Functional Programming with OCaml

G Programming Languages - Fall 2012

Design issues for objectoriented. languages. Objects-only "pure" language vs mixed. Are subclasses subtypes of the superclass?

Lecture 13: Object orientation. Object oriented programming. Introduction. Object oriented programming. OO and ADT:s. Introduction

Overview. Rationale Division of labour between script and C++ Choice of language(s) Interfacing to C++ Performance, memory

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 17: Types and Type-Checking 25 Feb 08

invokedynamic under the hood

Outline. Introduction Concepts and terminology The case for static typing. Implementing a static type system Basic typing relations Adding context

Topics Covered Thus Far. CMSC 330: Organization of Programming Languages. Language Features Covered Thus Far. Programming Languages Revisited

Semantic Analysis. How to Ensure Type-Safety. What Are Types? Static vs. Dynamic Typing. Type Checking. Last time: CS412/CS413

Functional Programming Principles in Scala. Martin Odersky

Chapter 2 Preview. Preview. History of Programming Languages. History of Programming Languages. History of Programming Languages

Chapter 9 Subprograms

Closures. Mooly Sagiv. Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming

CMSC 4023 Chapter 9. Fundamentals of Subprograms Introduction

COSE212: Programming Languages. Lecture 3 Functional Programming in OCaml

First Programming Language in CS Education The Arguments for Scala

A Tour of Language Implementation

CSc 372 Comparative Programming Languages

Concepts of programming languages

CSE373: Data Structure & Algorithms Lecture 23: Programming Languages. Aaron Bauer Winter 2014

Organization of Programming Languages (CSE452) Why are there so many programming languages? What makes a language successful?

CS558 Programming Languages

Subprograms. Copyright 2015 Pearson. All rights reserved. 1-1

Installation Download and installation instructions can be found at

Functional Programming

Lecture 4 Memory Management

CS 565: Programming Languages. Spring 2008 Tu, Th: 16:30-17:45 Room LWSN 1106

St. MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad

What Is Computer Science? The Scientific Study of Computation. Expressing or Describing

Programming Paradigms

CS558 Programming Languages

Scala : an LLVM-targeted Scala compiler

Functional Programming. Introduction To Cool

CS 330 Lecture 18. Symbol table. C scope rules. Declarations. Chapter 5 Louden Outline

INSTITUTE OF AERONAUTICAL ENGINEERING

CS558 Programming Languages

Introduction. A. Bellaachia Page: 1

Monday Feb 16, 5pm. solve these equalities. Midterm Thursday Feb 12. covers only ocaml part of the course, assignments 1 through 3.

Programming (Econometrics)

A Brief History of Distributed Programming: RPC. YOW Brisbane 2016

Programming Paradigms

Course Syllabus. Programming Language Paradigms. Spring - DIS Copenhagen. Semester & Location: Elective Course - 3 credits.

What is a programming language?

Lecture 23: Object Lifetime and Garbage Collection

CSE341: Programming Languages Interlude: Course Motivation. Zach Tatlock Winter 2018

Software II: Principles of Programming Languages. Why Expressions?

COMP 201: Principles of Programming

Where do we go from here?

Overview. Rationale Division of labour between script and C++ Choice of language(s) Interfacing to C++

Chapter 7. Expressions and Assignment Statements ISBN

Haskell 98 in short! CPSC 449 Principles of Programming Languages

Extending Jython. with SIM, SPARQL and SQL

Chapter 7. Expressions and Assignment Statements

Overview. Elements of Programming Languages. Advanced constructs. Motivating inner class example

Data Abstraction. Hwansoo Han

Transcription:

Static Typing or Dynamic Typing: A Real Issue or a Simple Case of Tribalism Dr Russel Winder Concertant LLP russel.winder@concertant.com 2007 Russel Winder 1

Aims and Objectives Survey some of the static typing vs. dynamic typing issues. Convince people that the static vs. dynamic typing issue is an opportunity not a problem. Show how symbiosis can be achieved easily, at least on the Java Platform. Foment thinking and debate. Exception handling and dynamic binding are a core part of the structure of this session. 2007 Russel Winder 2

Subliminal (!) Advertising Python for Rookies Sarah Mount, James Shuttleworth and Russel Winder Thomson Learning Now Cengage Learning. Draft cover, things may change. Python is, after all, a dynamic language. Learners of Python need this book. 2007 Russel Winder 3

The Players in the Game Statically typed: C Ada C++ Haskell Java Fortran Scala OCaml C# Eiffel Dynamically typed: Smalltalk Python Ruby Groovy Lua 2007 Russel Winder 4 Perl

Typing the Typing The major keywords are: Strong typing. Weak typing. Static typing. Dynamic typing. Two orthogonal dimensions: strong static dynamic weak There is a third dimension: manifest inferred 2007 Russel Winder 5

The Strong Typing Imperative Software engineering dogma demands abstract data types and strong ( static) typing. Java, Ada, Eiffel, Scala, Haskell are paradigms of languages meeting the requirements of software engineering doctrine. C and C++ are allowed, but are they compatible with doctrine? Imperative languages are not mandated but: Object orientation has hegemony. Functional languages have been ignored. 2007 Russel Winder 6

Placing Languages in the Space Haskell Eiffel Ada Scala Fortran OCaml Static Strong Java C# Groovy Python Ruby Dynamic C++ Lua Scales are quantized, there is not a continuum. C Weak Smalltalk 2007 Russel Winder 7 Perl

Benefits of Static Type Checking Type checking as: Pre execution testing of code. A tool for not getting it wrong. The Problem: My program compiles so it is correct. 2007 Russel Winder 8

Managing Expectations Unit tests, integration tests, acceptance tests. Test driven development incorporate unit testing as an integral part of the development process. The testing oriented philosophy is now part of the dogma and doctrine. Emphasis on testing is independent of static, dynamic, strong, or weak typing. 2007 Russel Winder 9

Interfaces Java really popularized interfaces, though C++, Eiffel etc. have them. Interfaces reify the public interface of an object. Interfaces define types as well as classes. public interface Blah { int dodah ( String s ) ; } class Blah { int dodah ( std::string ) = 0 ; } ; 2007 Russel Winder 10

Programming to Interfaces Classes are for creating objects, interfaces are for defining the public interfaces. cf. List in Java. List<T> is the interface defining listness. ArrayList<T>, LinkedList<T> provide representations of List<T> with different properties. 2007 Russel Winder 11

The Importance of Being Typed Code uses types not classes. Correct use of types checked at compile time. It is not the class that is crucial for execution, it is the public interface exposed by an object. 2007 Russel Winder 12

Polymorphism Generic programming and polymorphic functions increasingly seen as the way forward. Programming to interfaces supports polymorphism. In statically typed languages, there has to be an underlying type relationship to achieve polymorphism: inheritance or conformance required. Do we agree that programming to interfaces and polymorphism are good? 2007 Russel Winder 13

Being Manifestly Typed C++, Java, Ada, Eiffel, etc. require explicit naming of types in all places duplication of typing (on the keyboard). For example in Java: final List<String> l = new ArrayList<String> ( ) ; 2007 Russel Winder 14

Inferring the Types Type inference systems have been around for ages: Functional languages such as Haskell infer the types: fibonacci 0 = 0 fibonacci 1 = 1 fibonacci n = fibonacci ( n - 1 ) + fibonacci ( n - 2 ) Scala also has type inference: val l = new Array[T] ( ) The type structure and checking are the same but the compiler does the work. 2007 Russel Winder 15

Doing the Inference Thing Scala and Haskell have type inferencing. C++ will get some aspects of type inferencing in C++0x. There appear no plans for type inferencing in Java or C#. Why not? Are Java and C# wrong to not use type inferencing? 2007 Russel Winder 16

Strong Static? The strongly typed languages such as C++, Java, C#, Scala, Haskell are compiled languages, i.e. statically typed. Are there any dynamic languages that are strongly typed? Python, Ruby, Groovy Duck now 2007 Russel Winder 17

Who Put the Duck in Typing Inducktive reasoning. If it looks like a duck, walks like a duck, swims like a duck, and quacks like a duck, then it must be a duck. 2007 Russel Winder 18

Not Inferring the Types Take a simple step: Enforce programming to interfaces. Do the check at run time instead of compile time. Are there adherents? Smalltalk Python Ruby Groovy If an object responds to the method, it must be of the right type. Is this the ultimate expression of polymorphism? 2007 Russel Winder 19

The Role of Testing Testing is critical for programming. Programming in C++, Java, Haskell, etc. requires test suites using test frameworks: Aeryn, TestNG, HUnit. What is good for statically typed languages is good for dynamically typed languages. Programming in Smalltalk, Python, Ruby, Groovy, etc. requires test suites using test frameworks: sunit, PyUnit, Test::Unit, Test N Groove. 2007 Russel Winder 20

Dynamic Languages and Testing It is true that dynamic languages rely more on unit testing that static languages do. Is this a problem? 2007 Russel Winder 21

Is Static Typing Irrelevant? Dynamically typed languages seem to have the same aims and goals as statically typed languages and there is no separate compilation phase. What do statically typed language bring that is actually needed? 2007 Russel Winder 22

Having it Both Ways Groovy is a dynamic programming language, with strong but dynamic typing. Groovy is compiled before executed compiled to JVM bytecodes. Groovy works symbiotically with Java uses the Java data types the object forms by default, can also use the primitives when calling Java code. Systems that are part Groovy and part Java are natural and work very well. Static where needed, dynamic where wanted. 2007 Russel Winder 23

Summary Dynamic typing is a technique to use when appropriate. Mixed statically typed and dynamically typed systems have the best of all world. Java + Groovy make a great team. Closures change the way you program. And finally 2007 Russel Winder 24

And Finally Java learners need this. 2007 Russel Winder 25