GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - fluentpython/abacus: Metaprogramming in service of user experience

BranchesTags
Open more actions menu

Latest commit

 

History

7 Commits
7 Commits

Folders and files

NameName
Last commit message
Last commit date
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
abacus.py
abacus.py
 
 
plain_abacus.py
plain_abacus.py
 
 
pyproject.toml
pyproject.toml
 
 

Repository files navigation

abacus

The abacus module is an example of module metaprogramming in service of developer experience.

The end-user APIs for plain_abacus and abacus are the same. Please view their module-level docstrings for examples.

But abacus uses metaprogramming to elliminate the code duplication in the add and sub functions of plain_abacus.

The metaprogramming features are:

  • @command: decorator to register a method name as a command;
  • @command_alias: decorator to register a method name and aliases as a command;
  • _make_command: builds a stand-alone function from an Abacus method;
  • _install_commands: makes commands and installs them as global functions;

Note: abacus has more lines of code and is much harder to understand than plain_abacus. However, this example was inspired by the jupyturtle project, where the Turtle class has many more methods than Abacus, therefore coding each global function by hand would require a lot of duplication and many more lines of code.

When using metaprogramming, it's always a good idea to consider whether the added complexity is worthwhile.

About

Metaprogramming in service of user experience

Resources

Readme
BSD-3-Clause license
Activity
Custom properties

Stars

6 stars

Watchers

2 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.