Declarative Thinking & Programming Florian Wilhelm - - PowerPoint PPT Presentation

declarative thinking programming
SMART_READER_LITE
LIVE PREVIEW

Declarative Thinking & Programming Florian Wilhelm - - PowerPoint PPT Presentation

Declarative Thinking & Programming Florian Wilhelm EuroPython, Rimini, 2017-07-13 Dr. Florian Wilhelm Data Scientist@inovex Contributor to Pandas, Scikit-Learn, Scipy etc. @FlorianWilhelm Creator of PyScaffold FlorianWilhelm


slide-1
SLIDE 1

Declarative Thinking & Programming

Florian Wilhelm

EuroPython, Rimini, 2017-07-13

slide-2
SLIDE 2

2

@FlorianWilhelm

  • FlorianWilhelm

florianwilhelm.info

  • Dr. Florian Wilhelm

Data Scientist@inovex Contributor to Pandas, Scikit-Learn, Scipy etc. Creator of PyScaffold

slide-3
SLIDE 3

3

Outline

  • 1. Motivation & Concept
  • 2. Examples
  • 3. Math Riddle
slide-4
SLIDE 4

4

Motivation

House-warming party with your friends

slide-5
SLIDE 5

5

Motivation

What is the actual task?

slide-6
SLIDE 6

6

Level of Abstraction

Right level of abstraction given a task What is needed to describe the problem?

map & reduce

slide-7
SLIDE 7

7

Imperative vs. Declarative

How vs. What imperative declarative

  • ver-specification,

detailed instructions, ... separation of concerns, single level of abstraction, ... depending on the level of abstraction

slide-8
SLIDE 8

8

Leaky Abstractions

Law of Leaky Abstractions by Spolsky: “All non-trivial abstractions, to some degree, are leaky.”

slide-9
SLIDE 9

9

Outline

  • 1. Motivation & Concept
  • 2. Examples
  • 3. Math Riddle
slide-10
SLIDE 10

10

Example 1:

List of squared number from 1 to 10 imperative: declarative:

List Comprehensions

slide-11
SLIDE 11

11

Example 2:

Dispatching with respect to some argument Imperative:

slide-12
SLIDE 12

12

Example 2: Dictionaries

Dispatching with respect to some argument Declarative:

slide-13
SLIDE 13

13

Example 3:

Find Plagiarism How many sentences of work A are equal to my work B?

Set Theory Sets

slide-14
SLIDE 14

14

Example 4: Configuration Files

Python modules vs markup languages

YAML

vs

slide-15
SLIDE 15

15

Outline

  • 1. Motivation & Concept
  • 2. Examples
  • 3. Math Riddle
slide-16
SLIDE 16

16 Quelle: Die Zeit, Logelei 52, http://www.zeit.de/2016/52/spiele-logelei-52

Math Riddle

horizontal: A: digit sum of horizontal C, C: prime number, E: palindrome, G: multiple of the backward number of horizontal A, ... vertical: All numbers are square numbers.

slide-17
SLIDE 17

17

Datalog

  • declarative logic programming
  • subset of Prolog
  • query language for deductive DBs
  • other use-cases: security, data integration, information

extraction, networking, program analysis etc. PyDatalog: https://sites.google.com/site/pydatalog/home Features

slide-18
SLIDE 18

18

PyDatalog

Rules & Facts Read the leftmost <= as if Is X a square number? Is X divisible by Y?

slide-19
SLIDE 19

19

PyDatalog

Rules & Facts Is X prime?

slide-20
SLIDE 20

20

PyDatalog

Rules & Facts Map digits to number

slide-21
SLIDE 21

21

Math Riddle

Keep the number of solutions low at all times Leaky Abstraction

slide-22
SLIDE 22

22

Math Riddle

Upper left corner A2, A3 are digits from [1...9] and number A2 A3 is prime

slide-23
SLIDE 23

23 http://www.florianwilhelm.info/2017/07/declarative_thinking_and_programming/

Math Riddle

Solution Querying the knowledge base: Solution:

slide-24
SLIDE 24

24

Other Applications

NixOS

slide-25
SLIDE 25

25

Summary

Advantages of Declarative Programming

  • improved readability of our code
  • reduced number of errors
  • increased performance
  • separation of concerns

„Declarative programming means finding the right abstraction level describing the problem“

slide-26
SLIDE 26

26 Find more details under http://florianwilhelm.info/2017/07/declarative_thinking_and_programming/

Thanks for your Attention! Questions?