- Notifications
You must be signed in to change notification settings - Fork0
Metaprogramming in service of user experience
License
fluentpython/abacus
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Theabacus
module is an example of module metaprogrammingin service of developer experience.
The end-user APIs forplain_abacus
andabacus
are the same.Please view their module-level docstrings for examples.
Butabacus
uses metaprogramming to elliminate the codeduplication in theadd
andsub
functions ofplain_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 anAbacus
method;_install_commands
: makes commands and installs them as global functions;
Note:abacus
has more lines of code and is much harder to understand thanplain_abacus
.However, this example was inspired by thejupyturtle project,where theTurtle
class has many more methods thanAbacus
,therefore coding each global function by hand would requirea lot of duplication and many more lines of code.
When using metaprogramming, it's always a good idea to considerwhether the added complexity is worthwhile.
About
Metaprogramming in service of user experience
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.