Skip to content
Snippets Groups Projects
Commit b462b848 authored by u214892's avatar u214892
Browse files

#254 review comments by Jeremy

parent 3f5d3844
No related branches found
No related tags found
No related merge requests found
...@@ -108,7 +108,7 @@ Merge Request Guidelines ...@@ -108,7 +108,7 @@ Merge Request Guidelines
Before you submit a merge request, check that it meets these guidelines: Before you submit a merge request, check that it meets these guidelines:
1. The merge request should include tests. 1. The merge request should include tests.
2. The could must be formatted (PyCharm) 2. The code must be formatted (PyCharm)
3. If the merge request adds functionality, the docs should be updated. Put 3. If the merge request adds functionality, the docs should be updated. Put
your new functionality into a function with a docstring, and add the your new functionality into a function with a docstring, and add the
feature to the list in README.rst. feature to the list in README.rst.
...@@ -313,10 +313,8 @@ Caveat: We discourage the usage of Type Aliases for structured data since its me ...@@ -313,10 +313,8 @@ Caveat: We discourage the usage of Type Aliases for structured data since its me
NamedTuple NamedTuple
~~~~~~~~~~ ~~~~~~~~~~
For structured data containers for which we do not write additional methods, we use
For structured data containers for which we do not write methods that have to ensure `NamedTuple` instead of plain `Dict` to ensure better readability by
some (class) invariant over multiple members, we use
`NamedTuple`s instead of plain `Dict`s to ensure better readability by
.. code-block:: python .. code-block:: python
from typing import NamedTuple from typing import NamedTuple
...@@ -330,10 +328,15 @@ some (class) invariant over multiple members, we use ...@@ -330,10 +328,15 @@ some (class) invariant over multiple members, we use
Members of NamedTuple can then be accessed through `.<member>` instead of `['<key>']`. Members of NamedTuple can then be accessed through `.<member>` instead of `['<key>']`.
If we have to ensure some (class) invariant over multiple members
(for instance, `o.A` always changes at the same time as `o.B`),
then we should uses classes instead, see the next section.
Class Attributes Class Attributes
~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~
We use classes for data structures if we need to write methods that ensure (class) invariants over multiple members. We use classes for data structures if we need to write methods that ensure (class) invariants over multiple members,
for instance, `o.A` always changes at the same time as `o.B`.
We use the attrs_ class decorator and a way to declaratively define the attributes on that class: We use the attrs_ class decorator and a way to declaratively define the attributes on that class:
.. code-block:: python .. code-block:: python
...@@ -400,7 +403,8 @@ And then ...@@ -400,7 +403,8 @@ And then
Currying Currying
~~~~~~~~ ~~~~~~~~
We discourage currying to encapsulate state since we often want the stateful object to have multiple methods (but the curried function only has its one and only interface). We discourage currying to encapsulate state since we often want the stateful object to have multiple methods
(but the curried function has only its signature and abusing params to switch behaviour is not very readable).
Thus, we should refactor our generators and use classes instead (see `Issue #283 <https://gitlab.aicrowd.com/flatland/flatland/issues/283>`_). Thus, we should refactor our generators and use classes instead (see `Issue #283 <https://gitlab.aicrowd.com/flatland/flatland/issues/283>`_).
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment