-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stdlib Development Guidelines #16
Comments
Bei der Beschreibung für "Prefer named functions over overloaded operators" wird für |
@lars-reimann Turn this into a documentation page. |
Closes #16. ### Summary of Changes Add development guidelines to documentation. The original issue is no longer needed.
🎉 This issue has been resolved in version 0.3.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
This document describes general guidelines for our user-friendly data science API. In the DO/DON'T examples below we either show client code to describe the code users should/shouldn't have to write, or library code to describe the code we, as library developers, need to write to achieve readable client code. We'll continuously update this document as we find new categories of usability issues.
Prefer named functions over overloaded operators
The names can better convey the intention of the programmer and enable better auto-completion.
✔️ DO (client code):
❌ DON'T (client code):
Related issues:
Prefer methods over global functions
This aids discoverability and again enables better auto-completion. It also supports polymorphism.
✔️ DO (client code):
❌ DON'T (client code):
Prefer separate functions over functions with a flag parameter
Some flag parameters drastically alter the semantics of a function. This can lead to confusion, and, if the parameter is optional, to errors if the default value is kept unknowingly. In such cases having two separate functions is preferable.
✔️ DO (client code):
❌ DON'T (client code):
Related issues:
Avoid uncommon abbreviations
Write full words rather than abbreviations. The increased verbosity is offset by better readability, better functioning auto-completion, and a reduced need to consult the documentation when writing code. Common abbreviations like CSV or HTML are fine though, since they rarely require explanation.
✔️ DO (client code):
❌ DON'T (client code):
Related issues:
Specify types of parameters and results
Use type hints to describe the types of parameters and results of functions. This enables static type checking of client code.
✔️ DO (library code):
❌ DON'T (library code):
Use narrow data types
Use data types that can accurately model the legal values of a declaration. This improves static detection of wrong client code.
✔️ DO (client code):
❌ DON'T (client code):
Related issues:
Check preconditions of functions and fail early
Not all preconditions of functions can be described with type hints but must instead be checked at runtime. This should be done as early as possible, usually right at the top of the body of a function. If the preconditions fail, execution of the function should halt and either a sensible value be returned (if possible) or an exception with a descriptive message be raised.
✔️ DO (library code):
❌ DON'T (library code):
Raise either Python exceptions or custom exceptions
The user should not have to deal with exceptions that are defined in the wrapper libraries. So, any exceptions that may be raised when a third-party function is called should be caught and a core Python exception or a custom exception should be raised instead. The exception to this rule is when we call a callable created by the user: In this case, we just pass any exceptions thrown by this callable along.
✔️ DO (library code):
❌ DON'T (library code):
Group API elements by task
Packages should correspond to a specific task like classification or imputation. This eases discovery and makes it easy to switch between different solutions for the same task.
✔️ DO (client code):
❌ DON'T (client code):
Group values that are used together into an object
Passing values that are commonly used together around separately is tedious, verbose, and error prone.
✔️ DO (client code):
❌ DON'T (client code):
Related issues:
Test non-trivial functions
If a function contains more code than just the getting or setting of a value, automated test should be added to the
tests
folder. The file structure in the tests folder should mirror the file structure of the implementation of the package.Document API elements
All classes should have
All functions should have
The documentation should follow the numpydoc format.
Prefer a usable API over simple implementation
It's more important to provide a user-friendly API to many people than to save some of our time when implementing the functionality.
The text was updated successfully, but these errors were encountered: