marp |
---|
true |
Karthikeyan Singaravelan /(Software Engineer at Platform Portal | Python core developer)/
Agenda
- Better abstractions
- Developer tooling
- Testing
- Performance
- 30 years of active development.
- Zen of Python.
- PEP8 as a standard.
- Learn more about dunder methods and protocols.
- Using properties and caching.
- Abstractions in standard library.
- Context manager protocol
__enter__
and__exit__
for resource management. - contextlib module provides handy wrappers.
try:
db = Database()
db.query()
finally:
db.close()
with Database() as db:
db.query()
- Properties for computational attributes. Cache them if they are immutable.
class Person:
first_name: str
last_name: str
def get_full_name(self):
return f"{first_name} {last_name}"
@property
def full_name(self):
return f"{first_name} {last_name}"
- collections - namedtuple, defaultdict, Counter.
- itertools - functional constructs
- command line interface for modules - zipfile, tarfile, json, etc.
- Dataclasses.
collection = {}
for student, mark in marks:
if mark not in collection:
collection[mark] = []
else:
collection[mark].append(student)
from collections import defaultdict
collection = defaultdict(list)
for student, mark in marks:
collection[mark].append(student)
- Helps catch potential errors in future.
- Ensures smooth upgrade process.
- IPython and notebook for interactive sessions.
- timeit for benchmarking. pyperformance from PyPI.
- CProfile for profiling.
- Automatic formatting - Choose one tool - autopep8, yapf, black.
- pdb for debugging. ipdb, pudb from PyPI.
- Optional typing with mypy.
- Use pytest for concise tests.
- Use coverage for code coverage.
- Use unittest.mock for mocking tests.
- Linters : flake8 and pylint.
- pypy is a JIT for computation intensive code.
- Cython for writing C interface code.
- Use native interface libraries. E.g. numpy, pandas, scipy, etc.