1 STL and Its Design Principles Alexander Stepanov.

Slides:



Advertisements
Similar presentations
Object Oriented Programming Lect. Dr. Daniel POP Universitatea de Vest din Timişoara Facultatea de Matematică şi Informatică.
Advertisements

C++ Templates. What is a template? Templates are type-generic versions of functions and/or classes Template functions and template classes can be used.
Generic Programming and Formal Methods David R. Musser Rensselaer Polytechnic Institute.
Alex Stepanov Zander Kelley CSCE 221H Spring 2014.
C++ Sets and Multisets Set containers automatically sort their elements automatically. Multisets allow duplication of elements whereas sets do not. Usually,
1 Software Testing and Quality Assurance Lecture 12 - The Testing Perspective (Chapter 2, A Practical Guide to Testing Object-Oriented Software)
What is generic programming? The essence of the generic programming approach is concept development: systematic classification of computing components.
. The Standard C++ Library. 2 Main Ideas Purpose Flexibility Efficiency Simple & Uniform Interface.
1 Iterators & Algorithms Iterators provide a link between containers and algorithms Example: We wish to write a function sum() that adds up the members.
Shallow Versus Deep Copy and Pointers Shallow copy: when two or more pointers of the same types point to the same memory – They point to the same data.
Data Structures Using C++ 2E
Computer Science and Software Engineering University of Wisconsin - Platteville 7. Inheritance and Polymorphism Yan Shi CS/SE 2630 Lecture Notes.
CSE 332: C++ Algorithms II From Last Time: Search with Generic Iterators Third generalization: separate iterator type parameter We arrive at the find algorithm.
Data Structures Using C++ 2E Chapter 3 Pointers and Array-Based Lists.
1 Concepts: Linguistic Support for Generic Programming in C++ Douglas Gregor Jeremy Siek Gabriel Dos Reis Jaakko Järvi Bjarne Stroustrup Andrew Lumsdaine.
Data Structures Using C++ 2E
Generic Programming Johan Torp. Agenda GP introduction GP in perspective Questions * GP = Generic programming in C++
Generic Programming Using the C++ Standard Template Library.
Programming Language Support for Generic Libraries Jeremy Siek and Walid Taha Abstract The generic programming methodology is revolutionizing the way we.
C++ History C++ was designed at AT&T Bell Labs by Bjarne Stroustrup in the early 80's Based on the ‘C’ programming language C++ language standardised in.
Alexander Stepanov A9.com 1 One algorithm from The Book: A tribute to Ira Pohl
Data Structures Using C++1 Chapter 1 Software Engineering Principles and C++ Classes.
1. The term STL stands for ? a) Simple Template Library b) Static Template Library c) Single Type Based Library d) Standard Template Library Answer : d.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 8: Class Relationships Data Abstraction & Problem Solving.
Chapter 12 Support for Object oriented Programming.
Standard Template Library The Standard Template Library was recently added to standard C++. –The STL contains generic template classes. –The STL permits.
1 Iterators Good reference site:
Introduction to c++ programming - object oriented programming concepts - Structured Vs OOP. Classes and objects - class definition - Objects - class scope.
ITERATORS. Iterator An iterator in C++ is a concept that refines the iterator design pattern into a specific set of behaviors that work well with the.
Object-Oriented Programming Chapter Chapter
Chapter 10: Classes and Data Abstraction. Objectives In this chapter, you will: Learn about classes Learn about private, protected, and public members.
Digging into the GAT API Comparing C, C++ and Python API‘s Hartmut Kaiser
Intro to the C++ STL Timmie Smith September 6, 2001.
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
ISBN Object-Oriented Programming Chapter Chapter
C++ Inheritance Data Structures & OO Development I 1 Computer Science Dept Va Tech June 2007 © McQuain Generalization versus Abstraction Abstraction:simplify.
Concepts in C++. Templates in current C++ C++ template is typeless No language support for constrained generics Accidental errors found in instantiation.
1 Future of Abstraction Alexander Stepanov. 2 Outline of the Talk Outline of the Talk  What is abstraction?  Abstraction in programming  OO vs. Templates.
1 CS Programming Languages Class 22 November 14, 2000.
STL CSSE 250 Susan Reeder. What is the STL? Standard Template Library Standard C++ Library is an extensible framework which contains components for Language.
Copyright © 2009 – Curt Hill Standard Template Library An Introduction.
Introduction The STL is a complex piece of software engineering that uses some of C++'s most sophisticated features STL provides an incredible amount.
CSCI-383 Object-Oriented Programming & Design Lecture 25.
Chapter 10: Classes and Data Abstraction. Classes Object-oriented design (OOD): a problem solving methodology Objects: components of a solution Class:
S3D Software Object Oriented Refactoring IMPA – Sistemas Gráficos 3D (2007) Mário de Sá Vera
1 C# - Inheritance and Polymorphism. 2 1.Inheritance 2.Implementing Inheritance in C# 3.Constructor calls in Inheritance 4.Protected Access Modifier 5.The.
CSE 332: C++ STL iterators What is an Iterator? An iterator must be able to do 2 main things –Point to the start of a range of elements (in a container)
Unified Modeling Language (UML)
C# Fundamentals An Introduction. Before we begin How to get started writing C# – Quick tour of the dev. Environment – The current C# version is 5.0 –
CSE 332: C++ templates and generic programming II Review: Concepts and Models Templates impose requirements on type parameters –Types that are plugged.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
Introduction to Generic Programming in C++
Programming with ANSI C ++
7. Inheritance and Polymorphism
Complexity Time: 2 Hours.
CS 326 Programming Languages, Concepts and Implementation
OOP What is problem? Solution? OOP
About the Presentations
Lecture 2 of Computer Science II
Object-Orientated Programming
Types of Programming Languages
Designing Software for Ease of Extension and Contraction
Chapter 2 Software Processes
Ada – 1983 History’s largest design effort
Generic Programming Karl Lieberherr 12/1/2018 Generic Programming.
Advanced Java Programming
Chapter 8: Class Relationships
Standard Template Library
SPL – PS3 C++ Classes.
Presentation transcript:

1 STL and Its Design Principles Alexander Stepanov

2 Outline of the Talk Outline of the Talk  Genesis of STL  Fundamental principles  Language requirements  Industrialized software engineering  Assessment

3 Genesis of STL Genesis of STL  Original intuition: associating algorithms with mathematical theories – 1976  Specification language Tecton (with Dave Musser and Deepak Kapur) – 1979 to 1983  Higher-order programming in Scheme (with Aaron Kershenbaum and Dave Musser) – 1984 to 1986  Ada Generic Library (with Dave Musser) – 1986  UKL Standard Components – 1987 to 1988  STL (with Meng Lee and Dave Musser) – 1993 to 1994  SGI STL (with Matt Austern and Hans Boehm) – 1995 to 1998

4 Fundamental Principles Fundamental Principles  Systematically identifying and organizing useful algorithms and data structures  Finding the most general representations of algorithms  Using whole-part value semantics for data structures  Using abstractions of addresses as the interface between algorithms and data structures

5 Identification and Organization Identification and Organization 1.Find algorithms and data structures 2.Implement them 3.Create usable taxonomy

6 Finding software components Finding software components  Books, papers  Other libraries  Real codes

7 Implementing Components Implementing Components  Specify correct interfaces  Implement  Validate  Measure

8 Organizing Components Organizing Components  Fill the gaps  Define orthogonal structure based on functionality  Document

9 1.Take a piece of code 2.Write specifications 3.Replace actual types with formal types 4.Derive requirements for the formal types that imply these specifications Generic Programming Generic Programming

10 Whole-part semantics Whole-part semantics  Data structures extend the semantics of structures  Copy of the whole copies the parts  When the whole is destroyed, all the parts are destroyed  Two things are equal when they have the same number of parts and their corresponding parts are equal

11 Addresses / Iterators Addresses / Iterators  Fast access to the data  Fast equality on iterators  Fast traversal operations – different for different categories

12 Iterator Categories Iterator Categories  Input  Output  Forward  Bidirectional  Random-access  Two-dimensional  …

13 Abstraction Mechanisms in C++  Object Oriented Programming  Inheritance  Virtual functions  Generic Programming  Overloading  Templates Both use classes, but in a rather different way

14 Object Oriented Programming  Separation of interface and implementation  Late or early binding  Slow  Limited expressability  Single variable type  Variance only in the first position

15 Generic Programming Generic Programming  Implementation is the interface  Terrible error messages  Syntax errors could survive for years  Early binding only  Could be very fast  But potential abstraction penalty  Unlimited expressability

16 Reduction operator Reduction operator template typename iterator_traits ::value_type reduce(InputIterator first, InputIterator last, BinaryOperation op) { if (first == last) return identity_element(op); typename iterator_traits ::value_type result = * first; while ( ++ first != last) result = op(result, * first); return result; }

17 Reduction operator with a bug template typename iterator_traits ::value_type reduce(InputIterator first, InputIterator last, BinaryOperation op) { if (first == last) return identity_element(op); typename iterator_traits ::value_type result = * first; while ( ++ first < last) result = op(result, * first); return result; }

18 We need to be able to define what InputIterator is in the language in which we program, not in English

19 Concepts Concepts concept SemiRegular : Assignable, DefaultConstructible{}; concept Regular : SemiRegular, EqualityComparable {}; concept InputIterator : Regular, Incrementable { SemiRegular value_type; Integral distance_type; const value_type& operator*(); };

20 Reduction done with Concepts Reduction done with Concepts value_type(InputIterator) reduce(InputIterator first, InputIterator last, BinaryOperation op) (value_type(InputIterator) == argument_type(BinaryOperation)) { if (first == last) return identity_element(op); value_type(InputIterator) result = * first; while ( ++ first != last) result = op(result, * first); return result; }

21 Signature of merge Signature of merge OutputIterator merge(InputIterator[1] first1, InputIterator[1] last1, InputIterator[2] first2, InputIterator[2] last2, OutputIterator result) (bool operator<(value_type(InputIterator[1]), value_type(InputIterator[2])), output_type(OutputIterator) == value_type(InputIterator[1]), output_type(OutputIterator) == value_type(InputIterator[2]));

22 Virtual Table for InputIterator Virtual Table for InputIterator  type of the iterator  copy constructor  default constructor  destructor  operator=  operator==  operator++  value type  distance type  operator*

23 Unifying OOP and GP Unifying OOP and GP  Pointers to concepts  Late or early binding  Well defined interfaces  Simple core language

24 Industrial Revolution in Software  Large, systematic catalogs  Validated, efficient, generic components  Component engineers (few)  System engineers (many)

25 Changes in Industry Changes in Industry  Industry  Code is a liability  Internal code tax  Continuous professional education  Government  Tax support for the fundamental infrastructure  Legal framework  Academia

26 Is STL successful? Is STL successful?  Millions of copies out  Everybody (Microsoft, IBM, Sun …) ships it  A dozen books  Very few extensions  No language progress  No effect on software engineering