Software maintenance PyConUK 2016

44
1 So you "want" to maintain a Python legacy code base PyConUK 2016 César Cardenas Desales

Transcript of Software maintenance PyConUK 2016

Page 1: Software maintenance PyConUK 2016

1

So you "want" to maintain a Python legacy code basePyConUK 2016César Cardenas Desales

Page 2: Software maintenance PyConUK 2016

2

About me

● Software Architect at Webrepublic AG

● Python user since v.2.0

● Co-organizer of the Swiss Python Summit (i.e. PyCon Switzerland) and the Zurich Python User Group

Page 3: Software maintenance PyConUK 2016

3

Agenda

❖ Introduction

❖ Maintenance “framework”

1. Understand (your system)

2. Safety net

3. Improve

Page 4: Software maintenance PyConUK 2016

4

Introduction

Page 5: Software maintenance PyConUK 2016

5

Why discuss maintenance?

● 50% software cost - Barry Boehm

● 40 to 80% software costs - Robert L. Glass

Page 6: Software maintenance PyConUK 2016

6

Computer programming

Page 7: Software maintenance PyConUK 2016

7

Software maintenance

Page 8: Software maintenance PyConUK 2016

8

Page 9: Software maintenance PyConUK 2016

9

Software maintenance?

Page 10: Software maintenance PyConUK 2016

10

Page 11: Software maintenance PyConUK 2016

11

Automotive Industry

● Warranty? 5 years or 100,000 KM● Life-time: 100,000 to 200,000 KM

Page 12: Software maintenance PyConUK 2016

12

Rail Industry

● Short cycle maintenance: 80 years

Page 13: Software maintenance PyConUK 2016

13

Rail Industry

● Short cycle maintenance: 80 years● Long cycle maintenance: 150 years

Page 14: Software maintenance PyConUK 2016

14

IT Industry?

● Linux kernel: 1991, 25 years ● LaTeX: 1985, 31 years● U.S. Treasury Department - Individual Master File: 56

years

Page 15: Software maintenance PyConUK 2016

15

IT Industry?

● Linux kernel: 1991, 25 years ● LaTeX: 1985, 31 years● U.S. Treasury Department - Individual Master File: 56

years ● Probably many Fortran or Cobol systems

COBOL programmer wanted

- 5 years experience life expectancy

Page 16: Software maintenance PyConUK 2016

16

IT Industry?

● Linux kernel: 1991, 25 years ● LaTeX: 1985, 31 years● U.S. Treasury Department - Individual Master File: 56

years ● Probably many Fortran or Cobol systems

● Mine WAS 4 years● Yours?

Page 17: Software maintenance PyConUK 2016

17

Maintenance: Raffle of a Tiger

Page 18: Software maintenance PyConUK 2016

18

The life of a maintainer (i.e. me)

1. “Our code is messy”2. “Everyone’s code is messy” (3k LOC class)3. “Somebody’s code is messy”

Page 19: Software maintenance PyConUK 2016

19

1 Understand

Page 20: Software maintenance PyConUK 2016

20

1 Understand - Context

● Code doesn’t live in a void

● Ask users● THE business case● Interview power users● Create personas● Read use cases● Write use cases

Page 21: Software maintenance PyConUK 2016

21

1 Understand - Architecture

● Understand the architecture

● Create diagrams

Page 22: Software maintenance PyConUK 2016

22

1 Understand - Architecture

● Print critical code● Read the code● Do code walkthroughs● Rubber duck debugging

Page 23: Software maintenance PyConUK 2016

23

1 Understand - Docs

● Read the docs● Write the docs● Comment the code

● Docstrings● Doxygen● Sphingx

Page 24: Software maintenance PyConUK 2016

24

1 Understand - Debug it

● Observe program behaviour● For the sake of it

● pdb● pudb● ipdb● Bugjar● Winpdb● Your IDE

Page 25: Software maintenance PyConUK 2016

25

1 Understand - Profile it

● Does 80/20 hold?

● cProfile, profile● timeit● heapy● memory_profiler● Your IDE● top, htop● IPython SnakeViz

Page 26: Software maintenance PyConUK 2016

26

1 Understand - Break it

● Scalability?● What breaks?● Why does it break?● Does it matter?● Recovery?

● nose, pytest● Apache Benchmark● Locust● JMeter● Adhoc scripts

Page 27: Software maintenance PyConUK 2016

27

2 Safety net

Page 28: Software maintenance PyConUK 2016

28

2 Safety net - Automated tests

● Regression tests● Acceptance tests● Data driven tests

● nose, pytest● coverage● selenium● tox

Page 29: Software maintenance PyConUK 2016

29

2 Safety net - Fail often and early

● Neutral/Nightly build● Continuous Integration

● Broken build =>

Not safe to release

Page 30: Software maintenance PyConUK 2016

30

2 Safety net - The build

● Github protected branches

● Jenkins● Buildout● Buildbot● Travis CI

Page 31: Software maintenance PyConUK 2016

31

2 Safety net - Monitoring

● What errors are current?● Opbeat

Page 32: Software maintenance PyConUK 2016

32

2 Safety net - Monitoring

● Visualize and filter log entries● Logstash + Kibana

Page 33: Software maintenance PyConUK 2016

33

2 Safety net - Automate it all

● Because humans make mistakes

● Provisioning deployment

● Ansible● Salt● Puppet● Chef

Page 34: Software maintenance PyConUK 2016

34

3 Improve

Page 35: Software maintenance PyConUK 2016

35

3 Improve - The code

● Leave the code cleaner than you found it

● pep8 -> pycodestyle● Flake8 (PyFlakes + pycodestyle)● pylint● radon● Your IDE

Page 36: Software maintenance PyConUK 2016

36

3 Improve - The code

● Radon○ LOC, SLOC○ Cyclomatic Complexity○ Maintainability Index○ Halstead Metrics

Page 37: Software maintenance PyConUK 2016

37

Page 38: Software maintenance PyConUK 2016

38

3 Improve - The code

$ radon cc -o SCORE -s -a processing/tasks.py

Page 39: Software maintenance PyConUK 2016

39

3 Improve - The code

$ pylint bot.py

Page 40: Software maintenance PyConUK 2016

40

3 Improve - The people

● TDD if possible● Do Code Reviews

Page 41: Software maintenance PyConUK 2016

41

3 Improve - The people

● Code Reviews○ Spread knowledge○ The Ego Factor○ Increase quality of software

“Your reputation at stake with every commit”

Page 42: Software maintenance PyConUK 2016

42

3 Improve - The people

● Code Reviews○ Easily done with Github○ Like washing your hands

after going to the toilet

Page 43: Software maintenance PyConUK 2016

43

Ask me

● Ascend a Swiss (Python) summit

● Why can you buy cornish pasties in Mexico

Page 44: Software maintenance PyConUK 2016

44

Let’s make it happen.Thank you.

@ccdesales