Search Python code for algorithmic features
Project description
Introduction
Paroxython is a set of command line tools which tag a collection of Python programs and filter them by algorithmic features.
Audience
You are a teacher, in charge of an introductory programming course in an educational institution. Over the years, you have accumulated many—far too many—programs and code snippets that may be of interest to your students.
Or, as a seasoned developer, you would like to share your knowledge by helping a loved one learn how to code. A cursory search for pedagogical material yields an overwhelming amount of websites and repositories stuffed with Python programs of various levels (e.g., 1, 2, 3, 4, 5, 6, and a lot more from Awesome Python in Education).
In any case, the Python source codes you have gathered are typically numerous (hundreds or even thousands), reasonably sized (anything below 1000 SLOC), and educational in nature (e.g., snippets, examples, quizzes, exercise solutions, classic algorithms). The programming concepts you plan to teach remain relatively low level (e.g. assignments, nested loops, accumulation patterns, tail-recursive functions, etc.).
If all that sounds familiar, keep reading me to see what Paroxython can do for you.
Main goals
Paroxython aims to help you select, from your collection, the one program that suits your needs. For instance, it will gladly answer the following questions:
- How can this concept be illustrated?
- What problems use the same algorithmic and data structures as this one?
- What homework assignment should I give my students so they can practice the content of the last lesson?
Since it knows what your class knows, it can recommend the right program at the right time:
- What would make a good review exercise?
- Which exercises can I give on this exam?
- What is the current learning cost of this example?
In the long run, it may guide you and somehow make you rethink your course outline:
- What are the prerequisites for the concept of assignment?
- Do I have enough material to introduce subroutines before I even talk about conditionals and loops?
- Among the loops, which must come first: the most powerful (
while
), or the most useful (for
)?- How to logically structure this bunch of usual iterative patterns?
- What are the basics, exactly?
All issues on which the author changed his mind since he started to work on this project!
In an ideal world, Paroxython could even put an end to the deadliest religious wars, with rational, data-driven arguments:
- Father, is it a sin to exit early?
- Should a real byte use a mask?
How it works
Specifications
+
Programs → Labels
+
Taxonomy → Tag database
+
Command pipeline → Recommendations
Paroxython starts by building a tag database from a given folder of programs. Tagging these programs is a two-step process:
- First, all features that meet the provided specifications are identified by free-form internal-use labels (e.g.,
assignment_lhs_identifier:a
orloop_with_late_exit:while
), and associated with their spanning lines (e.g., 4 or 5-7). - These labels are then mapped onto a knowledge taxonomy designed with basic hierarchical constraints in mind (e.g., the fact that the introduction of the concept of early exit must come after that of loop, which itself requires that of control flow, is expressed with the following taxon:
flow/loop/exit/early
).
The tag database can finally be filtered through a pipeline of commands, for instance: - include only the programs which feature a recursive function; - exclude this or that program which you are reserving for the exam; - “impart” all programs studied so far, i.e, consider that all the notions they implement are acquired.
The result is a list of program recommendations ordered by increasing learning cost.
Note that the label specification file is provided. For converting labels to taxa, a default taxonomy is also provided, but you may feel the need to tailor it to your own vision of the course. Initially, the pipeline can be left empty: the recommendations will then cover all programs, sorted by increasing level of knowledge.
Example
Suppose that the directory programs
contains these simple programs. First, build this tag database:
> paroxython collect programs
Labelling 21 programs.
Mapping taxonomy on 21 programs.
Writing programs_db.json.
Then, filter it through this pipeline:
> paroxython recommend -p programs_pipe.py programs_db.json
Processing 5 commands on 21 programs.
19 programs remaining after operation 1 (impart).
18 programs remaining after operation 2 (exclude).
12 programs remaining after operation 3 (exclude).
10 programs remaining after operation 4 (include).
10 programs remaining after operation 5 (hide).
Dumped: programs_recommendations.md.
Et voilà your recommendation report!
Installation and test-drive
Command line
Much to no one's surprise:
pip install paroxython
The following command should print a help message and exit:
paroxython --help
IPython magic command
If you use Jupyter notebook/lab, you've also just installed a so-called magic command. Load it like this:
%load_ext paroxython
And run it on a cell of Python code (line numbers added for clarity):
1 %%paroxython
2 def fibonacci(n):
3 result = []
4 (a, b) = (0, 1)
5 while a < n:
6 result.append(a)
7 (a, b) = (b, a + b)
8 return result
Taxon | Lines |
---|---|
call/method/append |
6 |
flow/loop/exit/late |
5-7 |
flow/loop/while |
5-7 |
metadata/program |
2-8 |
metadata/sloc/8 |
2-8 |
operator/arithmetic/addition |
7 |
subroutine/argument/arg |
2 |
subroutine/function |
2-8 |
test/inequality |
5 |
type/number/integer/literal |
4 |
type/number/integer/literal/zero |
4 |
type/sequence/list |
6 |
type/sequence/list/literal/empty |
3 |
type/sequence/tuple/literal |
4, 4, 7, 7 |
variable/assignment/parallel |
4 |
variable/assignment/parallel/slide |
7 |
variable/assignment/single |
3 |
Further reading
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for paroxython-0.4.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 40e096babb4046d89a8d85d5bf9ee31d7e787dd52e3595f7dac1a0238a94e180 |
|
MD5 | aa91436a307ba09d39ab5fd318097d9e |
|
BLAKE2b-256 | d55c64ff0df9a2b99ea5558a6a8c5367207d9adfacf465b1b23efff69982afa9 |