Slide 1

Slide 1 text

Pragmatic Python Sunghyun Hwang

Slide 2

Slide 2 text

2 ടࢿഅ Sunghyun Hwang • Software Engineer at Rainist Co., Ltd. • Python 2014 ~ • Scala 2017 ~ • Microservice Architecture 2017 ~ • Email: [email protected] • Twitter: @_sunghyunzz • Github: @sunghyunzz

Slide 3

Slide 3 text

3 Is Python Pragmatic? "

Slide 4

Slide 4 text

import unittest class PragmaticPythonTest(unittest.TestCase): def test_is_python_pragmatic(self): self.assertTrue( are_many_companies_using_python('KR') ) import unittest class PragmaticPythonTest(unittest.TestCase): def test_is_python_pragmatic(self): self.assertTrue( are_many_companies_using_python('KR') ) 4

Slide 5

Slide 5 text

import unittest class PragmaticPythonTest(unittest.TestCase): def test_is_python_pragmatic(self): self.assertTrue( are_many_companies_using_python('KR') ) import unittest class PragmaticPythonTest(unittest.TestCase): def test_is_python_pragmatic(self): self.assertTrue( are_many_companies_using_python('KR') ) 5

Slide 6

Slide 6 text

6 https://www.wanted.co.kr/wdlist/518/899?sort=-count

Slide 7

Slide 7 text

7 https://www.wanted.co.kr/wdlist/518/899?sort=-count

Slide 8

Slide 8 text

8 https://www.wanted.co.kr/wdlist/518/899?sort=-count

Slide 9

Slide 9 text

import requests URL = 'https://www.wanted.co.kr/api/v3/search?country=KR' def fetch_nr_of_jobs(q: str) -> int: r = requests.get(f'{URL}&query={q}') return r.json()['data']['jobs']['total'] fetch_nr_of_jobs('Python+Developer') # 115 fetch_nr_of_jobs('Server+Developer') # 269 import requests URL = 'https://www.wanted.co.kr/api/v3/search?country=KR' def fetch_nr_of_jobs(q: str) -> int: r = requests.get(f'{URL}&query={q}') return r.json()['data']['jobs']['total'] fetch_nr_of_jobs('Python+Developer') fetch_nr_of_jobs('Server+Developer') 9

Slide 10

Slide 10 text

import requests URL = 'https://www.wanted.co.kr/api/v3/search?country=KR' def fetch_nr_of_jobs(q: str) -> int: r = requests.get(f'{URL}&query={q}') return r.json()['data']['jobs']['total'] fetch_nr_of_jobs('Python+Developer') # 115 fetch_nr_of_jobs('Server+Developer') # 269 import requests URL = 'https://www.wanted.co.kr/api/v3/search?country=KR' def fetch_nr_of_jobs(q: str) -> int: r = requests.get(f'{URL}&query={q}') return r.json()['data']['jobs']['total'] fetch_nr_of_jobs('Python+Developer') fetch_nr_of_jobs('Server+Developer') 10

Slide 11

Slide 11 text

import requests URL = 'https://www.wanted.co.kr/api/v3/search?country=KR' def fetch_nr_of_jobs(q: str) -> int: r = requests.get(f'{URL}&query={q}') return r.json()['data']['jobs']['total'] fetch_nr_of_jobs('Python+Developer') # 115 fetch_nr_of_jobs('Server+Developer') # 269 import requests URL = 'https://www.wanted.co.kr/api/v3/search?country=KR' def fetch_nr_of_jobs(q: str) -> int: r = requests.get(f'{URL}&query={q}') return r.json()['data']['jobs']['total'] fetch_nr_of_jobs('Python+Developer') fetch_nr_of_jobs('Server+Developer') 11

Slide 12

Slide 12 text

import requests URL = 'https://www.wanted.co.kr/api/v3/search?country=KR' def fetch_nr_of_jobs(q: str) -> int: r = requests.get(f'{URL}&query={q}') return r.json()['data']['jobs']['total'] fetch_nr_of_jobs('Python+Developer') # 115 fetch_nr_of_jobs('Server+Developer') # 269 import requests URL = 'https://www.wanted.co.kr/api/v3/search?country=KR' def fetch_nr_of_jobs(q: str) -> int: r = requests.get(f'{URL}&query={q}') return r.json()['data']['jobs']['total'] fetch_nr_of_jobs('Python+Developer') fetch_nr_of_jobs('Server+Developer') 12

Slide 13

Slide 13 text

import requests URL = 'https://www.wanted.co.kr/api/v3/search?country=KR' def fetch_nr_of_jobs(q: str) -> int: r = requests.get(f'{URL}&query={q}') return r.json()['data']['jobs']['total'] fetch_nr_of_jobs('Python+Developer') # 115 fetch_nr_of_jobs('Server+Developer') import requests URL = 'https://www.wanted.co.kr/api/v3/search?country=KR' def fetch_nr_of_jobs(q: str) -> int: r = requests.get(f'{URL}&query={q}') return r.json()['data']['jobs']['total'] fetch_nr_of_jobs('Python+Developer') # 115 fetch_nr_of_jobs('Server+Developer') 13

Slide 14

Slide 14 text

import requests URL = 'https://www.wanted.co.kr/api/v3/search?country=KR' def fetch_nr_of_jobs(q: str) -> int: r = requests.get(f'{URL}&query={q}') return r.json()['data']['jobs']['total'] fetch_nr_of_jobs('Python+Developer') # 115 fetch_nr_of_jobs('Server+Developer') # 269 import requests URL = 'https://www.wanted.co.kr/api/v3/search?country=KR' def fetch_nr_of_jobs(q: str) -> int: r = requests.get(f'{URL}&query={q}') return r.json()['data']['jobs']['total'] fetch_nr_of_jobs('Python+Developer') # 115 fetch_nr_of_jobs('Server+Developer') # 269 14

Slide 15

Slide 15 text

15

Slide 16

Slide 16 text

16 PEP 20 — The Zen of Python https://www.python.org/dev/peps/pep-0020/

Slide 17

Slide 17 text

(…) Simple is better than complex. (…) Readability counts. (…) If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. (…) (…) Simple is better than complex. (…) Readability counts. (…) If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. (…) 17 PEP 20 — The Zen of Python https://www.python.org/dev/peps/pep-0020/

Slide 18

Slide 18 text

(…) Simple is better than complex. (…) Readability counts. (…) If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. (…) (…) Simple is better than complex. (…) Readability counts. (…) If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. (…) 18 PEP 20 — The Zen of Python https://www.python.org/dev/peps/pep-0020/

Slide 19

Slide 19 text

(…) Simple is better than complex.. (…) Readability counts. (…) If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. (…) (…) Simple is better than complex. (…) Readability counts. (…) If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. (…) 19 PEP 20 — The Zen of Python https://www.python.org/dev/peps/pep-0020/

Slide 20

Slide 20 text

20 if 'birth' < c < 'death': pass

Slide 21

Slide 21 text

21 s = {1, 2, 3} print(4 in s) l = [1, 2] * 5 print(l[:-1]) d = {1: 1, 2: 4, 3: 9} print(d[3])

Slide 22

Slide 22 text

22 data = [1, 2, 3] sum(d ** 2 for d in data)

Slide 23

Slide 23 text

23 l = [1, 2, 3, 4, 5] d = { i: i ** i for i in l if i % 2 == 1 }

Slide 24

Slide 24 text

24 def fib(n): a, b = 0, 1 for i in range(n): a, b = b, a + b return a

Slide 25

Slide 25 text

25 from itertools import permutations data = [1, 2, 3] for case in permutations(data): pass

Slide 26

Slide 26 text

26 import json d = {'org': 'Django Girls Seoul'} json.dumps(d)

Slide 27

Slide 27 text

27 from flask import Flask app = Flask(__name__) @app.route("/") def hello(): return "Hello World!"

Slide 28

Slide 28 text

28 https://twitter.com/gvanrossum/statuses/1372452815

Slide 29

Slide 29 text

29 https://madnight.github.io/githut/#/pull_requests/2018/1

Slide 30

Slide 30 text

Python Java C# PHP JavaScript Google Trends: KR, 2015-04-29 ~ 2018-04-29 30

Slide 31

Slide 31 text

Google Trends: KR, 2015-04-29 ~ 2018-04-29 31

Slide 32

Slide 32 text

32 Card Recommendation O(NC * NG * NB * NS) • NC = number of cards • NG = number of benefit groups per card • NB = number of benefits per benefit group • NS = number of user spendings

Slide 33

Slide 33 text

33 import timeit def calc(): s = 0 for i in range(10 ** 8): s += i return s print( timeit.timeit( "calc()", setup="from __main__ import calc", number=1 ) )

Slide 34

Slide 34 text

34 import timeit def calc(): s = 0 for i in range(10 ** 8): s += i return s print( timeit.timeit( "calc()", setup="from __main__ import calc", number=1 ) ) 7.25s

Slide 35

Slide 35 text

35 val t1 = System.nanoTime() var s: Long = 0 for (i ← 1 to 100000000) { s += i } val t2 = System.nanoTime() println((t2 - t1) / 1000000000.0)

Slide 36

Slide 36 text

36 val t1 = System.nanoTime() var s: Long = 0 for (i ← 1 to 100000000) { s += i } val t2 = System.nanoTime() println((t2 - t1) / 1000000000.0) 0.36s

Slide 37

Slide 37 text

37 https://martinfowler.com/articles/microservices.html

Slide 38

Slide 38 text

38

Slide 39

Slide 39 text

39

Slide 40

Slide 40 text

40 jg (user card)

Slide 41

Slide 41 text

41 jg (user card) alfred (card)

Slide 42

Slide 42 text

42 jg (user card) alfred (card) poong (promotion)

Slide 43

Slide 43 text

43 jg (user card) biryong (contents) alfred (card) poong (promotion)

Slide 44

Slide 44 text

44 jg (user card) biryong (contents) alfred (card) poong (promotion) dishwasher (FAQ)

Slide 45

Slide 45 text

45 https://www.redhat.com/en/blog/state-microservices Respondents believe in “using the right tool for the right task” According to 44% Middleware respondents & 50% OpenShift respondents

Slide 46

Slide 46 text

46 https://www.redhat.com/en/blog/state-microservices of respondents are using or considering multiple technologies for microservices. 87%

Slide 47

Slide 47 text

47 Python Scala Node.js Others * back-end services only Microservices in Banksalad

Slide 48

Slide 48 text

Prototyping I/O HTTP API Tasks (script) Data Science & Analysis Small Functions in MSA Prototyping I/O HTTP API Tasks (script) Data Science & Analysis Small Functions in MSA 48

Slide 49

Slide 49 text

Prototyping I/O HTTP API Tasks (script) Data Science & Analysis Small Functions in MSA Prototyping I/O HTTP API Tasks (script) Data Science & Analysis Small Functions in MSA 49

Slide 50

Slide 50 text

Prototyping I/O HTTP API Tasks (script) Data Science & Analysis Small Functions in MSA Prototyping I/O HTTP API Tasks (script) Data Science & Analysis Small Functions in MSA 50

Slide 51

Slide 51 text

Prototyping I/O HTTP API Tasks (script) Data Science & Analysis Small Functions in MSA Prototyping I/O HTTP API Tasks (script) Data Science & Analysis Small Functions in MSA 51

Slide 52

Slide 52 text

52

Slide 53

Slide 53 text

Prototyping I/O HTTP API Tasks (script) Data Science & Analysis Small Functions in MSA Prototyping I/O HTTP API Tasks (script) Data Science & Analysis Small Functions in MSA 53

Slide 54

Slide 54 text

Prototyping I/O HTTP API Tasks (script) Data Science & Analysis Small Functions in MSA Prototyping I/O HTTP API Tasks (script) Data Science & Analysis Small Functions in MSA 54

Slide 55

Slide 55 text

55 2015.5.3 2018.4.22 Microservice Google Trends: 2015-05-03 ~ 2018-04-22

Slide 56

Slide 56 text

56 import antigravity

Slide 57

Slide 57 text

57 import antigravity https://xkcd.com/353/

Slide 58

Slide 58 text

58 Join Us! https://rainist.com/recruit/engineer • Back-end Engineer (Python/Scala) • Devops Engineer • Data Engineer • Data Scientist • Growth Hacker • Web Front-end Engineer • Android Engineer • iOS Engineer • QA Engineer • Security Engineer