Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Metaprogramming in service of user experience

License

NotificationsYou must be signed in to change notification settings

fluentpython/abacus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

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

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp