SlideShare a Scribd company logo
typing


 Development Techniques Seminar
                         s03e04
... definitions ...
An informal definition:
A type is metadata describing a chunk of memory that classifies
the data stored there. This classification usually implicitly specifies
what sort of operations may be performed on the data.
Common types include primitive types (as strings or numbers),
container types (as arrays), pointers or references and complex
types (as classes or interfaces).

In a pure OOL, every instance (of data) is an object.
... the typing problem ...
In a OOL, the only event than can happen during the
execution of an object-oriented system:

obj.f(arg)

Type violation/failure:
  no f applicable to obj
  arg no acceptable argument to f

Type safety: not possible to apply invalid operations
... typing rules ...

Every entity must be declared as being of a certain type.

In every assignment and in every routine the type of the source
must conform the type of the target (type conformance rule).

x := y

In a call of the form x.f(arg), f must be a feature of x(feature call
rule).
... implitic type conversions ...
n: INTEGER

n := 0.0
n := 1.0
n := -3,67
n := 3.67 - 3.67

With strict typing, assigning a float value should fail.
Allowing that is ambiguous (do we want the rounded or the
truncated version?).

For implicit conversions to work in a strict typed environment
additional functions are needed (truncate, round, ...).
... static and dynamic typing ...
                    (... another holy war ...)

Although intermediate variants are possible two main
approaches:

   Dynamic typing: type verification at execution time.
   Static typing: type verification performed on the text, before
   execution.

A dynamically typed language has no type declarations.
'Entities' simply become associated with whatever values the
execution attaches to them.
... static ...
Languages: C, C++, Java, Pascal, Ada,...

Arguments:
   catching errors earlier (at compile type or interpreting time)
   => less cost in large projects
   readability
   efficiency and less memory consumption
   Better IDE support
       (In a dynamically typed program, it's easy for a human to tell
       what type something is likely to be, but no way for a machine
       to say for sure what type something is)
... dynamic (i) ...

Languages: Smalltalk, Python, PHP, Ruby, Perl, ...

Martin Fowler:
  Static typing is a premature tool to catching bugs, but if you
  use TestDrivenDevelopment (as you should) you are
  already catching them additionally to more types of bugs
  more flow programming (it is difficult to put the experience in
  words)
... dynamic (ii) ...

Robert Martin:

"Too many systems crashed in the field due to silly typing
errors."

"I was depending less and less on the type system for safety.
My unit tests were preventing me from making type errors. "

"The flexibility of dynamically typed langauges makes writing
code significantly easier. Modules are easier to write, and
easier to change. There are no build time issues at all. Life in a
dynamically typed world is fundamentally simpler."
... dynamic (iii) ...
Brucke Eckel (not agains static typing):

"I think that statically typed languages give the illusion of
program correctness. "
"llusion that static type checking can solve all of your problems,
followed by the conclusion that more static type checking is
always better."
"Additional forms of static type checking are often added to a
language without regard to the actual cost. "
"In extreme cases you spend all your time arguing with the
compiler."
"In general, my attitude is that static typing is desirable as long
as it doesn't cost you too much"
"With a dynamic language the model becomes the code"
... dynamic (iV) ...
More quotes:

"The early warnings/errors are not the real disadvantage. The
point is more that static typechecks with existing languages
force you to structure programs to suit the particular, single
static type system that the language in question uses."

"Combined with testing, assertions, contracts, and other good
practices (including a more disciplined use of types than the
one I've just described), you can scale up from a prototype to a
more disciplined system without changing to a statically-
checked language."
... binding (i)...

Don´t confuse with typing.

If we have x.f(arg)...

Typing question: When do we now for sure that at run time
there will be an operation corresponding to f and applicable to
the object attached to x (with the argument arg).
  > Addresses the existance.

Binding question: Which operation will be executed by the
call?
  > Addresses the choice of the right one.
... binding (ii)...


                   static typing    dynamic typing

static binding     ADA, Pascal, C++ Assembly,
                                    scripting
dynamic binding C++, Eiffel         Smalltalk
... strong and weak typing (i) ...
    Don´t confuse static / dynamic with strong / weak.

Weak typing: Allows incorrect messages to be sent to objects

Just an example of what you could do in a weak typing
language: "1" + 1

Languages with unchecked casts (as C/C++) 'could' also be
considered weak.

Examples of dynamic languages:
   weak: php and perl
   strong: python and ruby
... strong and weak typing (ii)...
WeakTyping / StrongTyping / StronglyTypedWithoutLoopholes.

There are well known errors with numeric castings.
C has the problem of the unconditional type cast.

C++ introduced new casts but maintained the old one and the
unsafe new static cast (dynamic cast is safe)

Java, provides static type checking and its runtime cast
checking sharply limits the consequences of a bad cast.

Dynamic languages work like java (withouth static typing)
... more definitions (i) ...
Typing dimensions:
   is there a nontrivial type associated with each declaration?
        StaticTyping: yes
        DynamicTyping: no
        SoftTyping: optional
   if there is, are these types declared explicitly in the source code?
        ManifestTyping: yes
        TypeInference: optional
   does the possibility of a type failure cause a compile-time error?
        StaticTyping: yes
        SoftTyping or DynamicTyping: no
   is the type system strictly enforced, with no loopholes or unsafe
   casts?
        StronglyTypedWithoutLoopholes: yes
        WeakTyping: no
... more definitions (ii) ...
StaticTyping: Type checking before runtime.
DynamicTyping: Type checking at runtime.
StronglyTyped: All operations are checked (either statically or at run-time)
for type correctness, with the exception of only a small number of
loopholes/escapes from typesafety
StronglyTypedWithoutLoopholes: StronlyTypes but withough Loopholes.
WeaklyTyped: Type failures are possible and cause UndefinedBehavior.
ManifestTyping: Requires a type annotation to be given explicitly for each
declaration.
SoftTyping: Where the type checker can prove that the program is type
safe, everything is cool. Where the type checker can't prove correctness it
informs the programmer and inserts appropriate type checks, but doesn't
reject the program.
... more definitions (iii) ...
   TypeInference: Analysis of a program to infer the types of some or all
   expressions (Haskell).
   ImplicitTyping: Typing system which requires few or no type annotations.
   DuckTyping, StructuralTyping, MockTyping (tecnique),...



Examples of flavours:
   Static typing:
      Manifest typing (C, C++)
      Type Inference (Haskell)
   Implicit typing
      Dynamic
      Static Type inference
      Soft typing
... covariance (i) ...
Covariance: change of argument types in redefinitions.

In general, covariance allows you to express more
information in the derived class interface than is true in the base class
interface. The behaviour of a derived class is more specific than that of
a base class, and covariance expresses (one aspect of) the difference.

In many strictly-typed languages (with the notable exception of Eiffel),
subclassing must allow for substitution. That is, a child class can
always stand in for a parent class. This places restrictions on the sorts
of relationships that subclassing can represent. In particular, it means
that arguments to member functions can only be contravariant and
return types can only be covariant.
... covariance (ii)...
Covariance and descendant hiding can introduce errors that the
language has to resolve.
Problems arise with polymorphism.

s: SKIER; b:BOY; g:GIRL
...
!!b; !!g;
s:=b;      -- Polymorphic assignment
s.share(g) -- the type of the argument of share is different in
         -- each class (redeclaration)

p: POLYGON; r:RECTANGLE
...
!!r;         -- creation
p := r        -- polymorphic assignment
p.add_vertex(...) -- ¿accepted in the rectangle? (defined
            -- in the father and hidden in the child)
... covariance in c++...
class A {
  virtual ~A();
  virtual A * f();
  ...
};

class CovB : public A {
  virtual CovB * f();
  ...
};

class NonCovB : public A {
  virtual A * f();
  ...
};

Also the templates are a covariance mechanism.
... PHP (i) ...

Our most used language is:
   dynamic typed
   with type hinting
$a = 1; $a = "hello";

function foo(array $arg) {
  echo "$arg n";
}

foo($a);
... PHP (i) ...

Our most used language is:
   dynamic typed
   with type hinting
                     Catchable fatal error: Argument 1 passed to foo2() must be an array, string
$a = 1; $a = "hello";given...

function foo(array $arg) { <---- !!!!!!!!!
                    hello
  echo "$arg n";
}

foo($a);
... PHP (ii)...
class A {
   public function foo1($arg = "hola") { echo "$arg n"; }
   public function foo2($arg = NULL) {
     if ($arg === NULL) $arg = "hola";
     echo "$arg n";
   }
   public function foo3($arg1) { echo "A::foo3 n";}
   public function foo4(array $arg1) { echo "A::foo4 n";}
}
class B extends A {
   public function foo1($arg = "hello") { parent::foo1($arg); }
   public function foo2($arg = NULL) { parent::foo2($arg); }
   public function foo3($arg1, $arg2) { parent::foo3($arg1); }
   public function foo4($arg1, $arg2) { echo "B::foo4 n"; }
}

$b = new B();
$b->foo1();   // what is the output?
$b->foo2();   // what is the output?
$b->foo3(1,2); // changing signature allowed
$b->foo4(1);
... PHP (ii)...
class A {
   public function foo1($arg = "hola") { echo "$arg n"; }
   public function foo2($arg = NULL) {
     if ($arg === NULL) $arg = "hola";
                     hello
     echo "$arg n"; hola
   }                 A::foo3
   public function foo3($arg1) { echo "A::foo3 n";}
   public function foo4(array $arg1) { echo "A::foo4 n";}
                     Warning: Missing argument 2 for B::foo4(), ...
}
class B extends A { A::foo4
   public function foo1($arg = "hello") { parent::foo1($arg); }
   public function foo2($arg = NULL) { parent::foo2($arg); }
   public function foo3($arg1, $arg2) { parent::foo3($arg1); }
   public function foo4($arg1, $arg2) { echo "A::foo4 n"; }
}

$b = new B();
$b->foo1();   // what is the output?
$b->foo2();   // what is the output?
$b->foo3(1,2); // changing signature allowed
$b->foo4(1);
... PHP (iii)...
class A {
   // public function foo1() { echo "A::foo1 n";}
   private function foo2() { echo "A::foo2 n";}
}

class B extends A {
   // Fatal error: Access level to B::foo1()
   // must be public (as in class A)
   // private function foo1() { echo "B::foo2 n"; }
   public function foo2() { echo "B::foo2 n"; }
}

$b = new B();
// $b->foo1();
$b->foo2();
... PHP (iii)...
class A {
   // public function foo1() { echo "A::foo1 n";}
   private function foo2() { echo "A::foo2 n";}
}                      B::foo2
class B extends A {
   // Fatal error: Access level to B::foo1()
   // must be public (as in class A)
   // private function foo1() { echo "B::foo2 n"; }
   public function foo2() { echo "B::foo2 n"; }
}

$b = new B();
// $b->foo1();
$b->foo2();
... references and links ...

OOSC2nd
Typing: Strong vs. Weak, Static vs. Dynamic
A "fair and balanced" look at the static vs. dynamic typing
schism
Brucke Eckel - 11-16-04 Static vs. Dynamic
Weighing into the static vs dynamic typing debate
Category Language typing
Covariance in C++
Covariance (wikipedia)
Type system (wikipedia)
... fin ...




                    César Ortiz
              cesar@tuenti.com

More Related Content

What's hot

Stringing Things Along
Stringing Things AlongStringing Things Along
Stringing Things Along
Kevlin Henney
 
Language tour of dart
Language tour of dartLanguage tour of dart
Language tour of dart
Imran Qasim
 
New c sharp4_features_part_ii
New c sharp4_features_part_iiNew c sharp4_features_part_ii
New c sharp4_features_part_ii
Nico Ludwig
 
Type Systems
Type SystemsType Systems
Type Systems
Jordan Parmer
 
Unit 2 python
Unit 2 pythonUnit 2 python
Unit 2 python
praveena p
 
Introduction To C#
Introduction To C#Introduction To C#
Introduction To C#
SAMIR BHOGAYTA
 
Swift Tutorial Part 1. The Complete Guide For Swift Programming Language
Swift Tutorial Part 1. The Complete Guide For Swift Programming LanguageSwift Tutorial Part 1. The Complete Guide For Swift Programming Language
Swift Tutorial Part 1. The Complete Guide For Swift Programming Language
Hossam Ghareeb
 
C# lecture 2: Literals , Variables and Data Types in C#
C# lecture 2: Literals , Variables and Data Types in C#C# lecture 2: Literals , Variables and Data Types in C#
C# lecture 2: Literals , Variables and Data Types in C#
Dr.Neeraj Kumar Pandey
 
Highly Strung
Highly StrungHighly Strung
Highly Strung
Kevlin Henney
 
LEARN C# PROGRAMMING WITH GMT
LEARN C# PROGRAMMING WITH GMTLEARN C# PROGRAMMING WITH GMT
LEARN C# PROGRAMMING WITH GMT
Tabassum Ghulame Mustafa
 
Data Types, Variables, and Constants in C# Programming
Data Types, Variables, and Constants in C# ProgrammingData Types, Variables, and Constants in C# Programming
Data Types, Variables, and Constants in C# Programming
Sherwin Banaag Sapin
 
C++ programming language basic to advance level
C++ programming language basic to advance levelC++ programming language basic to advance level
C++ programming language basic to advance level
sajjad ali khan
 
Presentation 2nd
Presentation 2ndPresentation 2nd
Presentation 2ndConnex
 
C language basics
C language basicsC language basics
C language basics
Nikshithas R
 
Computer programming questions
Computer programming questionsComputer programming questions
Computer programming questions
estoredesignerclothi
 
C# Basics
C# BasicsC# Basics
C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#
Hawkman Academy
 

What's hot (19)

C sharp chap2
C sharp chap2C sharp chap2
C sharp chap2
 
Stringing Things Along
Stringing Things AlongStringing Things Along
Stringing Things Along
 
Language tour of dart
Language tour of dartLanguage tour of dart
Language tour of dart
 
New c sharp4_features_part_ii
New c sharp4_features_part_iiNew c sharp4_features_part_ii
New c sharp4_features_part_ii
 
Type Systems
Type SystemsType Systems
Type Systems
 
Unit 2 python
Unit 2 pythonUnit 2 python
Unit 2 python
 
Introduction To C#
Introduction To C#Introduction To C#
Introduction To C#
 
Swift Tutorial Part 1. The Complete Guide For Swift Programming Language
Swift Tutorial Part 1. The Complete Guide For Swift Programming LanguageSwift Tutorial Part 1. The Complete Guide For Swift Programming Language
Swift Tutorial Part 1. The Complete Guide For Swift Programming Language
 
C# lecture 2: Literals , Variables and Data Types in C#
C# lecture 2: Literals , Variables and Data Types in C#C# lecture 2: Literals , Variables and Data Types in C#
C# lecture 2: Literals , Variables and Data Types in C#
 
Highly Strung
Highly StrungHighly Strung
Highly Strung
 
LEARN C# PROGRAMMING WITH GMT
LEARN C# PROGRAMMING WITH GMTLEARN C# PROGRAMMING WITH GMT
LEARN C# PROGRAMMING WITH GMT
 
Data Types, Variables, and Constants in C# Programming
Data Types, Variables, and Constants in C# ProgrammingData Types, Variables, and Constants in C# Programming
Data Types, Variables, and Constants in C# Programming
 
C++ programming language basic to advance level
C++ programming language basic to advance levelC++ programming language basic to advance level
C++ programming language basic to advance level
 
Presentation 2nd
Presentation 2ndPresentation 2nd
Presentation 2nd
 
C language basics
C language basicsC language basics
C language basics
 
Computer programming questions
Computer programming questionsComputer programming questions
Computer programming questions
 
Switch case and looping
Switch case and loopingSwitch case and looping
Switch case and looping
 
C# Basics
C# BasicsC# Basics
C# Basics
 
C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#
 

Viewers also liked

Shannon Plummer Folio II
Shannon Plummer Folio IIShannon Plummer Folio II
Shannon Plummer Folio II
shannonplummer
 
DTS s03e02 Handling the code
DTS s03e02 Handling the codeDTS s03e02 Handling the code
DTS s03e02 Handling the codeTuenti
 
Tuenti Release Workflow
Tuenti Release WorkflowTuenti Release Workflow
Tuenti Release Workflow
Tuenti
 
Tuenti: Web Application Security
Tuenti: Web Application SecurityTuenti: Web Application Security
Tuenti: Web Application Security
Tuenti
 
Shannon Plummer Folio I
Shannon Plummer Folio IShannon Plummer Folio I
Shannon Plummer Folio I
shannonplummer
 
AJAX for Scalability
AJAX for ScalabilityAJAX for Scalability
AJAX for ScalabilityTuenti
 
Tuenti Release Workflow v1.1
Tuenti Release Workflow v1.1Tuenti Release Workflow v1.1
Tuenti Release Workflow v1.1
Tuenti
 

Viewers also liked (7)

Shannon Plummer Folio II
Shannon Plummer Folio IIShannon Plummer Folio II
Shannon Plummer Folio II
 
DTS s03e02 Handling the code
DTS s03e02 Handling the codeDTS s03e02 Handling the code
DTS s03e02 Handling the code
 
Tuenti Release Workflow
Tuenti Release WorkflowTuenti Release Workflow
Tuenti Release Workflow
 
Tuenti: Web Application Security
Tuenti: Web Application SecurityTuenti: Web Application Security
Tuenti: Web Application Security
 
Shannon Plummer Folio I
Shannon Plummer Folio IShannon Plummer Folio I
Shannon Plummer Folio I
 
AJAX for Scalability
AJAX for ScalabilityAJAX for Scalability
AJAX for Scalability
 
Tuenti Release Workflow v1.1
Tuenti Release Workflow v1.1Tuenti Release Workflow v1.1
Tuenti Release Workflow v1.1
 

Similar to DTS s03e04 Typing

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
Codemotion
 
Understanding Typing. Understanding Ruby.
Understanding Typing. Understanding Ruby.Understanding Typing. Understanding Ruby.
Understanding Typing. Understanding Ruby.
Justin Lin
 
Hack Programming Language
Hack Programming LanguageHack Programming Language
Hack Programming Language
Radu Murzea
 
Hack programming language
Hack programming languageHack programming language
Hack programming language
Radu Murzea
 
The D Programming Language - Why I love it!
The D Programming Language - Why I love it!The D Programming Language - Why I love it!
The D Programming Language - Why I love it!
ryutenchi
 
Grooming with Groovy
Grooming with GroovyGrooming with Groovy
Grooming with Groovy
Dhaval Dalal
 
Can functional programming be liberated from static typing?
Can functional programming be liberated from static typing?Can functional programming be liberated from static typing?
Can functional programming be liberated from static typing?
Vsevolod Dyomkin
 
From DOT to Dotty
From DOT to DottyFrom DOT to Dotty
From DOT to Dotty
Martin Odersky
 
Unit 1 c - all topics
Unit 1   c - all topicsUnit 1   c - all topics
Unit 1 c - all topics
veningstonk
 
Boo Manifesto
Boo ManifestoBoo Manifesto
Boo Manifesto
hu hans
 
Peyton jones-2011-parallel haskell-the_future
Peyton jones-2011-parallel haskell-the_futurePeyton jones-2011-parallel haskell-the_future
Peyton jones-2011-parallel haskell-the_future
Takayuki Muranushi
 
Simon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelismSimon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelism
Skills Matter
 
Python-01| Fundamentals
Python-01| FundamentalsPython-01| Fundamentals
Python-01| Fundamentals
Mohd Sajjad
 
Introduction to Python Programming
Introduction to Python ProgrammingIntroduction to Python Programming
Introduction to Python Programming
VijaySharma802
 
Functional Programming - Worth the Effort
Functional Programming - Worth the EffortFunctional Programming - Worth the Effort
Functional Programming - Worth the Effort
BoldRadius Solutions
 
Common mistakes in C programming
Common mistakes in C programmingCommon mistakes in C programming
Common mistakes in C programming
Larion
 
C++ lecture 01
C++   lecture 01C++   lecture 01
C++ lecture 01
HNDE Labuduwa Galle
 
Maintenance of Dynamically vs. Statically typed Languages
Maintenance of Dynamically vs. Statically typed LanguagesMaintenance of Dynamically vs. Statically typed Languages
Maintenance of Dynamically vs. Statically typed LanguagesAmin Bandeali
 
Douglas Crockford - Programming Style and Your Brain
Douglas Crockford - Programming Style and Your BrainDouglas Crockford - Programming Style and Your Brain
Douglas Crockford - Programming Style and Your Brain
Web Directions
 
Tools for the Toolmakers
Tools for the ToolmakersTools for the Toolmakers
Tools for the Toolmakers
Caleb Callaway
 

Similar to DTS s03e04 Typing (20)

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
 
Understanding Typing. Understanding Ruby.
Understanding Typing. Understanding Ruby.Understanding Typing. Understanding Ruby.
Understanding Typing. Understanding Ruby.
 
Hack Programming Language
Hack Programming LanguageHack Programming Language
Hack Programming Language
 
Hack programming language
Hack programming languageHack programming language
Hack programming language
 
The D Programming Language - Why I love it!
The D Programming Language - Why I love it!The D Programming Language - Why I love it!
The D Programming Language - Why I love it!
 
Grooming with Groovy
Grooming with GroovyGrooming with Groovy
Grooming with Groovy
 
Can functional programming be liberated from static typing?
Can functional programming be liberated from static typing?Can functional programming be liberated from static typing?
Can functional programming be liberated from static typing?
 
From DOT to Dotty
From DOT to DottyFrom DOT to Dotty
From DOT to Dotty
 
Unit 1 c - all topics
Unit 1   c - all topicsUnit 1   c - all topics
Unit 1 c - all topics
 
Boo Manifesto
Boo ManifestoBoo Manifesto
Boo Manifesto
 
Peyton jones-2011-parallel haskell-the_future
Peyton jones-2011-parallel haskell-the_futurePeyton jones-2011-parallel haskell-the_future
Peyton jones-2011-parallel haskell-the_future
 
Simon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelismSimon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelism
 
Python-01| Fundamentals
Python-01| FundamentalsPython-01| Fundamentals
Python-01| Fundamentals
 
Introduction to Python Programming
Introduction to Python ProgrammingIntroduction to Python Programming
Introduction to Python Programming
 
Functional Programming - Worth the Effort
Functional Programming - Worth the EffortFunctional Programming - Worth the Effort
Functional Programming - Worth the Effort
 
Common mistakes in C programming
Common mistakes in C programmingCommon mistakes in C programming
Common mistakes in C programming
 
C++ lecture 01
C++   lecture 01C++   lecture 01
C++ lecture 01
 
Maintenance of Dynamically vs. Statically typed Languages
Maintenance of Dynamically vs. Statically typed LanguagesMaintenance of Dynamically vs. Statically typed Languages
Maintenance of Dynamically vs. Statically typed Languages
 
Douglas Crockford - Programming Style and Your Brain
Douglas Crockford - Programming Style and Your BrainDouglas Crockford - Programming Style and Your Brain
Douglas Crockford - Programming Style and Your Brain
 
Tools for the Toolmakers
Tools for the ToolmakersTools for the Toolmakers
Tools for the Toolmakers
 

More from Tuenti

Tu: Telco 2.0 at FICOD 2011
Tu: Telco 2.0 at FICOD 2011Tu: Telco 2.0 at FICOD 2011
Tu: Telco 2.0 at FICOD 2011
Tuenti
 
Tuenti - de la idea a la web
Tuenti -  de la idea a la webTuenti -  de la idea a la web
Tuenti - de la idea a la webTuenti
 
Tuenti Mobile Development
Tuenti Mobile DevelopmentTuenti Mobile Development
Tuenti Mobile Development
Tuenti
 
Tuenti release process
Tuenti release processTuenti release process
Tuenti release processTuenti
 
Tuenti - tu entidad
Tuenti -  tu entidadTuenti -  tu entidad
Tuenti - tu entidad
Tuenti
 
Tuenti Tech Teams. Frontend, Backend, Systems and more, working together
Tuenti Tech Teams. Frontend, Backend, Systems and more, working togetherTuenti Tech Teams. Frontend, Backend, Systems and more, working together
Tuenti Tech Teams. Frontend, Backend, Systems and more, working togetherTuenti
 

More from Tuenti (6)

Tu: Telco 2.0 at FICOD 2011
Tu: Telco 2.0 at FICOD 2011Tu: Telco 2.0 at FICOD 2011
Tu: Telco 2.0 at FICOD 2011
 
Tuenti - de la idea a la web
Tuenti -  de la idea a la webTuenti -  de la idea a la web
Tuenti - de la idea a la web
 
Tuenti Mobile Development
Tuenti Mobile DevelopmentTuenti Mobile Development
Tuenti Mobile Development
 
Tuenti release process
Tuenti release processTuenti release process
Tuenti release process
 
Tuenti - tu entidad
Tuenti -  tu entidadTuenti -  tu entidad
Tuenti - tu entidad
 
Tuenti Tech Teams. Frontend, Backend, Systems and more, working together
Tuenti Tech Teams. Frontend, Backend, Systems and more, working togetherTuenti Tech Teams. Frontend, Backend, Systems and more, working together
Tuenti Tech Teams. Frontend, Backend, Systems and more, working together
 

Recently uploaded

GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 

Recently uploaded (20)

GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 

DTS s03e04 Typing

  • 2. ... definitions ... An informal definition: A type is metadata describing a chunk of memory that classifies the data stored there. This classification usually implicitly specifies what sort of operations may be performed on the data. Common types include primitive types (as strings or numbers), container types (as arrays), pointers or references and complex types (as classes or interfaces). In a pure OOL, every instance (of data) is an object.
  • 3. ... the typing problem ... In a OOL, the only event than can happen during the execution of an object-oriented system: obj.f(arg) Type violation/failure: no f applicable to obj arg no acceptable argument to f Type safety: not possible to apply invalid operations
  • 4. ... typing rules ... Every entity must be declared as being of a certain type. In every assignment and in every routine the type of the source must conform the type of the target (type conformance rule). x := y In a call of the form x.f(arg), f must be a feature of x(feature call rule).
  • 5. ... implitic type conversions ... n: INTEGER n := 0.0 n := 1.0 n := -3,67 n := 3.67 - 3.67 With strict typing, assigning a float value should fail. Allowing that is ambiguous (do we want the rounded or the truncated version?). For implicit conversions to work in a strict typed environment additional functions are needed (truncate, round, ...).
  • 6. ... static and dynamic typing ... (... another holy war ...) Although intermediate variants are possible two main approaches: Dynamic typing: type verification at execution time. Static typing: type verification performed on the text, before execution. A dynamically typed language has no type declarations. 'Entities' simply become associated with whatever values the execution attaches to them.
  • 7. ... static ... Languages: C, C++, Java, Pascal, Ada,... Arguments: catching errors earlier (at compile type or interpreting time) => less cost in large projects readability efficiency and less memory consumption Better IDE support (In a dynamically typed program, it's easy for a human to tell what type something is likely to be, but no way for a machine to say for sure what type something is)
  • 8. ... dynamic (i) ... Languages: Smalltalk, Python, PHP, Ruby, Perl, ... Martin Fowler: Static typing is a premature tool to catching bugs, but if you use TestDrivenDevelopment (as you should) you are already catching them additionally to more types of bugs more flow programming (it is difficult to put the experience in words)
  • 9. ... dynamic (ii) ... Robert Martin: "Too many systems crashed in the field due to silly typing errors." "I was depending less and less on the type system for safety. My unit tests were preventing me from making type errors. " "The flexibility of dynamically typed langauges makes writing code significantly easier. Modules are easier to write, and easier to change. There are no build time issues at all. Life in a dynamically typed world is fundamentally simpler."
  • 10. ... dynamic (iii) ... Brucke Eckel (not agains static typing): "I think that statically typed languages give the illusion of program correctness. " "llusion that static type checking can solve all of your problems, followed by the conclusion that more static type checking is always better." "Additional forms of static type checking are often added to a language without regard to the actual cost. " "In extreme cases you spend all your time arguing with the compiler." "In general, my attitude is that static typing is desirable as long as it doesn't cost you too much" "With a dynamic language the model becomes the code"
  • 11. ... dynamic (iV) ... More quotes: "The early warnings/errors are not the real disadvantage. The point is more that static typechecks with existing languages force you to structure programs to suit the particular, single static type system that the language in question uses." "Combined with testing, assertions, contracts, and other good practices (including a more disciplined use of types than the one I've just described), you can scale up from a prototype to a more disciplined system without changing to a statically- checked language."
  • 12. ... binding (i)... Don´t confuse with typing. If we have x.f(arg)... Typing question: When do we now for sure that at run time there will be an operation corresponding to f and applicable to the object attached to x (with the argument arg). > Addresses the existance. Binding question: Which operation will be executed by the call? > Addresses the choice of the right one.
  • 13. ... binding (ii)... static typing dynamic typing static binding ADA, Pascal, C++ Assembly, scripting dynamic binding C++, Eiffel Smalltalk
  • 14. ... strong and weak typing (i) ... Don´t confuse static / dynamic with strong / weak. Weak typing: Allows incorrect messages to be sent to objects Just an example of what you could do in a weak typing language: "1" + 1 Languages with unchecked casts (as C/C++) 'could' also be considered weak. Examples of dynamic languages: weak: php and perl strong: python and ruby
  • 15. ... strong and weak typing (ii)... WeakTyping / StrongTyping / StronglyTypedWithoutLoopholes. There are well known errors with numeric castings. C has the problem of the unconditional type cast. C++ introduced new casts but maintained the old one and the unsafe new static cast (dynamic cast is safe) Java, provides static type checking and its runtime cast checking sharply limits the consequences of a bad cast. Dynamic languages work like java (withouth static typing)
  • 16. ... more definitions (i) ... Typing dimensions: is there a nontrivial type associated with each declaration? StaticTyping: yes DynamicTyping: no SoftTyping: optional if there is, are these types declared explicitly in the source code? ManifestTyping: yes TypeInference: optional does the possibility of a type failure cause a compile-time error? StaticTyping: yes SoftTyping or DynamicTyping: no is the type system strictly enforced, with no loopholes or unsafe casts? StronglyTypedWithoutLoopholes: yes WeakTyping: no
  • 17. ... more definitions (ii) ... StaticTyping: Type checking before runtime. DynamicTyping: Type checking at runtime. StronglyTyped: All operations are checked (either statically or at run-time) for type correctness, with the exception of only a small number of loopholes/escapes from typesafety StronglyTypedWithoutLoopholes: StronlyTypes but withough Loopholes. WeaklyTyped: Type failures are possible and cause UndefinedBehavior. ManifestTyping: Requires a type annotation to be given explicitly for each declaration. SoftTyping: Where the type checker can prove that the program is type safe, everything is cool. Where the type checker can't prove correctness it informs the programmer and inserts appropriate type checks, but doesn't reject the program.
  • 18. ... more definitions (iii) ... TypeInference: Analysis of a program to infer the types of some or all expressions (Haskell). ImplicitTyping: Typing system which requires few or no type annotations. DuckTyping, StructuralTyping, MockTyping (tecnique),... Examples of flavours: Static typing: Manifest typing (C, C++) Type Inference (Haskell) Implicit typing Dynamic Static Type inference Soft typing
  • 19. ... covariance (i) ... Covariance: change of argument types in redefinitions. In general, covariance allows you to express more information in the derived class interface than is true in the base class interface. The behaviour of a derived class is more specific than that of a base class, and covariance expresses (one aspect of) the difference. In many strictly-typed languages (with the notable exception of Eiffel), subclassing must allow for substitution. That is, a child class can always stand in for a parent class. This places restrictions on the sorts of relationships that subclassing can represent. In particular, it means that arguments to member functions can only be contravariant and return types can only be covariant.
  • 20. ... covariance (ii)... Covariance and descendant hiding can introduce errors that the language has to resolve. Problems arise with polymorphism. s: SKIER; b:BOY; g:GIRL ... !!b; !!g; s:=b; -- Polymorphic assignment s.share(g) -- the type of the argument of share is different in -- each class (redeclaration) p: POLYGON; r:RECTANGLE ... !!r; -- creation p := r -- polymorphic assignment p.add_vertex(...) -- ¿accepted in the rectangle? (defined -- in the father and hidden in the child)
  • 21. ... covariance in c++... class A { virtual ~A(); virtual A * f(); ... }; class CovB : public A { virtual CovB * f(); ... }; class NonCovB : public A { virtual A * f(); ... }; Also the templates are a covariance mechanism.
  • 22. ... PHP (i) ... Our most used language is: dynamic typed with type hinting $a = 1; $a = "hello"; function foo(array $arg) { echo "$arg n"; } foo($a);
  • 23. ... PHP (i) ... Our most used language is: dynamic typed with type hinting Catchable fatal error: Argument 1 passed to foo2() must be an array, string $a = 1; $a = "hello";given... function foo(array $arg) { <---- !!!!!!!!! hello echo "$arg n"; } foo($a);
  • 24. ... PHP (ii)... class A { public function foo1($arg = "hola") { echo "$arg n"; } public function foo2($arg = NULL) { if ($arg === NULL) $arg = "hola"; echo "$arg n"; } public function foo3($arg1) { echo "A::foo3 n";} public function foo4(array $arg1) { echo "A::foo4 n";} } class B extends A { public function foo1($arg = "hello") { parent::foo1($arg); } public function foo2($arg = NULL) { parent::foo2($arg); } public function foo3($arg1, $arg2) { parent::foo3($arg1); } public function foo4($arg1, $arg2) { echo "B::foo4 n"; } } $b = new B(); $b->foo1(); // what is the output? $b->foo2(); // what is the output? $b->foo3(1,2); // changing signature allowed $b->foo4(1);
  • 25. ... PHP (ii)... class A { public function foo1($arg = "hola") { echo "$arg n"; } public function foo2($arg = NULL) { if ($arg === NULL) $arg = "hola"; hello echo "$arg n"; hola } A::foo3 public function foo3($arg1) { echo "A::foo3 n";} public function foo4(array $arg1) { echo "A::foo4 n";} Warning: Missing argument 2 for B::foo4(), ... } class B extends A { A::foo4 public function foo1($arg = "hello") { parent::foo1($arg); } public function foo2($arg = NULL) { parent::foo2($arg); } public function foo3($arg1, $arg2) { parent::foo3($arg1); } public function foo4($arg1, $arg2) { echo "A::foo4 n"; } } $b = new B(); $b->foo1(); // what is the output? $b->foo2(); // what is the output? $b->foo3(1,2); // changing signature allowed $b->foo4(1);
  • 26. ... PHP (iii)... class A { // public function foo1() { echo "A::foo1 n";} private function foo2() { echo "A::foo2 n";} } class B extends A { // Fatal error: Access level to B::foo1() // must be public (as in class A) // private function foo1() { echo "B::foo2 n"; } public function foo2() { echo "B::foo2 n"; } } $b = new B(); // $b->foo1(); $b->foo2();
  • 27. ... PHP (iii)... class A { // public function foo1() { echo "A::foo1 n";} private function foo2() { echo "A::foo2 n";} } B::foo2 class B extends A { // Fatal error: Access level to B::foo1() // must be public (as in class A) // private function foo1() { echo "B::foo2 n"; } public function foo2() { echo "B::foo2 n"; } } $b = new B(); // $b->foo1(); $b->foo2();
  • 28. ... references and links ... OOSC2nd Typing: Strong vs. Weak, Static vs. Dynamic A "fair and balanced" look at the static vs. dynamic typing schism Brucke Eckel - 11-16-04 Static vs. Dynamic Weighing into the static vs dynamic typing debate Category Language typing Covariance in C++ Covariance (wikipedia) Type system (wikipedia)
  • 29. ... fin ... César Ortiz cesar@tuenti.com