You're Writing Too Much Code

Let Python Reflection do the Work

John McDonough

APIs Configuration Management (Ansible/Fabric/Chef/...) Programming Python general python

See in schedule

The ability of a programming language to do introspection, better known as reflection can dramatically reduce the amount of code you write. What is reflection, how do you use it and will it fit your scenario are common questions. With a well-defined API, reflection allows you to reduce your code to an object agnostic processing engine. Reflection-enabling Python methods getattr() and setattr() used with dynamic module importing allow you to move your "code" to a configuration file, regardless of the configuration file encoding, JSON, YAML, XML, etc. This session will go over the important elements of an API that assist with reflection, how to "reflect" and separate "code" from "configuration" and show how I took thousands of lines of purpose written code to less than twenty lines of object agnostic code.

Type: Talk (30 mins); Python level: Beginner; Domain level: Beginner


John McDonough

Cisco Systems, Inc.

John McDonough is a Technical Leader for Cisco DevNet in the role of Data Center Programmability and Automation Advocate. John is responsible for promoting the consumption of the Cisco Data Center Management and Automation APIs. John’s application development and delivery experience is well suited to assist customers, both internal and external in fully utilizing the power of these APIs.