Type Less,
Code Better

Python MetaProgramming
with Spreadsheets


Javier Candeira / @candeira
Watch video / Get Code
Pycon Australia. Brisbane, 1 August 2015.

Hi, I'm Javier

I help people solve their business needs with code.

This is Jenn

She needs to validate some data from an energy regulator.

She has a compete description of the validation rules.

In a spreadsheet.

This is Adrian

He needs to test a medical instrument.

He has a compete description of both the instrument to be tested and the dedicated tester hardware.

In a spreadsheet.


Spreadsheets are
enablers of order

Users often evolve strong conventions

to help them organise their information...


The spreadsheet as tool
and as document

You can pick either or both.

Organised people are consistent

Their spreadsheets become informal specs

Maybe we can use code to interpret these specs.

(By metaprogramming).


Metaprogramming

Preventing errors... of a certain type.

Reducing bugs by reducing lines of code.

Making bugs consistent by making asumptions explicit.

Clarifying ambiguous specifications.


Metaprogramming saves time

Reducing turnaround latency in response to changes.

Giving more time to new features and less to solving defects.

(Like TDD, it involves an upfront investment of time, returned later with interest).


It yields more readable code

  • By producing much more consistent code.

    (via code generation)

  • By yielding better APIs.

    (via reflection)


Metaprogramming saves bugs

Preventing errors... of a certain type.

Reducing bugs by reducing lines of code.

Making bugs consistent by making asumptions explicit.

Clarifying ambiguous specifications.


Metaprogramming saves time

Reducing turnaround latency in response to changes.

Giving more time to new features and less to solving defects.

(Like TDD, it involves an upfront investment of time, returned later with interest).


It yields more readable code

  • By producing much more consistent code.

    (via code generation)

  • By yielding better APIs.

    (via reflection)

Different problems,
different solutions

Problem Technology Solution
Data Validation Django Code Generation
Hardware API LabJack Device Reflection
Yours !! ??

Reflection vs Generation

Code Generation Reflection
Compile-time Spreadsheet read
Run-Time Spreadsheet read
Code written by Your program You

THE PLAN

- Code generation with Django (Tutorial)
- API design and implementation via Reflection (Tutorial)

THE NEW PLAN

- API design and implementation via Reflection (Tutorial)
- Code generation with Django (Demo) (Maybe)

Do the tutorial!

  1. Download the repo, install it, get the iPython Notebook working.
  2. Start the video, and stop when I start interacting with the iPython Notebook.
  3. Interact with the iPython notebook until you're happy that you understand the previous point made in the video.
  4. GOTO 3

Thank You

javier@candeira.com

@candeira

http://hiperactivo.com/talks/