Simplify the examples and make them more specific

Bug #1487269 reported by Everett Toews
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack SDK
Fix Released
Undecided
Everett Toews

Bug Description

The majority of the current example code mimics a CLI. It does this in a very generic way with indirection and parsing arguments to discover module names. This is very clever and effective but it is not very instructive to users who are likely new to OpenStack and possibly even new to Python.

Consider this, if a user new to the SDK asked for example code to create a server, what file would you link them to? If it's example/create.py then that user will be lost almost immediately since there is nothing about creating a server in that example. They would need to understand the example code deeply just to decipher how to create a server.

The number one property of examples is that they should be instructive. We can make them instructive by making them simple, straight-forward, and easily understood. They can be simplified by making them linearly readable without having to bounce around to many source files to understand one example. They can be straight-forward by having them designed for one purpose (e.g. listing compute resources, creating block storage resources, etc). And they can be easily understood by having them split into separate and stand-alone functions.

Some nice properties emerge when we follow these principles. The example functions are testable, ensuring ongoing quality. We can display the functions from within the user guides using literalinclude with the :lines: option. That means that not only are our examples tested but our user guides are tested too!

All of this also make the examples very easy to copy/paste from. This a very important property for busy developers. If you've ever written example code for a popular SDK before, you'll know this as you'll see the example code you've written reflected back at you in StackOverflow, forums, and email. It makes you want it to be the most clear and concise code you've ever written because it gets used everywhere.

Revision history for this message
Terry Howe (thowe-g) wrote :

I agree, but I'd like to keep some bits useful for developers. I use examples/connection.py mostly because it is a basic proxy level example and I just modify it to test whatever.

I think it'd be great if we discontinued a lot of CLI argparse support and just used OCC.

The only other example I use a fair amount is examples/list.py, but maybe that could go.

Changed in python-openstacksdk:
assignee: nobody → Everett Toews (everett-toews)
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to python-openstacksdk (master)

Fix proposed to branch: master
Review: https://review.openstack.org/215823

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to python-openstacksdk (master)

Reviewed: https://review.openstack.org/215823
Committed: https://git.openstack.org/cgit/stackforge/python-openstacksdk/commit/?id=7e98020b837548c063b5fb0b3c9b1e49940230d5
Submitter: Jenkins
Branch: master

commit 7e98020b837548c063b5fb0b3c9b1e49940230d5
Author: Everett Toews <email address hidden>
Date: Fri Aug 21 15:37:14 2015 -0500

    The Compute User Guide

    The beginning of the compute user guide.

    This also begins the simplification of the examples, makes them
    more specific, and adds testing.

    Change-Id: Ic4bac2fe30601c196b03ce73b2dd04a916231f33
    Partial-Bug: #1487269
    Partial-Bug: #1419012
    Partial-Bug: #1466180

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to python-openstacksdk (master)

Fix proposed to branch: master
Review: https://review.openstack.org/241446

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to python-openstacksdk (master)

Reviewed: https://review.openstack.org/241446
Committed: https://git.openstack.org/cgit/openstack/python-openstacksdk/commit/?id=6f2376ee8bff1233cbaf54c87d7510e7275d09f0
Submitter: Jenkins
Branch: master

commit 6f2376ee8bff1233cbaf54c87d7510e7275d09f0
Author: Everett Toews <email address hidden>
Date: Tue Nov 3 20:40:26 2015 -0600

    Remove the example code that mimics a CLI

    Change-Id: I84c990b5a73a4690c26d52bcc46eb936fdd4c1b8
    Partial-Bug: #1487269

Changed in python-openstacksdk:
status: In Progress → Fix Committed
Revision history for this message
Everett Toews (everett-toews) wrote :
Changed in python-openstacksdk:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.