SlideShare ist ein Scribd-Unternehmen logo
1 von 26
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Ähnlich wie 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
 
Full CSE 310 Unit 1 PPT.pptx for java language
Full CSE 310 Unit 1 PPT.pptx for java languageFull CSE 310 Unit 1 PPT.pptx for java language
Full CSE 310 Unit 1 PPT.pptx for java language
 

Mehr von 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
 

Mehr von 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
 

Kürzlich hochgeladen

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusZilliz
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbuapidays
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 

Kürzlich hochgeladen (20)

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 

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