20
1 Future of Abstraction Alexander Stepanov

1 Future of Abstraction Alexander Stepanov. 2 Outline of the Talk Outline of the Talk What is abstraction? Abstraction in programming OO vs. Templates

Embed Size (px)

DESCRIPTION

3 AbstractionAbstraction  The fundamental way of organizing knowledge  Grouping of similar facts together  Specific to a scientific discipline

Citation preview

Page 1: 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

Future of Abstraction

Alexander Stepanov

Page 2: 1 Future of Abstraction Alexander Stepanov. 2 Outline of the Talk Outline of the Talk  What is abstraction?  Abstraction in programming  OO vs. Templates

2

Outline of the TalkOutline of the Talk

What is abstraction?

Abstraction in programming

OO vs. Templates

Concepts

A new programming language?

Page 3: 1 Future of Abstraction Alexander Stepanov. 2 Outline of the Talk Outline of the Talk  What is abstraction?  Abstraction in programming  OO vs. Templates

3

AbstractionAbstraction

The fundamental way of organizing knowledge

Grouping of similar facts together

Specific to a scientific discipline

Page 4: 1 Future of Abstraction Alexander Stepanov. 2 Outline of the Talk Outline of the Talk  What is abstraction?  Abstraction in programming  OO vs. Templates

4

Abstraction in MathematicsAbstraction in Mathematics

Vector space {V: Group; F: Field; ×: F, V → V; distributivity; distributivity of scalars;

associativity; identity}

Algebraic structures (Bourbaki)

Page 5: 1 Future of Abstraction Alexander Stepanov. 2 Outline of the Talk Outline of the Talk  What is abstraction?  Abstraction in programming  OO vs. Templates

5

Abstraction in ProgrammingAbstraction in Programmingfor (i = 0; i < n; i++) sum += A[i];

Abstracting + associativity; commutativity; identity parallelizability ; permutability; initial value

Abstracting i constant time access; value extraction

Page 6: 1 Future of Abstraction Alexander Stepanov. 2 Outline of the Talk Outline of the Talk  What is abstraction?  Abstraction in programming  OO vs. Templates

6

1. Take a piece of code2. Write specifications3. Replace actual types with formal types4. Derive requirements for the formal types that

imply these specifications

Abstraction in ProgrammingAbstraction in Programming

Page 7: 1 Future of Abstraction Alexander Stepanov. 2 Outline of the Talk Outline of the Talk  What is abstraction?  Abstraction in programming  OO vs. Templates

7

Abstraction Mechanisms in C++Abstraction Mechanisms in C++

Object Oriented Programming Inheritance Virtual functions

Generic Programming Overloading Templates

Both use classes, but in a rather different way

Page 8: 1 Future of Abstraction Alexander Stepanov. 2 Outline of the Talk Outline of the Talk  What is abstraction?  Abstraction in programming  OO vs. Templates

8

Object Oriented ProgrammingObject Oriented Programming

Separation of interface and implementation Late or early binding Slow Limited expressability

Single variable type Variance only in the first position

Page 9: 1 Future of Abstraction Alexander Stepanov. 2 Outline of the Talk Outline of the Talk  What is abstraction?  Abstraction in programming  OO vs. Templates

9

Class reducerClass reducer

class reducer {public:

virtual void initialize(int value) = 0;virtual void add_values(int* first, int* last) = 0;virtual int get_value() = 0;

};

class sequential_reducer : public reducer { … };

class parallel_reducer : public reducer { … };

Page 10: 1 Future of Abstraction Alexander Stepanov. 2 Outline of the Talk Outline of the Talk  What is abstraction?  Abstraction in programming  OO vs. Templates

10

Generic ProgrammingGeneric 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

Page 11: 1 Future of Abstraction Alexander Stepanov. 2 Outline of the Talk Outline of the Talk  What is abstraction?  Abstraction in programming  OO vs. Templates

11

Reduction operatorReduction operator

template <class InputIterator, class BinaryOperation>typename iterator_traits<InputIterator>::value_typereduce(InputIterator first,

InputIterator last, BinaryOperation op) { if (first == last) return identity_element(op); typename iterator_traits<InputIterator>::value_type

result = *first; while (++first != last) result = op(result, *first); return result;}

Page 12: 1 Future of Abstraction Alexander Stepanov. 2 Outline of the Talk Outline of the Talk  What is abstraction?  Abstraction in programming  OO vs. Templates

12

Reduction operator with a bugReduction operator with a bug

template <class InputIterator, class BinaryOperation>typename iterator_traits<InputIterator>::value_typereduce(InputIterator first,

InputIterator last, BinaryOperation op) { if (first == last) return identity_element(op); typename iterator_traits<InputIterator>::value_type result = *first; while (++first < last) result = op(result, *first); return result;}

Page 13: 1 Future of Abstraction Alexander Stepanov. 2 Outline of the Talk Outline of the Talk  What is abstraction?  Abstraction in programming  OO vs. Templates

13

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

Page 14: 1 Future of Abstraction Alexander Stepanov. 2 Outline of the Talk Outline of the Talk  What is abstraction?  Abstraction in programming  OO vs. Templates

14

ConceptsConcepts

concept SemiRegular : Assignable, DefaultConstructible{};

concept Regular : SemiRegular, EqualityComparable {};concept InputIterator : Regular, Incrementable {

SemiRegular value_type;Integral distance_type;const value_type& operator*();

};

Page 15: 1 Future of Abstraction Alexander Stepanov. 2 Outline of the Talk Outline of the Talk  What is abstraction?  Abstraction in programming  OO vs. Templates

15

Reduction done with ConceptsReduction 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;}

Page 16: 1 Future of Abstraction Alexander Stepanov. 2 Outline of the Talk Outline of the Talk  What is abstraction?  Abstraction in programming  OO vs. Templates

16

Signature of mergeSignature 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]));

Page 17: 1 Future of Abstraction Alexander Stepanov. 2 Outline of the Talk Outline of the Talk  What is abstraction?  Abstraction in programming  OO vs. Templates

17

Virtual Table for InputIteratorVirtual Table for InputIterator

type of the iterator copy constructor default constructor destructor operator= operator== operator++

value type distance type operator*

Page 18: 1 Future of Abstraction Alexander Stepanov. 2 Outline of the Talk Outline of the Talk  What is abstraction?  Abstraction in programming  OO vs. Templates

18

Unifying OOP and GPUnifying OOP and GP

Pointers to concepts

Late or early binding

Well defined interfaces

Simple core language

Page 19: 1 Future of Abstraction Alexander Stepanov. 2 Outline of the Talk Outline of the Talk  What is abstraction?  Abstraction in programming  OO vs. Templates

19

Other Language ProblemsOther Language Problems

Semantic information: assertions, complexity

Multiple memory types: pointers, references, parameter passing

Compilation model: cpp, includes, header files

Design approach: evolution vs. revolution

Page 20: 1 Future of Abstraction Alexander Stepanov. 2 Outline of the Talk Outline of the Talk  What is abstraction?  Abstraction in programming  OO vs. Templates

20

ConclusionConclusion

We have to create a language that expresses everything we want to say about computations:

If it is worth saying, it is worth saying formally.