Ratnadeep Debnath
Nick:
rtnpro
Mail: rtnpro AT gmail DOT com
FOSS contributor:
Currently working at
JOB SEcurity with Python!
Lightning talk @ Pycon US, 2013 by Christopher Neugebauer
What is Clean Code?
- Elegant
- Simple, direct & prose
- Readable
- Written with care
- Small, expressive, simple
- You get what you expect
Follow coding GUIDELINES
- Most languages have one
- e.g. PEP8 for Python (http://legacy.python.org/dev/peps/pep-0008/)
- Else the community comes up with one
Meaningful names
- Use intention revealing names
- Use pronounceable names
- Use searchable names
MANAGEABLE FUNCTIONS
- Small
- Do one thing
- Has no side effects
- DRY
- Structured programming
Document YOUR CODE
- Docstrings
- Document API
- Examples
- doctests
- Inline comments (only when needed)
- Comments should be replaced by readable names
- Don't add comments for bad code, rewrite it
code THAT CAN BE TESTED EASILY
If you need to think too much to write tests, then it's bad code ;)
-
TDD
-
Functional code is easy to test
-
Abstract out external deps
- Make code depend on data elements (rather than objects)
- removes the need for mocking
READ, READ, READ
Read a lot of source codes
(of good open source projects)
CONTRIBUTE
The Open Source community has a lot to teach :)