CODiNG FOR HUMANS




WHO AM I?

Ratnadeep Debnath


Nick: rtnpro
Mail: rtnpro AT gmail DOT com
Creator & maintainer @ https://waartaa.com


FOSS contributor:

Currently working at
 




Let's Have some fun!




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




Measurement of good code






How to write clean code?

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 :)




THANKS!

CODING FOR HUMANS

By Ratnadeep Debnath

CODING FOR HUMANS

  • 1,599