On t the Usa Usage o of P Pyth thonic I c Idioms ms Carol V. - - PowerPoint PPT Presentation

on t the usa usage o of p pyth thonic i c idioms ms
SMART_READER_LITE
LIVE PREVIEW

On t the Usa Usage o of P Pyth thonic I c Idioms ms Carol V. - - PowerPoint PPT Presentation

Onward! 2018 Boston Park Plaza Hotel Boston, Massachusetts, United States 07 November 2018 On t the Usa Usage o of P Pyth thonic I c Idioms ms Carol V. Alexandru , Jos J. Merchante, Sebastiano Panichella , Sebastian Proksch,


slide-1
SLIDE 1

On t the Usa Usage o

  • f P

Pyth thonic I c Idioms ms

Carol V. Alexandru¹, José J. Merchante², Sebastiano Panichella¹,³ Sebastian Proksch¹, Harald C. Gall¹, Gregorio Robles² ¹Software Evolution and Architecture Lab, University of Zurich, Switzerland

{alexandru,proksch,gall}@ifi.uzh.ch

²Grupo de Sistemas y Comunicaciones, Universidad Rey Juan Carlos, Spain

jj.merchante@alumnos.urjc.es, grex@gsyc.urjc.es

³Service Prototype Lab, Zurich University of Applied Sciences, Switzerland

panc@zhaw.ch

Onward! 2018 Boston Park Plaza Hotel Boston, Massachusetts, United States 07 November 2018

slide-2
SLIDE 2
slide-3
SLIDE 3

Harald C. Gall Sebastiano Panichella Carol V. Alexandru Sebastian Proksch Gregorio Robles José J. Merchante

slide-4
SLIDE 4

4

Th Things t to k know a about t Pyth thon

slide-5
SLIDE 5

5

Th Things t to k know a about t Pyth thon

  • Cr

Crea eated ted by y Guido van Rossum

slide-6
SLIDE 6

6

Th Things t to k know a about t Pyth thon

  • Cr

Crea eated ted by y Guido van Rossum

– He is (was) the “Benevolent Dictator for Life” – Makes the final decisions when necessary

slide-7
SLIDE 7

7

Th Things t to k know a about t Pyth thon

  • Cr

Crea eated ted by y Guido van Rossum

– He is (was) the “Benevolent Dictator for Life” – Makes the final decisions when necessary

  • Str

trong principles es

– The “Zen of Python” >>> import this

slide-8
SLIDE 8

8

Th Things t to k know a about t Pyth thon

slide-9
SLIDE 9

9

Th Things t to k know a about t Pyth thon

  • Cr

Crea eated ted by y Guido van Rossum

– He is (was) the “Benevolent Dictator for Life” – Makes the final decisions when necessary

  • Str

trong principles es

– The “Zen of Python” >>> import this – Python Enhancement Proposals (PEPs)

slide-10
SLIDE 10

10

Th Things t to k know a about t Pyth thon

  • Cr

Crea eated ted by y Guido van Rossum

– He is (was) the “Benevolent Dictator for Life” – Makes the final decisions when necessary

  • Str

trong principles es

– The “Zen of Python” >>> import this – Python Enhancement Proposals (PEPs)

  • Wi

Widesprea ead adopti tion across many y fi fiel elds

slide-11
SLIDE 11

11 11

Py Pythonic a c appears to s to b be 'a th thing'

slide-12
SLIDE 12

12

Py Pythonic a c appears to s to b be 'a th thing'

“It would be more pythonic to...”

slide-13
SLIDE 13

13

A simp mple q question

slide-14
SLIDE 14

14

T

  • p Answer cl

r claims t ms to b be e “pythonic” c”... ...

slide-15
SLIDE 15

15

.. ...but t 100s 0s of people se seem em sce ceptica cal

slide-16
SLIDE 16

16

“Pythonic” c” beca cause of t the s style guide ( (PEP 8) PEP 8)

slide-17
SLIDE 17

17

“Pythonic” c” beca cause o

  • f p

performa rmance ce

slide-18
SLIDE 18

18

Idioms ms and signaling

slide-19
SLIDE 19

19

Idioms ms and signaling

slide-20
SLIDE 20

20

And th there a are exceptions

slide-21
SLIDE 21

21

Cr Creati tive use o

  • f th

the word “Pyth thonic” c”

slide-22
SLIDE 22

22

Is th s there a a d definiti tion f for “Pyth thonic” c”?

slide-23
SLIDE 23

23

Is th s there a a d definiti tion f for “Pyth thonic” c”?

slide-24
SLIDE 24

24

Is th s there a a d definiti tion f for “Pyth thonic” c”?

slide-25
SLIDE 25

25

Is th s there a a d definiti tion f for “Pyth thonic” c”?

slide-26
SLIDE 26

26

Pyth thonic c vs. N

  • s. Non-pyth

thonic

slide-27
SLIDE 27

27

Pyth thonic c vs. N

  • s. Non-pyth

thonic

slide-28
SLIDE 28

28

Pyth thonic c vs. N

  • s. Non-pyth

thonic

slide-29
SLIDE 29

29

Is th s there a a d definiti tion f for “Pyth thonic” c”?

So it' t's “Using Pyth ython-specific syn yntax x and concep epts ts”, right? But t what t do devel eveloper ers bel elieve? eve?

slide-30
SLIDE 30

30

Let' t's ask k a f few d devel elopers

Interviews done

  • in Person
  • at a Python conference
  • in Spain
  • using open questions
slide-31
SLIDE 31

31

Let' t's ask k a f few d devel elopers

Interviews done

  • in Person
  • at a Python conference
  • in Spain
  • using open questions
slide-32
SLIDE 32

32

What t does P s Pythonic c me mean?

slide-33
SLIDE 33

33

What t does P s Pythonic c me mean?

“makes code easier to understand and maintain” “elegant and readable code” “boosts readability and performance”

slide-34
SLIDE 34

34

What t does P s Pythonic c me mean?

“makes code easier to understand and maintain” “using features provided by the language or standard library” “elegant and readable code” “boosts readability and performance”

slide-35
SLIDE 35

35

What t does P s Pythonic c me mean?

“makes code easier to understand and maintain” “using features provided by the language or standard library” “elegant and readable code” “boosts readability and performance” “simply the most accepted way of writing python”

slide-36
SLIDE 36

36

Usi Using Py Python i idioms ms != != Pyth thonic

slide-37
SLIDE 37

37

Usi Using Py Python i idioms ms != != Pyth thonic

→ → Using idioms ms != = Pyth ythonic code → → Using idioms ms != = always mo more e readable

slide-38
SLIDE 38

38

Novice ce vs. P

  • s. Pro

Novi

  • vice:

– Better style – Fewer lines of code

Pro:

  • :

– Using built-in functionality – Efficient execution

slide-39
SLIDE 39

39

Novice ce vs. P

  • s. Pro

Novi

  • vice:

– Better style – Fewer lines of code – Using idioms

Pro:

  • :

– Using built-in functionality – Efficient execution – Writing elegant code

slide-40
SLIDE 40

40

Novice ce vs. P

  • s. Pro

Novi

  • vice:

– Better style – Fewer lines of code – Using idioms – Simpler interpretation

Pro:

  • :

– Using built-in functionality – Efficient execution – Writing elegant code – Less concrete interpretation

slide-41
SLIDE 41

41

Le Learn rning ' 'Pyth thonic' c'?

slide-42
SLIDE 42

42

Le Learn rning ' 'Pyth thonic' c'?

“StackOverflow shows you multiple points of view of people, and you always learn.”

slide-43
SLIDE 43

43

Le Learn rning ' 'Pyth thonic' c'?

“StackOverflow shows you multiple points of view of people, and you always learn.” “reading code in repositories of other projects” “saw them in documentation”

slide-44
SLIDE 44

44

Le Learn rning ' 'Pyth thonic' c'?

“StackOverflow shows you multiple points of view of people, and you always learn.” “reading code in repositories of other projects” “from colleagues during code review” “saw them in documentation”

slide-45
SLIDE 45

45

Le Learn rning ' 'Pyth thonic' c'?

“StackOverflow shows you multiple points of view of people, and you always learn.” “Becoming a pythonic programmer takes time” “My code became more pythonic year after year” “reading code in repositories of other projects” “from colleagues during code review” “saw them in documentation”

slide-46
SLIDE 46

46

Le Learn rning ' 'Pyth thonic' c'?

“StackOverflow shows you multiple points of view of people, and you always learn.” “Becoming a pythonic programmer takes time” “My code became more pythonic year after year” “reading code in repositories of other projects” “from colleagues during code review” “saw them in documentation”

→ Pythonic not ta taught t in books or lec ectu tures → Seems eems to to cree eep in with th exp experien ence

slide-47
SLIDE 47

47

Do Do y you ca care? ? Do Do your r peer ers ca care?

slide-48
SLIDE 48

48

Do Do y you ca care? ? Do Do your r peer ers ca care?

“Pythonic code is positively viewed but not required”

slide-49
SLIDE 49

49

Do Do y you ca care? ? Do Do your r peer ers ca care?

“Pythonic code is positively viewed but not required” “If you're a novice Python programmer, better focus on general programming skills”

slide-50
SLIDE 50

50

Do Do y you ca care? ? Do Do your r peer ers ca care?

“Pythonic idioms can at least be used to measure a developer’s knowledge.” “Pythonic code is positively viewed but not required” “If you're a novice Python programmer, better focus on general programming skills”

slide-51
SLIDE 51

51

Do Do y you ca care? ? Do Do your r peer ers ca care?

“Pythonic idioms can at least be used to measure a developer’s knowledge.” “Pythonic code is positively viewed but not required” “If you're a novice Python programmer, better focus on general programming skills” “If I learn a new idiom I add it to my toolbox and then when I touch something, I modify it and leave it better, but it’s not an obsession.

slide-52
SLIDE 52

52

Do Do y you ca care? ? Do Do your r peer ers ca care?

“Pythonic idioms can at least be used to measure a developer’s knowledge.” “Pythonic code is positively viewed but not required” “If you're a novice Python programmer, better focus on general programming skills” “If I learn a new idiom I add it to my toolbox and then when I touch something, I modify it and leave it better, but it’s not an obsession.

→ Pythonic imp mporta tant, t, but t not fo forma mally → Pythonic signals exp exper ertise e and garners res espect

slide-53
SLIDE 53

53

A ca cata talogue of Py Pythonic I c Idioms ms

slide-54
SLIDE 54

54

A ca cata talogue of Py Pythonic I c Idioms ms

  • Published

ed online e at http ttp://p /pyth ythonic.libres esoft. t.info fo/c /cata talogue

– including examples, references and benchmarks

slide-55
SLIDE 55

55

A ca cata talogue of Py Pythonic I c Idioms ms

  • Published

ed online e at http ttp://p /pyth ythonic.libres esoft. t.info fo/c /cata talogue

– including examples, references and benchmarks

  • Co

Compiled ed fr from

– Several books (on learning and applying Python) – Online statements by influential and renowned Python developers

slide-56
SLIDE 56

56

A ca cata talogue of Py Pythonic I c Idioms ms

  • Published

ed online e at http ttp://p /pyth ythonic.libres esoft. t.info fo/c /cata talogue

– including examples, references and benchmarks

  • Co

Compiled ed fr from

– Several books (on learning and applying Python) – Online statements by influential and renowned Python developers

  • Cl

Classified ed into to “per erfo forma mance” e” and “rea eadability” ty”

– performance measured using benchmarks

slide-57
SLIDE 57

57

A ca cata talogue of Py Pythonic I c Idioms ms

slide-58
SLIDE 58

58

Em Empiri rica cal stu tudy

slide-59
SLIDE 59

59

Em Empiri rica cal study setu tup

  • Most

t rec ecen ent t commi mit t in 1000 Pyth ython projec ects ts fr from m GitH tHub

– >1mb, sorted by stars, cleaned for books etc., no forks, not archived – 178,735 files, 38,505,577 lines of code

slide-60
SLIDE 60

60

Em Empiri rica cal study setu tup

  • Most

t rec ecen ent t commi mit t in 1000 Pyth ython projec ects ts fr from m GitH tHub

– >1mb, sorted by stars, cleaned for books etc., no forks, not archived – 178,735 files, 38,505,577 lines of code

  • An

Analyz yzed ed using LIS ISA A (http tp:// //t.uzh zh.ch/Fk)

– AST-based detection of all idioms

slide-61
SLIDE 61

61

Em Empiri rica cal study setu tup

  • Most

t rec ecen ent t commi mit t in 1000 Pyth ython projec ects ts fr from m GitH tHub

– >1mb, sorted by stars, cleaned for books etc., no forks, not archived – 178,735 files, 38,505,577 lines of code

  • An

Analyz yzed ed using LIS ISA A (http tp:// //t.uzh zh.ch/Fk)

– AST-based detection of all idioms

  • Idiom occuren

ences es in #p #projec ects and total occurence e count

slide-62
SLIDE 62

62

Emp mpiri rica cal s study - a a quick ck look

Idiom # projects (out of 1000) # of occurences List comprehension 866 75,466 Generator expressions 709 33,038 Dict comprehension 146 796

slide-63
SLIDE 63

63

Emp mpiri rica cal s study - a a quick ck look

Idiom # projects (out of 1000) # of occurences List comprehension 866 75,466 Generator expressions 709 33,038 Dict comprehension 146 796 Simple magic methods Intermediate magic methods Advanced magic methods

slide-64
SLIDE 64

64

Emp mpiri rica cal s study - a a quick ck look

Idiom # projects (out of 1000) # of occurences List comprehension 866 75,466 Generator expressions 709 33,038 Dict comprehension 146 796 Simple magic methods Intermediate magic methods Advanced magic methods __nonzero__(self) Defines behavior for when bool() is called on an instance of your class. Should return True or False, depending on whether you would want to consider the instance to be True or False.

Magic methods

slide-65
SLIDE 65

65

Emp mpiri rica cal s study - a a quick ck look

Idiom # projects (out of 1000) # of occurences List comprehension 866 75,466 Generator expressions 709 33,038 Dict comprehension 146 796 Simple magic methods 759 78,376 Intermediate magic methods 417 13,255 Advanced magic methods 190 2,613

slide-66
SLIDE 66

66

Emp mpiri rica cal s study - a a quick ck look

Idiom # projects (out of 1000) # of occurences List comprehension 866 75,466 Generator expressions 709 33,038 Dict comprehension 146 796 Simple magic methods 759 78,376 Intermediate magic methods 417 13,255 Advanced magic methods 190 2,613

→ Mo More e in-depth th res esearch is need eded ed → Detec etecti ting anti-idioms ms is diffi fficult

slide-67
SLIDE 67

67

Wh What t we l learned so far

  • “Pyth

ythonic” is imp mporta tant t - somehow

slide-68
SLIDE 68

68

Wh What t we l learned so far

  • “Pyth

ythonic” is imp mporta tant t - somehow

  • “Pyth

ythonic” en encomp mpasses es mo more e th than just t programm mming idioms ms

slide-69
SLIDE 69

69

Wh What t we l learned so far

  • “Pyth

ythonic” is imp mporta tant t - somehow

  • “Pyth

ythonic” en encomp mpasses es mo more e th than just t programm mming idioms ms

  • Using “Pyth

ythonic idioms”...

– makes you appear more knowledgeable – alone does not

  • t necessarily make your code better or more pythonic
slide-70
SLIDE 70

70 70

Wh What t we l learned so far

  • “Pyth

ythonic” is imp mporta tant t - somehow

  • “Pyth

ythonic” en encomp mpasses es mo more e th than just t programm mming idioms ms

  • Using “Pyth

ythonic idioms”...

– makes you appear more knowledgeable – alone does not

  • t necessarily make your code better or more pythonic
  • “Pyth

ythonic” does es not always ys mea mean “more e rea eadable” e” fo for eve everyo yone

slide-71
SLIDE 71

71 71

Wh What t we l learned so far

  • “Pyth

ythonic” is imp mporta tant t - somehow

  • “Pyth

ythonic” en encomp mpasses es mo more e th than just t programm mming idioms ms

  • Using “Pyth

ythonic idioms”...

– makes you appear more knowledgeable – alone does not

  • t necessarily make your code better or more pythonic
  • “Pyth

ythonic” does es not always ys mea mean “more e rea eadable” e” fo for eve everyo yone

  • “Pyth

ythonic” is not t lea earned sys ystema temati tically

slide-72
SLIDE 72

72 72

Questi stions r s rema main... ...

  • Is th

there e someth mething spec ecial in th the cultu ture e of f Pyth ython?

– The Zen of Python / “one way to do it” – Why are there no words like “Rubyist”, “Javanese” or “C#y”

slide-73
SLIDE 73

73 73

Questi stions r s rema main... ...

  • Is th

there e someth mething spec ecial in th the cultu ture e of f Pyth ython?

– The Zen of Python / “one way to do it” – Why are there no words like “Rubyist”, “Javanese” or “C#y”

  • If

f “Pyth ythonic” is not t just t syn ynta tax x and idioms ms, what t is it?

slide-74
SLIDE 74

74 74

Questi stions r s rema main... ...

  • Is th

there e someth mething spec ecial in th the cultu ture e of f Pyth ython?

– The Zen of Python / “one way to do it” – Why are there no words like “Rubyist”, “Javanese” or “C#y”

  • If

f “Pyth ythonic” is not t just t syn ynta tax x and idioms ms, what t is it?

  • Does

es “Pyth ythonic” correl elate te with th code quality?

slide-75
SLIDE 75

75 75

Questi stions r s rema main... ...

  • Is th

there e someth mething spec ecial in th the cultu ture e of f Pyth ython?

– The Zen of Python / “one way to do it” – Why are there no words like “Rubyist”, “Javanese” or “C#y”

  • If

f “Pyth ythonic” is not t just t syn ynta tax x and idioms ms, what t is it?

  • Does

es “Pyth ythonic” correl elate te with th code quality?

  • Is “Pythonic” just

t a posh ma mark of pride e ser erving to crea eate te a tw two-ti tier er society ety with thin th the e Pyth ython commu mmunity?

slide-76
SLIDE 76

Carol V. Alexandru¹, José J. Merchante², Sebastiano Panichella¹,³ Sebastian Proksch¹, Harald C. Gall¹, Gregorio Robles²

Read the paper: http://t.uzh.ch/S7 Get the slides: http://t.uzh.ch/Sb Browse the catalogue: http://pythonic.libresoft.info/catalogue

On t the Usa Usage o

  • f P

Pyth thonic I c Idioms ms