SlideShare una empresa de Scribd logo
1 de 26
Descargar para leer sin conexión
Softwaretechnik
                          Vorlesung 02: Specification with Types


                                      Peter Thiemann

                                  Universit¨t Freiburg, Germany
                                           a


                                           SS 2009




Peter Thiemann (Univ. Freiburg)           Softwaretechnik         SWT   1 / 21
Inhalt




Specification with Types
   Excursion: Scripting Languages
   Ultra-Brief JavaScript Tutorial
   Thesis




 Peter Thiemann (Univ. Freiburg)   Softwaretechnik   SWT   2 / 21
Specification with Types   Excursion: Scripting Languages




    Excursion to a World Without Types:
            Scripting Languages




Peter Thiemann (Univ. Freiburg)                    Softwaretechnik                           SWT   3 / 21
Specification with Types   Excursion: Scripting Languages


Scripting Languages

      Lightweight programming languages
      evolved from command languages
      Lightweight data structures
      hashmap (object), strings
      Lightweight syntax
      familiar, no semicolon, (often not well specified), . . .
      Lightweight typing
      dynamic, weak, duck typing
      Lightweight metaprogramming
      Lightweight implementation
      interpreted, few tools



 Peter Thiemann (Univ. Freiburg)                    Softwaretechnik                           SWT   4 / 21
Specification with Types   Excursion: Scripting Languages


JavaScript, a Typical Scripting Language



      Initially developed by Netscape’s Brendan Eich
      Standardized as ECMAScript (ECMA-262 Edition 3)
      Application areas (scripting targets)
              client-side web scripting (dynamic HTML, SVG, XUL)
              server-side scripting (Whitebeam, Helma, Cocoon, iPlanet)
              animation scripting (diablo, dim3, k3d)
              and many more




 Peter Thiemann (Univ. Freiburg)                    Softwaretechnik                           SWT   5 / 21
Specification with Types   Excursion: Scripting Languages


JavaScript, Technically



      Java-style syntax
      Object-based imperative language                                    node.onmouseout =
              no classes, but prototype concept                             function (ev) {
              objects are hashtables                                          init();
      First-class functions                                                   state++;
                                                                              node.className =
              a functional language
                                                                                "highlight-"
      Weak, dynamic type system                                                 + state;
  Slogan: Any type can be converted to                                        ev.stopPropagation();
    any other reasonable type                                               };




 Peter Thiemann (Univ. Freiburg)                    Softwaretechnik                           SWT   6 / 21
Specification with Types   Excursion: Scripting Languages


Problems with JavaScript

Symptomatic for other scripting languages

       No module system
               No namespace management
               No interface descriptions
       No static type system
       No application specific datatypes
       primitive datatypes, strings, hashtables
       Type conversions are sometimes surprising
       “A scripting language should never throw an exception [the script
       should just continue]” (Rob Pike, Google)
 ⇒ Limited to small applications



 Peter Thiemann (Univ. Freiburg)                     Softwaretechnik                           SWT   7 / 21
Specification with Types   Excursion: Scripting Languages


Specific Problems with JavaScript


      Most popular applications
              client-side scripting
              AJAX
      Dynamic modification of page content via DOM interface
              DOM = document object model
              W3C standard interface for accessing and modifying XML
              Mainly used in web browers




 Peter Thiemann (Univ. Freiburg)                    Softwaretechnik                           SWT   8 / 21
Specification with Types   Excursion: Scripting Languages


Specific Problems with JavaScript


      Most popular applications
              client-side scripting
              AJAX
      Dynamic modification of page content via DOM interface
              DOM = document object model
              W3C standard interface for accessing and modifying XML
              Mainly used in web browers
      Incompatible DOM implementations in Web browsers
 ⇒ programming recipes instead of techniques




 Peter Thiemann (Univ. Freiburg)                    Softwaretechnik                           SWT   8 / 21
Specification with Types   Excursion: Scripting Languages


Can You Write Reliable Programs in JavaScript?



      Struggle with the lack of e.g. a module system
              Ad-hoc structuring of large programs
              Naming conventions
              Working in a team
      Work around DOM incompatibilities
              Use existing JavaScript frameworks (widgets, networking)
              Frameworks are also incompatible
      Wonder about unexpected results




 Peter Thiemann (Univ. Freiburg)                    Softwaretechnik                           SWT   9 / 21
Specification with Types   Ultra-Brief JavaScript Tutorial


An Ultra-Brief JavaScript Tutorial

Rule 1:
JavaScript is object-based. An object is a hash table that maps named
properties to values.




 Peter Thiemann (Univ. Freiburg)                    Softwaretechnik                            SWT   10 / 21
Specification with Types   Ultra-Brief JavaScript Tutorial


An Ultra-Brief JavaScript Tutorial

Rule 1:
JavaScript is object-based. An object is a hash table that maps named
properties to values.

Rule 2:
Every value has a type. For most reasonable combinations, values can be
converted from one type to another type.




 Peter Thiemann (Univ. Freiburg)                    Softwaretechnik                            SWT   10 / 21
Specification with Types   Ultra-Brief JavaScript Tutorial


An Ultra-Brief JavaScript Tutorial

Rule 1:
JavaScript is object-based. An object is a hash table that maps named
properties to values.

Rule 2:
Every value has a type. For most reasonable combinations, values can be
converted from one type to another type.

Rule 3:
Types include null, boolean, number, string, object, and function.




 Peter Thiemann (Univ. Freiburg)                    Softwaretechnik                            SWT   10 / 21
Specification with Types   Ultra-Brief JavaScript Tutorial


An Ultra-Brief JavaScript Tutorial

Rule 1:
JavaScript is object-based. An object is a hash table that maps named
properties to values.

Rule 2:
Every value has a type. For most reasonable combinations, values can be
converted from one type to another type.

Rule 3:
Types include null, boolean, number, string, object, and function.

Rule 4:
‘Undefined’ is a value (and a type).



 Peter Thiemann (Univ. Freiburg)                    Softwaretechnik                            SWT   10 / 21
Specification with Types   Ultra-Brief JavaScript Tutorial


Some Quick Questions


Let’s define an object obj:

js> var obj = { x: 1 }

What are the values/outputs of
      obj.x
      obj.y
      print(obj.y)
      obj.y.z




 Peter Thiemann (Univ. Freiburg)                    Softwaretechnik                            SWT   11 / 21
Specification with Types   Ultra-Brief JavaScript Tutorial


Answers


js> var obj = {x:1}
js> obj.x
1
js> obj.y
js> print(obj.y)
undefined
js> obj.y.z
js: "<stdin>", line 12: uncaught JavaScript exception:
 ConversionError: The undefined value has no properties.
 (<stdin>; line 12)




Peter Thiemann (Univ. Freiburg)                    Softwaretechnik                            SWT   12 / 21
Specification with Types   Ultra-Brief JavaScript Tutorial


Weak, Dynamic Types in JavaScript II

Rule 5:
An object is really a dynamic mapping from strings to values.

js> var x = "x"
js> obj[x]
1
js> obj.undefined = "gotcha"
gotcha
js> obj[obj.y]

What is the effect/result of the last expression?

       == "gotcha"



 Peter Thiemann (Univ. Freiburg)                    Softwaretechnik                            SWT   13 / 21
Specification with Types   Ultra-Brief JavaScript Tutorial


Weak, Dynamic Types in JavaScript II

Rule 5:
An object is really a dynamic mapping from strings to values.

js> var x = "x"
js> obj[x]
1
js> obj.undefined = "gotcha"
gotcha
js> obj[obj.y]
    == obj[undefined]
    == obj["undefined"]
    == obj.undefined
    == "gotcha"



 Peter Thiemann (Univ. Freiburg)                    Softwaretechnik                            SWT   14 / 21
Specification with Types   Ultra-Brief JavaScript Tutorial


Weak, Dynamic Types in JavaScript III


Recall Rule 2:
Every value has a type. For most reasonable combinations, values can be
converted from one type to another type.

js> var a = 17
js> a.x = 42
42
js> a.x

What is the effect/result of the last expression?




 Peter Thiemann (Univ. Freiburg)                    Softwaretechnik                            SWT   15 / 21
Specification with Types   Ultra-Brief JavaScript Tutorial


Weak, Dynamic Types in JavaScript III

Wrapper objects for numbers

   js> m = new Number (17); n = new Number (4)
   js> m+n
   21




 Peter Thiemann (Univ. Freiburg)                    Softwaretechnik                            SWT   16 / 21
Specification with Types   Ultra-Brief JavaScript Tutorial


Weak, Dynamic Types in JavaScript III

Wrapper objects for numbers

   js> m = new Number (17); n = new Number (4)
   js> m+n
   21


Wrapper objects for booleans

   js> flag = new Bool(false);
   js> result = flag ? true : false;

What is the value of result?



 Peter Thiemann (Univ. Freiburg)                    Softwaretechnik                            SWT   16 / 21
Specification with Types   Ultra-Brief JavaScript Tutorial


Weak, Dynamic Types in JavaScript IV

Rule 6:
Functions are first-class, but behave differently when used as methods or
as constructors.

js> function f () { return this.x }
js> f()
x
js> obj.f = f
function f() { return this.x; }
js> obj.f()
1
js> new f()
[object Object]



 Peter Thiemann (Univ. Freiburg)                    Softwaretechnik                            SWT   17 / 21
Specification with Types   Ultra-Brief JavaScript Tutorial


Distinguishing Absence and Undefinedness I



js> obju = { u : {}.xx }
[object Object]
js> objv = { v : {}.xx }
[object Object]
js> print(obju.u)
undefined
js> print(objv.u)
undefined




 Peter Thiemann (Univ. Freiburg)                    Softwaretechnik                            SWT   18 / 21
Specification with Types   Ultra-Brief JavaScript Tutorial


Distinguishing Absence and Undefinedness II


Rule 7:
The with construct puts its argument object on top of the current
environment stack.

js> u = "defined"
defined
js> with (obju) print(u)
undefined
js> with (objv) print(u)
defined




 Peter Thiemann (Univ. Freiburg)                    Softwaretechnik                            SWT   19 / 21
Specification with Types   Ultra-Brief JavaScript Tutorial


Distinguishing Absence and Undefinedness III

Rule 8:
The for construct has an in operator to range over all defined indexes.

js> for (i           in obju) print(i)
u
js> for (i           in objv) print(i)
v
js> delete           objv.v
true
js> for (i           in objv) print(i)
js> delete           objv.v
true



 Peter Thiemann (Univ. Freiburg)                    Softwaretechnik                            SWT   20 / 21
Specification with Types   Thesis


Thesis


      Common errors such as
              using non-objects as objects
              e.g. using numbers as functions
              invoking non-existing methods
              accessing non-existing fields
              surprising conversions
      can all be caught by a
                                            Static Type System
      and much more.




 Peter Thiemann (Univ. Freiburg)                    Softwaretechnik   SWT   21 / 21

Más contenido relacionado

La actualidad más candente

Programming Paradigms
Programming ParadigmsProgramming Paradigms
Programming ParadigmsDirecti Group
 
មេរៀនៈ Data Structure and Algorithm in C/C++
មេរៀនៈ Data Structure and Algorithm in C/C++មេរៀនៈ Data Structure and Algorithm in C/C++
មេរៀនៈ Data Structure and Algorithm in C/C++Ngeam Soly
 
04 iec t1_s1_oo_ps_session_05
04 iec t1_s1_oo_ps_session_0504 iec t1_s1_oo_ps_session_05
04 iec t1_s1_oo_ps_session_05Niit Care
 
06 iec t1_s1_oo_ps_session_08
06 iec t1_s1_oo_ps_session_0806 iec t1_s1_oo_ps_session_08
06 iec t1_s1_oo_ps_session_08Niit Care
 
11 iec t1_s1_oo_ps_session_16
11 iec t1_s1_oo_ps_session_1611 iec t1_s1_oo_ps_session_16
11 iec t1_s1_oo_ps_session_16Niit Care
 

La actualidad más candente (6)

Programming Paradigms
Programming ParadigmsProgramming Paradigms
Programming Paradigms
 
មេរៀនៈ Data Structure and Algorithm in C/C++
មេរៀនៈ Data Structure and Algorithm in C/C++មេរៀនៈ Data Structure and Algorithm in C/C++
មេរៀនៈ Data Structure and Algorithm in C/C++
 
ASE02 DMP.ppt
ASE02 DMP.pptASE02 DMP.ppt
ASE02 DMP.ppt
 
04 iec t1_s1_oo_ps_session_05
04 iec t1_s1_oo_ps_session_0504 iec t1_s1_oo_ps_session_05
04 iec t1_s1_oo_ps_session_05
 
06 iec t1_s1_oo_ps_session_08
06 iec t1_s1_oo_ps_session_0806 iec t1_s1_oo_ps_session_08
06 iec t1_s1_oo_ps_session_08
 
11 iec t1_s1_oo_ps_session_16
11 iec t1_s1_oo_ps_session_1611 iec t1_s1_oo_ps_session_16
11 iec t1_s1_oo_ps_session_16
 

Similar a v02-types.en (20)

Learning typescript
Learning typescriptLearning typescript
Learning typescript
 
Getting started with typescript
Getting started with typescriptGetting started with typescript
Getting started with typescript
 
Modern C++
Modern C++Modern C++
Modern C++
 
invokedynamic: Evolution of a Language Feature
invokedynamic: Evolution of a Language Featureinvokedynamic: Evolution of a Language Feature
invokedynamic: Evolution of a Language Feature
 
New c sharp4_features_part_v
New c sharp4_features_part_vNew c sharp4_features_part_v
New c sharp4_features_part_v
 
Programming Paradigms
Programming ParadigmsProgramming Paradigms
Programming Paradigms
 
Java1
Java1Java1
Java1
 
Java
Java Java
Java
 
findbugs Bernhard Merkle
findbugs Bernhard Merklefindbugs Bernhard Merkle
findbugs Bernhard Merkle
 
TypeScript Overview
TypeScript OverviewTypeScript Overview
TypeScript Overview
 
Functional Programming In Jdk8
Functional Programming In Jdk8 Functional Programming In Jdk8
Functional Programming In Jdk8
 
Future Programming Language
Future Programming LanguageFuture Programming Language
Future Programming Language
 
Introducing TypeScript
Introducing TypeScriptIntroducing TypeScript
Introducing TypeScript
 
Framework engineering JCO 2011
Framework engineering JCO 2011Framework engineering JCO 2011
Framework engineering JCO 2011
 
02paradigms.ppt
02paradigms.ppt02paradigms.ppt
02paradigms.ppt
 
SMI - Introduction to Java
SMI - Introduction to JavaSMI - Introduction to Java
SMI - Introduction to Java
 
Software engineering
Software engineeringSoftware engineering
Software engineering
 
Software engineering
Software engineeringSoftware engineering
Software engineering
 
Java-Intro.pptx
Java-Intro.pptxJava-Intro.pptx
Java-Intro.pptx
 
DTS s03e04 Typing
DTS s03e04 TypingDTS s03e04 Typing
DTS s03e04 Typing
 

Más de tutorialsruby

&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>tutorialsruby
 
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>tutorialsruby
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008tutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheetstutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheetstutorialsruby
 

Más de tutorialsruby (20)

&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
 
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
 
CSS
CSSCSS
CSS
 
CSS
CSSCSS
CSS
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 

Último

What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 

Último (20)

What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 

v02-types.en

  • 1. Softwaretechnik Vorlesung 02: Specification with Types Peter Thiemann Universit¨t Freiburg, Germany a SS 2009 Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 1 / 21
  • 2. Inhalt Specification with Types Excursion: Scripting Languages Ultra-Brief JavaScript Tutorial Thesis Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 2 / 21
  • 3. Specification with Types Excursion: Scripting Languages Excursion to a World Without Types: Scripting Languages Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 3 / 21
  • 4. Specification with Types Excursion: Scripting Languages Scripting Languages Lightweight programming languages evolved from command languages Lightweight data structures hashmap (object), strings Lightweight syntax familiar, no semicolon, (often not well specified), . . . Lightweight typing dynamic, weak, duck typing Lightweight metaprogramming Lightweight implementation interpreted, few tools Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 4 / 21
  • 5. Specification with Types Excursion: Scripting Languages JavaScript, a Typical Scripting Language Initially developed by Netscape’s Brendan Eich Standardized as ECMAScript (ECMA-262 Edition 3) Application areas (scripting targets) client-side web scripting (dynamic HTML, SVG, XUL) server-side scripting (Whitebeam, Helma, Cocoon, iPlanet) animation scripting (diablo, dim3, k3d) and many more Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 5 / 21
  • 6. Specification with Types Excursion: Scripting Languages JavaScript, Technically Java-style syntax Object-based imperative language node.onmouseout = no classes, but prototype concept function (ev) { objects are hashtables init(); First-class functions state++; node.className = a functional language "highlight-" Weak, dynamic type system + state; Slogan: Any type can be converted to ev.stopPropagation(); any other reasonable type }; Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 6 / 21
  • 7. Specification with Types Excursion: Scripting Languages Problems with JavaScript Symptomatic for other scripting languages No module system No namespace management No interface descriptions No static type system No application specific datatypes primitive datatypes, strings, hashtables Type conversions are sometimes surprising “A scripting language should never throw an exception [the script should just continue]” (Rob Pike, Google) ⇒ Limited to small applications Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 7 / 21
  • 8. Specification with Types Excursion: Scripting Languages Specific Problems with JavaScript Most popular applications client-side scripting AJAX Dynamic modification of page content via DOM interface DOM = document object model W3C standard interface for accessing and modifying XML Mainly used in web browers Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 8 / 21
  • 9. Specification with Types Excursion: Scripting Languages Specific Problems with JavaScript Most popular applications client-side scripting AJAX Dynamic modification of page content via DOM interface DOM = document object model W3C standard interface for accessing and modifying XML Mainly used in web browers Incompatible DOM implementations in Web browsers ⇒ programming recipes instead of techniques Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 8 / 21
  • 10. Specification with Types Excursion: Scripting Languages Can You Write Reliable Programs in JavaScript? Struggle with the lack of e.g. a module system Ad-hoc structuring of large programs Naming conventions Working in a team Work around DOM incompatibilities Use existing JavaScript frameworks (widgets, networking) Frameworks are also incompatible Wonder about unexpected results Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 9 / 21
  • 11. Specification with Types Ultra-Brief JavaScript Tutorial An Ultra-Brief JavaScript Tutorial Rule 1: JavaScript is object-based. An object is a hash table that maps named properties to values. Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 10 / 21
  • 12. Specification with Types Ultra-Brief JavaScript Tutorial An Ultra-Brief JavaScript Tutorial Rule 1: JavaScript is object-based. An object is a hash table that maps named properties to values. Rule 2: Every value has a type. For most reasonable combinations, values can be converted from one type to another type. Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 10 / 21
  • 13. Specification with Types Ultra-Brief JavaScript Tutorial An Ultra-Brief JavaScript Tutorial Rule 1: JavaScript is object-based. An object is a hash table that maps named properties to values. Rule 2: Every value has a type. For most reasonable combinations, values can be converted from one type to another type. Rule 3: Types include null, boolean, number, string, object, and function. Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 10 / 21
  • 14. Specification with Types Ultra-Brief JavaScript Tutorial An Ultra-Brief JavaScript Tutorial Rule 1: JavaScript is object-based. An object is a hash table that maps named properties to values. Rule 2: Every value has a type. For most reasonable combinations, values can be converted from one type to another type. Rule 3: Types include null, boolean, number, string, object, and function. Rule 4: ‘Undefined’ is a value (and a type). Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 10 / 21
  • 15. Specification with Types Ultra-Brief JavaScript Tutorial Some Quick Questions Let’s define an object obj: js> var obj = { x: 1 } What are the values/outputs of obj.x obj.y print(obj.y) obj.y.z Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 11 / 21
  • 16. Specification with Types Ultra-Brief JavaScript Tutorial Answers js> var obj = {x:1} js> obj.x 1 js> obj.y js> print(obj.y) undefined js> obj.y.z js: "<stdin>", line 12: uncaught JavaScript exception: ConversionError: The undefined value has no properties. (<stdin>; line 12) Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 12 / 21
  • 17. Specification with Types Ultra-Brief JavaScript Tutorial Weak, Dynamic Types in JavaScript II Rule 5: An object is really a dynamic mapping from strings to values. js> var x = "x" js> obj[x] 1 js> obj.undefined = "gotcha" gotcha js> obj[obj.y] What is the effect/result of the last expression? == "gotcha" Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 13 / 21
  • 18. Specification with Types Ultra-Brief JavaScript Tutorial Weak, Dynamic Types in JavaScript II Rule 5: An object is really a dynamic mapping from strings to values. js> var x = "x" js> obj[x] 1 js> obj.undefined = "gotcha" gotcha js> obj[obj.y] == obj[undefined] == obj["undefined"] == obj.undefined == "gotcha" Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 14 / 21
  • 19. Specification with Types Ultra-Brief JavaScript Tutorial Weak, Dynamic Types in JavaScript III Recall Rule 2: Every value has a type. For most reasonable combinations, values can be converted from one type to another type. js> var a = 17 js> a.x = 42 42 js> a.x What is the effect/result of the last expression? Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 15 / 21
  • 20. Specification with Types Ultra-Brief JavaScript Tutorial Weak, Dynamic Types in JavaScript III Wrapper objects for numbers js> m = new Number (17); n = new Number (4) js> m+n 21 Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 16 / 21
  • 21. Specification with Types Ultra-Brief JavaScript Tutorial Weak, Dynamic Types in JavaScript III Wrapper objects for numbers js> m = new Number (17); n = new Number (4) js> m+n 21 Wrapper objects for booleans js> flag = new Bool(false); js> result = flag ? true : false; What is the value of result? Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 16 / 21
  • 22. Specification with Types Ultra-Brief JavaScript Tutorial Weak, Dynamic Types in JavaScript IV Rule 6: Functions are first-class, but behave differently when used as methods or as constructors. js> function f () { return this.x } js> f() x js> obj.f = f function f() { return this.x; } js> obj.f() 1 js> new f() [object Object] Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 17 / 21
  • 23. Specification with Types Ultra-Brief JavaScript Tutorial Distinguishing Absence and Undefinedness I js> obju = { u : {}.xx } [object Object] js> objv = { v : {}.xx } [object Object] js> print(obju.u) undefined js> print(objv.u) undefined Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 18 / 21
  • 24. Specification with Types Ultra-Brief JavaScript Tutorial Distinguishing Absence and Undefinedness II Rule 7: The with construct puts its argument object on top of the current environment stack. js> u = "defined" defined js> with (obju) print(u) undefined js> with (objv) print(u) defined Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 19 / 21
  • 25. Specification with Types Ultra-Brief JavaScript Tutorial Distinguishing Absence and Undefinedness III Rule 8: The for construct has an in operator to range over all defined indexes. js> for (i in obju) print(i) u js> for (i in objv) print(i) v js> delete objv.v true js> for (i in objv) print(i) js> delete objv.v true Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 20 / 21
  • 26. Specification with Types Thesis Thesis Common errors such as using non-objects as objects e.g. using numbers as functions invoking non-existing methods accessing non-existing fields surprising conversions can all be caught by a Static Type System and much more. Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 21 / 21