What guidelines should I follow when given the task of reviewing code, and making…
- User
What guidelines should I follow when given the task of reviewing code, and making necessary optimisations
- Assistant
The guidelines may vary depending on your language, but here are a few general rules:
- Ensure the code works. Not just that it doesn't crash, but that it does what people want. This can be done with tests.
- Make sure the code is self explaining. Someone should be able to tell what it does by reading it over. This also means names should make sense.
- Make sure there is good documentation. There should be docstrings for functions and classes. In many IDEs, these will popup whenever someone hovers over a function, and they will also be used in documentation generators like Sphinx.
- Use linters. These tools will automatically tell you if the formatting is right, if things are too complex, etc.
- Make sure the code isn't too complex. Some linters will measure complexity, but if there are massive functions with many branches, breaking it up into multiple functions that are easier to understand should help with maintenance.
- User
Can you give some examples of good and bad documentation?
- Assistant
Sure, here are some examples of good and bad documentation:
Good documentation:
pythondef add(a, b): """ Adds two numbers together and returns the result. :param a: the first number to add :param b: the second number to add :return: the sum of a and b """ return a + bBad documentation:
pythondef add(a, b): # This function adds two numbers return a + bIn the first example, the docstring provides clear and concise information about the purpose of the function, the parameters it takes, and what it returns. This makes it easy for someone to understand how to use the function without having to read through the code.
In the second example, the comment provides some information about the function, but it is not as clear or as complete as the docstring. It also does not follow a consistent format, which can make it harder to read and understand.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)