{ "cells": [ { "cell_type": "markdown", "id": "commercial-participant", "metadata": {}, "source": [ "# Reviewer Checklist\n", "\n", "- The code must be readable without extra effort from your part. The\n", " code should be easily readable (for infos e.g.\n", " [here](https://treyhunner.com/2017/07/craft-your-python-like-poetry/?__s=jf8h91lx6zhl7vv6o9jo))\n", "- Include references to the used algorithms in the docstring\n", "- If the algorithm is new, please include a description in the\n", " docstring, or be sure to include a reference as soon as you publish\n", " the work\n", "- Variable names should be chosen to be clear. Avoid\n", " ``item, element, var, list, data`` etc... A good variable name makes\n", " it immediately clear what it contains.\n", "- Avoid as much as possible hard-coded indices for list (no\n", " ``x = l[0], y = l[1]``). Rather, use tuple unpacking (see\n", " [here](https://treyhunner.com/2018/03/tuple-unpacking-improves-python-code-readability/)).\n", " Note that tuple unpacking can also be used to update variables. For\n", " example, the Fibonacci sequence next number pair can be written as\n", " ``n1, n2 = n2, n1+n2``.\n", "- Do not use\n", " [mutable](https://www.geeksforgeeks.org/mutable-vs-immutable-objects-in-python/)\n", " (lists, dictionnaries, ...) as [default values for functions and\n", " methods](https://stackoverflow.com/questions/1132941/least-astonishment-and-the-mutable-default-argument).\n", " Do not write: \n", " ``` \n", " def function(default=[]):\n", " ``` \n", " \n", " but use\n", " ``` \t\n", " def function(default=None):\n", " if default is None: default=[]\n", " ``` \n", "\n", "- Use pythonic loops, [list\n", " comprehensions](https://treyhunner.com/2015/12/python-list-comprehensions-now-in-color/)\n", "- Make sure the unit tests are testing all the lines of the code. Do not\n", " only check for working cases, but also the most common wrong use\n", " cases.\n", "- Check the docstrings (Do they follow the [Numpydoc conventions](https://numpydoc.readthedocs.io/en/latest/format.html), is everything clearly explained, are the default\n", " values given and is it clear why they are set to this value)\n", "- Keep the code simple. Avoid using complex Python functionalities whose use\n", " is oppaque to non-expert developers unless necessary. For example, the\n", " ``@staticmethod`` decorator should only be used if really \n", " necessary. Another example, for counting the dictionnary\n", " ``colors = ['red', 'green', 'red', 'blue', 'green', 'red']``,\n", " version:\n", " ``` \t\n", " d = {}\n", " for color in colors:\n", " d[color] = d.get(color, 0) + 1 \n", " ``` \t\n", " is perfectly fine, no need to complicate it to a maybe more pythonic\n", " version\n", " ``` \t\n", " \td = collections.defaultdict(int)\n", " for color in colors:\n", " d[color] += 1\n", " ``` \t\n", "\n", "- Did the code writer perform a static code analysis? Does the code\n", " respect Pep8 (see also the [pylint config file](https://github.com/CLIMADA-project/climada_python/blob/main/.pylintrc/))?\n", "- Did the code writer perform a profiling and checked that there are no\n", " obviously ineficient (computation time-wise and memore-wise) parts in\n", " the code?" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.8" } }, "nbformat": 4, "nbformat_minor": 5 }