Closure Design Patterns the Power of Functions in Javascript

Total Page:16

File Type:pdf, Size:1020Kb

Closure Design Patterns the Power of Functions in Javascript Closure Design Patterns The power of functions in JavaScript Qafoo GmbH October 25, 2012 Closure Design Patterns 1 / 54 What comes next? Welcome Closure Design Patterns 2 / 54 About Me Jakob Westhoff I More than 11 years of professional PHP Working with experience I More than 8 years of Qafoo passion for software quality professional JavaScript experience I Open source enthusiast I Regular speaker at (inter)national conferences I Consultant, Trainer and Author Closure Design Patterns 2 / 54 About Me Jakob Westhoff I More than 11 years of professional PHP Working with experience I More than 8 years of Qafoo passion for software quality professional JavaScript experience We help people to create I Open source enthusiast high quality web I Regular speaker at applications. (inter)national conferences I Consultant, Trainer and Author Closure Design Patterns 2 / 54 About Me Jakob Westhoff I More than 11 years of professional PHP Working with experience I More than 8 years of Qafoo passion for software quality professional JavaScript experience We help people to create I Open source enthusiast high quality web I Regular speaker at applications. (inter)national conferences I Consultant, Trainer and http://qafoo.com Author Closure Design Patterns 2 / 54 Goals of this session I Special role of functions in JavaScript I The concept of closures I Utilize those features I Closure/Function Design Patterns Closure Design Patterns 5 / 54 Goals of this session I Special role of functions in JavaScript I The concept of closures I Utilize those features I Closure/Function Design Patterns Closure Design Patterns 5 / 54 What comes next? Functions Closure Design Patterns 6 / 54 First level citizens I Functions are first level citizens in JavaScript I Can be passed like any other variable I Can be created inline I Can be defined at any nesting level I Can be assigned like any other variable Closure Design Patterns 6 / 54 First level citizens I Can be passed like any other variable 1 function foo(callback) f g 2 3 function bar() f g 4 5 foo(bar); Closure Design Patterns 7 / 54 First level citizens I Can be created inline 1 function foo(callback) f g 2 3 foo( function () f 4 //.. 5 g ); Closure Design Patterns 8 / 54 First level citizens I Can be defined at any nesting level 1 function foo() f 2 function bar() f 3 function baz() f 4 //... 5 g 6 g 7 g Closure Design Patterns 9 / 54 First level citizens I Can be assigned like any other variable 1 function baz(callback) f g 2 3 var foo= function () f g 4 var bar= foo; 5 baz(bar); Closure Design Patterns 10 / 54 What comes next? Scope Basics Closure Design Patterns 11 / 54 JavaScript Scoping Basics I Scoping in JavaScript isn’t trivial I To understand closures only a part of JavaScripts scoping rules are essential I Especially Scope Isolation and the Scope Chain Closure Design Patterns 11 / 54 JavaScript Scoping Basics I Scoping in JavaScript isn’t trivial I To understand closures only a part of JavaScripts scoping rules are essential I Especially Scope Isolation and the Scope Chain Closure Design Patterns 11 / 54 JavaScript Scoping Basics I Scoping in JavaScript isn’t trivial I To understand closures only a part of JavaScripts scoping rules are essential I Especially Scope Isolation and the Scope Chain Closure Design Patterns 11 / 54 Scope Isolation I JavaScript does only provide scope isolation on a function level I In contrast to block level isolation in other languages (C, C++, Java, ...) 1 var i = 100; 2 3 ( function () f 4 f o r( var i=1;i <=3; ++i) f 5 a l e r t(i);// 1, 2,3 6 g 7 g )(); 8 9 a l e r t(i)// 100 Closure Design Patterns 12 / 54 Scope Isolation I JavaScript does only provide scope isolation on a function level I In contrast to block level isolation in other languages (C, C++, Java, ...) 1 var i = 100; 2 3 ( function () f 4 f o r( var i=1;i <=3; ++i) f 5 a l e r t(i);// 1, 2,3 6 g 7 g )(); 8 9 a l e r t(i)// 100 Closure Design Patterns 12 / 54 Scope Isolation I JavaScript does only provide scope isolation on a function level I In contrast to block level isolation in other languages (C, C++, Java, ...) 1 var i = 100; 1 var i = 100; 2 2 3 f o r( var i=1;i <=3; ++i) f 3 ( function () f 4 a l e r t(i);// 1, 2,3 4 f o r( var i=1;i <=3; ++i) f 5 g 5 a l e r t(i);// 1, 2,3 6 6 g 7 a l e r t(i)// 100 or 4? 7 g )(); 8 9 a l e r t(i)// 100 Closure Design Patterns 12 / 54 Scope Isolation I JavaScript does only provide scope isolation on a function level I In contrast to block level isolation in other languages (C, C++, Java, ...) 1 var i = 100; 1 var i = 100; 2 2 3 f o r( var i=1;i <=3; ++i) f 3 ( function () f 4 a l e r t(i);// 1, 2,3 4 f o r( var i=1;i <=3; ++i) f 5 g 5 a l e r t(i);// 1, 2,3 6 6 g 7 a l e r t(i)//4 7 g )(); 8 9 a l e r t(i)// 100 Closure Design Patterns 12 / 54 Scope Isolation I JavaScript does only provide scope isolation on a function level I In contrast to block level isolation in other languages (C, C++, Java, ...) 1 var i = 100; 1 var i = 100; 2 2 3 f o r( var i=1;i <=3; ++i) f 3 ( function () f 4 a l e r t(i);// 1, 2,3 4 f o r( var i=1;i <=3; ++i) f 5 g 5 a l e r t(i);// 1, 2,3 6 6 g 7 a l e r t(i)//4 7 g )(); 8 9 a l e r t(i)// 100 Closure Design Patterns 12 / 54 Scope Chain I JavaScript Engines chain scopes during their creation I Inner scopes are always allowed to access outer scopes variables I Outer scopes can not access inner scopes variables I Outer scope access is done by reference not by value Closure Design Patterns 13 / 54 Scope Chain 1 var a = 42; Closure Design Patterns 14 / 54 Scope Chain 1 var a = 42; a = 42 Closure Design Patterns 14 / 54 Scope Chain 1 var a = 42; a = 42 null Closure Design Patterns 14 / 54 Scope Chain 1 var a = 42; 2 3 function somefunc() f 4 var b = 23; 5 g a = 42 b = 23 null Closure Design Patterns 14 / 54 Scope Chain 1 var a = 42; 2 3 function somefunc() f 4 var b = 23; 5 g a = 42 b = 23 null Closure Design Patterns 14 / 54 Scope Chain 1 var a = 42; 2 3 function somefunc() f 4 var b = 23; 5 6 function otherfunc() f 7 var c=”foo”; 8 g 9 g a = 42 b = 23 c = "foo" null Closure Design Patterns 14 / 54 Scope Chain 1 var a = 42; 2 3 function somefunc() f 4 var b = 23; 5 6 function otherfunc() f 7 var c=”foo”; 8 g 9 g a = 42 b = 23 c = "foo" null Closure Design Patterns 14 / 54 Scope Chain 1 var a = 42; 2 3 function somefunc() f 4 var b = 23; 5 6 function otherfunc() f 7 var c=”foo”; 8 var a=”bar”; 9 g 10 g a = 42 b = 23 c = "foo" a = "bar" null Closure Design Patterns 14 / 54 Scope Chain 1 var a = 42; 2 3 function somefunc() f 4 var b = 23; 5 6 function otherfunc() f 7 var c=”foo”; 8 var a=”bar”; 9 a=”baz”; 10 g 11 g a = 42 b = 23 c = "foo" a = "baz" null Closure Design Patterns 14 / 54 Scope Chain 1 var a = 42; 2 3 function somefunc() f 4 var b = 23; 5 6 function otherfunc() f 7 var c=”foo”; 8 var a=”bar”; 9 a=”baz”; 10 b= 5; 11 g 12 g a = 42 b = 5 c = "foo" a = "baz" null Closure Design Patterns 14 / 54 Scope Chain 1 var a = 42; 2 3 function somefunc() f 4 var b = 23; 5 6 function otherfunc() f 7 var c=”foo”; 8 a=”baz”; 9 g 10 g a = "baz" b = 23 c = "foo" null Closure Design Patterns 14 / 54 What comes next? Closures Closure Design Patterns 15 / 54 Closures in computer science I Closures are functions I They are closed over their free variables I Variables from an outside scope can be accessed (upvalues) I Still accessible if outer scope ceases to exist I Upvalues are passed by reference not by value Closure Design Patterns 15 / 54 Closures in JavaScript 1 var g r e e t i n g=”Hello World!”; 2 3 function showGreetings() f 4 a l e r t( greeting); 5 g 6 7 showGreetings(); Closure Design Patterns 16 / 54 Closures in JavaScript Closure Design Patterns 17 / 54 Closures in JavaScript 1 function createAlertMessage( message) f 2 var showMessage= function () f 3 a l e r t( message); 4 g 5 6 return showMessage; 7 g Closure Design Patterns 18 / 54 Closures in JavaScript 1 function createAlertMessage( message) f 2 var showMessage= function () f 3 a l e r t( message); 4 g 5 6 return showMessage; 7 g 1 var greetTheWorld= createAlertMessage( 2 ”Hello World!” 3 ); 4 5 greetTheWorld(); Closure Design Patterns 18 / 54 Closures in JavaScript Closure Design Patterns 19 / 54 Closures in JavaScript 1 function createAlertMessage( message) f 2 var showMessage= function () f 3 a l e r t( message); 4 g 5 6 return showMessage; 7 g 1 var greetTheWorld= createAlertMessage( 2 ”Hello World!” 3 ); 4 var greetTheAudience= createAlertMessage( 5 ”Hello Audience.
Recommended publications
  • Reversible Programming with Negative and Fractional Types
    9 A Computational Interpretation of Compact Closed Categories: Reversible Programming with Negative and Fractional Types CHAO-HONG CHEN, Indiana University, USA AMR SABRY, Indiana University, USA Compact closed categories include objects representing higher-order functions and are well-established as models of linear logic, concurrency, and quantum computing. We show that it is possible to construct such compact closed categories for conventional sum and product types by defining a dual to sum types, a negative type, and a dual to product types, a fractional type. Inspired by the categorical semantics, we define a sound operational semantics for negative and fractional types in which a negative type represents a computational effect that “reverses execution flow” and a fractional type represents a computational effect that“garbage collects” particular values or throws exceptions. Specifically, we extend a first-order reversible language of type isomorphisms with negative and fractional types, specify an operational semantics for each extension, and prove that each extension forms a compact closed category. We furthermore show that both operational semantics can be merged using the standard combination of backtracking and exceptions resulting in a smooth interoperability of negative and fractional types. We illustrate the expressiveness of this combination by writing a reversible SAT solver that uses back- tracking search along freshly allocated and de-allocated locations. The operational semantics, most of its meta-theoretic properties, and all examples are formalized in a supplementary Agda package. CCS Concepts: • Theory of computation → Type theory; Abstract machines; Operational semantics. Additional Key Words and Phrases: Abstract Machines, Duality of Computation, Higher-Order Reversible Programming, Termination Proofs, Type Isomorphisms ACM Reference Format: Chao-Hong Chen and Amr Sabry.
    [Show full text]
  • Process Synchronisation Background (1)
    Process Synchronisation Background (1) Concurrent access to shared data may result in data inconsistency Maintaining data consistency requires mechanisms to ensure the orderly execution of cooperating processes Producer Consumer Background (2) Race condition count++ could be implemented as register1 = count register1 = register1 + 1 count = register1 count- - could be implemented as register2 = count register2 = register2 - 1 count = register2 Consider this execution interleaving with ―count = 5‖ initially: S0: producer execute register1 = count {register1 = 5} S1: producer execute register1 = register1 + 1 {register1 = 6} S2: consumer execute register2 = count {register2 = 5} S3: consumer execute register2 = register2 - 1 {register2 = 4} S4: producer execute count = register1 {count = 6 } S5: consumer execute count = register2 {count = 4} Solution: ensure that only one process at a time can manipulate variable count Avoid interference between changes Critical Section Problem Critical section: a segment of code in which a process may be changing Process structure common variables ◦ Only one process is allowed to be executing in its critical section at any moment in time Critical section problem: design a protocol for process cooperation Requirements for a solution ◦ Mutual exclusion ◦ Progress ◦ Bounded waiting No assumption can be made about the relative speed of processes Handling critical sections in OS ◦ Pre-emptive kernels (real-time programming, more responsive) Linux from 2.6, Solaris, IRIX ◦ Non-pre-emptive kernels (free from race conditions) Windows XP, Windows 2000, traditional UNIX kernel, Linux prior 2.6 Peterson’s Solution Two process solution Process Pi ◦ Mutual exclusion is preserved? ◦ The progress requirements is satisfied? ◦ The bounded-waiting requirement is met? Assumption: LOAD and STORE instructions are atomic, i.e.
    [Show full text]
  • Gnu Smalltalk Library Reference Version 3.2.5 24 November 2017
    gnu Smalltalk Library Reference Version 3.2.5 24 November 2017 by Paolo Bonzini Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled \GNU Free Documentation License". 1 3 1 Base classes 1.1 Tree Classes documented in this manual are boldfaced. Autoload Object Behavior ClassDescription Class Metaclass BlockClosure Boolean False True CObject CAggregate CArray CPtr CString CCallable CCallbackDescriptor CFunctionDescriptor CCompound CStruct CUnion CScalar CChar CDouble CFloat CInt CLong CLongDouble CLongLong CShort CSmalltalk CUChar CByte CBoolean CUInt CULong CULongLong CUShort ContextPart 4 GNU Smalltalk Library Reference BlockContext MethodContext Continuation CType CPtrCType CArrayCType CScalarCType CStringCType Delay Directory DLD DumperProxy AlternativeObjectProxy NullProxy VersionableObjectProxy PluggableProxy SingletonProxy DynamicVariable Exception Error ArithmeticError ZeroDivide MessageNotUnderstood SystemExceptions.InvalidValue SystemExceptions.EmptyCollection SystemExceptions.InvalidArgument SystemExceptions.AlreadyDefined SystemExceptions.ArgumentOutOfRange SystemExceptions.IndexOutOfRange SystemExceptions.InvalidSize SystemExceptions.NotFound SystemExceptions.PackageNotAvailable SystemExceptions.InvalidProcessState SystemExceptions.InvalidState
    [Show full text]
  • APPLYING MODEL-VIEW-CONTROLLER (MVC) in DESIGN and DEVELOPMENT of INFORMATION SYSTEMS an Example of Smart Assistive Script Breakdown in an E-Business Application
    APPLYING MODEL-VIEW-CONTROLLER (MVC) IN DESIGN AND DEVELOPMENT OF INFORMATION SYSTEMS An Example of Smart Assistive Script Breakdown in an e-Business Application Andreas Holzinger, Karl Heinz Struggl Institute of Information Systems and Computer Media (IICM), TU Graz, Graz, Austria Matjaž Debevc Faculty of Electrical Engineering and Computer Science, University of Maribor, Maribor, Slovenia Keywords: Information Systems, Software Design Patterns, Model-view-controller (MVC), Script Breakdown, Film Production. Abstract: Information systems are supporting professionals in all areas of e-Business. In this paper we concentrate on our experiences in the design and development of information systems for the use in film production processes. Professionals working in this area are neither computer experts, nor interested in spending much time for information systems. Consequently, to provide a useful, useable and enjoyable application the system must be extremely suited to the requirements and demands of those professionals. One of the most important tasks at the beginning of a film production is to break down the movie script into its elements and aspects, and create a solid estimate of production costs based on the resulting breakdown data. Several film production software applications provide interfaces to support this task. However, most attempts suffer from numerous usability deficiencies. As a result, many film producers still use script printouts and textmarkers to highlight script elements, and transfer the data manually into their film management software. This paper presents a novel approach for unobtrusive and efficient script breakdown using a new way of breaking down text into its relevant elements. We demonstrate how the implementation of this interface benefits from employing the Model-View-Controller (MVC) as underlying software design paradigm in terms of both software development confidence and user satisfaction.
    [Show full text]
  • Learning Javascript Design Patterns
    Learning JavaScript Design Patterns Addy Osmani Beijing • Cambridge • Farnham • Köln • Sebastopol • Tokyo Learning JavaScript Design Patterns by Addy Osmani Copyright © 2012 Addy Osmani. All rights reserved. Revision History for the : 2012-05-01 Early release revision 1 See http://oreilly.com/catalog/errata.csp?isbn=9781449331818 for release details. ISBN: 978-1-449-33181-8 1335906805 Table of Contents Preface ..................................................................... ix 1. Introduction ........................................................... 1 2. What is a Pattern? ...................................................... 3 We already use patterns everyday 4 3. 'Pattern'-ity Testing, Proto-Patterns & The Rule Of Three ...................... 7 4. The Structure Of A Design Pattern ......................................... 9 5. Writing Design Patterns ................................................. 11 6. Anti-Patterns ......................................................... 13 7. Categories Of Design Pattern ............................................ 15 Creational Design Patterns 15 Structural Design Patterns 16 Behavioral Design Patterns 16 8. Design Pattern Categorization ........................................... 17 A brief note on classes 17 9. JavaScript Design Patterns .............................................. 21 The Creational Pattern 22 The Constructor Pattern 23 Basic Constructors 23 Constructors With Prototypes 24 The Singleton Pattern 24 The Module Pattern 27 iii Modules 27 Object Literals 27 The Module Pattern
    [Show full text]
  • From Perl to Python
    From Perl to Python Fernando Pineda 140.636 Oct. 11, 2017 version 0.1 3. Strong/Weak Dynamic typing The notion of strong and weak typing is a little murky, but I will provide some examples that provide insight most. Strong vs Weak typing To be strongly typed means that the type of data that a variable can hold is fixed and cannot be changed. To be weakly typed means that a variable can hold different types of data, e.g. at one point in the code it might hold an int at another point in the code it might hold a float . Static vs Dynamic typing To be statically typed means that the type of a variable is determined at compile time . Type checking is done by the compiler prior to execution of any code. To be dynamically typed means that the type of variable is determined at run-time. Type checking (if there is any) is done when the statement is executed. C is a strongly and statically language. float x; int y; # you can define your own types with the typedef statement typedef mytype int; mytype z; typedef struct Books { int book_id; char book_name[256] } Perl is a weakly and dynamically typed language. The type of a variable is set when it's value is first set Type checking is performed at run-time. Here is an example from stackoverflow.com that shows how the type of a variable is set to 'integer' at run-time (hence dynamically typed). $value is subsequently cast back and forth between string and a numeric types (hence weakly typed).
    [Show full text]
  • Declare New Function Javascript
    Declare New Function Javascript Piggy or embowed, Levon never stalemating any punctuality! Bipartite Amory wets no blackcurrants flagged anes after Hercules supinate methodically, quite aspirant. Estival Stanleigh bettings, his perspicaciousness exfoliating sopped enforcedly. How a javascript objects for mistakes to retain the closure syntax and maintainability of course, written by reading our customers and line? Everything looks very useful. These values or at first things without warranty that which to declare new function javascript? You declare a new class and news to a function expressions? Explore an implementation defined in new row with a function has a gas range. If it allows you probably work, regular expression evaluation but mostly warszawa, and to retain the explanation of. Reimagine your namespaces alone relate to declare new function javascript objects for arrow functions should be governed by programmers avoid purity. Js library in the different product topic and zip archives are. Why is selected, and declare a superclass method decorators need them into functions defined by allocating local time. It makes more sense to handle work in which support optional, only people want to preserve type to be very short term, but easier to! String type variable side effects and declarations take a more situations than or leading white list of merchantability or a way as explicit. You declare many types to prevent any ecmascript program is not have two categories by any of parameters the ecmascript is one argument we expect. It often derived from the new knowledge within the string, news and error if the function expression that their prototype.
    [Show full text]
  • Let's Get Functional
    5 LET’S GET FUNCTIONAL I’ve mentioned several times that F# is a functional language, but as you’ve learned from previous chapters you can build rich applications in F# without using any functional techniques. Does that mean that F# isn’t really a functional language? No. F# is a general-purpose, multi paradigm language that allows you to program in the style most suited to your task. It is considered a functional-first lan- guage, meaning that its constructs encourage a functional style. In other words, when developing in F# you should favor functional approaches whenever possible and switch to other styles as appropriate. In this chapter, we’ll see what functional programming really is and how functions in F# differ from those in other languages. Once we’ve estab- lished that foundation, we’ll explore several data types commonly used with functional programming and take a brief side trip into lazy evaluation. The Book of F# © 2014 by Dave Fancher What Is Functional Programming? Functional programming takes a fundamentally different approach toward developing software than object-oriented programming. While object-oriented programming is primarily concerned with managing an ever-changing system state, functional programming emphasizes immutability and the application of deterministic functions. This difference drastically changes the way you build software, because in object-oriented programming you’re mostly concerned with defining classes (or structs), whereas in functional programming your focus is on defining functions with particular emphasis on their input and output. F# is an impure functional language where data is immutable by default, though you can still define mutable data or cause other side effects in your functions.
    [Show full text]
  • Notes on Functional Programming with Haskell
    Notes on Functional Programming with Haskell H. Conrad Cunningham [email protected] Multiparadigm Software Architecture Group Department of Computer and Information Science University of Mississippi 201 Weir Hall University, Mississippi 38677 USA Fall Semester 2014 Copyright c 1994, 1995, 1997, 2003, 2007, 2010, 2014 by H. Conrad Cunningham Permission to copy and use this document for educational or research purposes of a non-commercial nature is hereby granted provided that this copyright notice is retained on all copies. All other rights are reserved by the author. H. Conrad Cunningham, D.Sc. Professor and Chair Department of Computer and Information Science University of Mississippi 201 Weir Hall University, Mississippi 38677 USA [email protected] PREFACE TO 1995 EDITION I wrote this set of lecture notes for use in the course Functional Programming (CSCI 555) that I teach in the Department of Computer and Information Science at the Uni- versity of Mississippi. The course is open to advanced undergraduates and beginning graduate students. The first version of these notes were written as a part of my preparation for the fall semester 1993 offering of the course. This version reflects some restructuring and revision done for the fall 1994 offering of the course|or after completion of the class. For these classes, I used the following resources: Textbook { Richard Bird and Philip Wadler. Introduction to Functional Program- ming, Prentice Hall International, 1988 [2]. These notes more or less cover the material from chapters 1 through 6 plus selected material from chapters 7 through 9. Software { Gofer interpreter version 2.30 (2.28 in 1993) written by Mark P.
    [Show full text]
  • Design Patterns in Ocaml
    Design Patterns in OCaml Antonio Vicente [email protected] Earl Wagner [email protected] Abstract The GOF Design Patterns book is an important piece of any professional programmer's library. These patterns are generally considered to be an indication of good design and development practices. By giving an implementation of these patterns in OCaml we expected to better understand the importance of OCaml's advanced language features and provide other developers with an implementation of these familiar concepts in order to reduce the effort required to learn this language. As in the case of Smalltalk and Scheme+GLOS, OCaml's higher order features allows for simple elegant implementation of some of the patterns while others were much harder due to the OCaml's restrictive type system. 1 Contents 1 Background and Motivation 3 2 Results and Evaluation 3 3 Lessons Learned and Conclusions 4 4 Creational Patterns 5 4.1 Abstract Factory . 5 4.2 Builder . 6 4.3 Factory Method . 6 4.4 Prototype . 7 4.5 Singleton . 8 5 Structural Patterns 8 5.1 Adapter . 8 5.2 Bridge . 8 5.3 Composite . 8 5.4 Decorator . 9 5.5 Facade . 10 5.6 Flyweight . 10 5.7 Proxy . 10 6 Behavior Patterns 11 6.1 Chain of Responsibility . 11 6.2 Command . 12 6.3 Interpreter . 13 6.4 Iterator . 13 6.5 Mediator . 13 6.6 Memento . 13 6.7 Observer . 13 6.8 State . 14 6.9 Strategy . 15 6.10 Template Method . 15 6.11 Visitor . 15 7 References 18 2 1 Background and Motivation Throughout this course we have seen many examples of methodologies and tools that can be used to reduce the burden of working in a software project.
    [Show full text]
  • Bespoke Tools: Adapted to the Concepts Developers Know
    Bespoke Tools: Adapted to the Concepts Developers Know Brittany Johnson, Rahul Pandita, Emerson Murphy-Hill, and Sarah Heckman Department of Computer Science North Carolina State University, Raleigh, NC, USA {bijohnso, rpandit}@ncsu.edu, {emerson, heckman}@csc.ncsu.edu ABSTRACT Such manual customization is undesirable for several rea- Even though different developers have varying levels of ex- sons. First, to choose among alternative tools, a developer pertise, the tools in one developer's integrated development must be aware that alternatives exist, yet lack of awareness environment (IDE) behave the same as the tools in every is a pervasive problem in complex software like IDEs [3]. other developers' IDE. In this paper, we propose the idea of Second, even after being aware of alternatives, she must be automatically customizing development tools by modeling able to intelligently choose which tool will be best for her. what a developer knows about software concepts. We then Third, if a developer's situation changes and she recognizes sketch three such \bespoke" tools and describe how devel- that the tool she is currently using is no longer the optimal opment data can be used to infer what a developer knows one, she must endure the overhead of switching to another about relevant concepts. Finally, we describe our ongoing ef- tool. Finally, customization takes time, time that is spent forts to make bespoke program analysis tools that customize fiddling with tools rather than developing software. their notifications to the developer using them. 2. WHAT IS THE NEW IDEA? Categories and Subject Descriptors Our idea is bespoke tools: tools that automatically fit D.2.6 [Software Engineering]: Programming Environments| themselves to the developer using them.
    [Show full text]
  • Scala by Example (2009)
    Scala By Example DRAFT January 13, 2009 Martin Odersky PROGRAMMING METHODS LABORATORY EPFL SWITZERLAND Contents 1 Introduction1 2 A First Example3 3 Programming with Actors and Messages7 4 Expressions and Simple Functions 11 4.1 Expressions And Simple Functions...................... 11 4.2 Parameters.................................... 12 4.3 Conditional Expressions............................ 15 4.4 Example: Square Roots by Newton’s Method................ 15 4.5 Nested Functions................................ 16 4.6 Tail Recursion.................................. 18 5 First-Class Functions 21 5.1 Anonymous Functions............................. 22 5.2 Currying..................................... 23 5.3 Example: Finding Fixed Points of Functions................ 25 5.4 Summary..................................... 28 5.5 Language Elements Seen So Far....................... 28 6 Classes and Objects 31 7 Case Classes and Pattern Matching 43 7.1 Case Classes and Case Objects........................ 46 7.2 Pattern Matching................................ 47 8 Generic Types and Methods 51 8.1 Type Parameter Bounds............................ 53 8.2 Variance Annotations.............................. 56 iv CONTENTS 8.3 Lower Bounds.................................. 58 8.4 Least Types.................................... 58 8.5 Tuples....................................... 60 8.6 Functions.................................... 61 9 Lists 63 9.1 Using Lists.................................... 63 9.2 Definition of class List I: First Order Methods..............
    [Show full text]