action #162698
closedEnhance/Improve OpenQA perldoc
0%
Description
Observation¶
The idea is to make the documentation in OpenQA more explanatory and helpful.
Example of not very useful description¶
There are many example but I will point you to create_artefact function.
=item create_artefact()
Used by the worker to upload files to the test.
=back
=cut
Without read the code is hard to understand what it does or answer questions like:
- Can you tell what is the input and what the expected output?
Example of missing documentation¶
OpenQA::WebAPI::Controller::API::V1::JobSettings::jobs
Example of a better description¶
I consider get_parents a good example
Enhance/Improve OpenQA perldoc
This was an idea raised by @ybonatakis.
Acceptance criteria¶
- AC1: functions under lib/OpenQA provides a short description
- AC2: At least expected inputs/outputs are documented.
Suggestions¶
- I don't want to write pod.
- extract and refactor if function is too big and while writing a documentation you find mismatch between the name what the function
- Do we publish html of the pods?
- Opportunity to play with AI stuff?
Updated by ybonatakis 6 months ago ยท Edited
- Description updated (diff)
- Priority changed from Normal to Low
Updated by okurz 6 months ago
@ybonatakis thanks for the details. Can you state what you see as ACs?
Updated by ybonatakis 5 months ago
- Description updated (diff)
An example I generate with chatGPT might be a better example. I used _needle_by_id_and_extension
The result was
=head2 _needle_by_id_and_extension
$self->_needle_by_id_and_extension($extension);
Fetches a needle by its ID and serves a static file with the specified extension.
=over 4
=item *
$self: The object instance (usually a controller object).
=item *
$extension: The file extension to append to the needle's name when constructing the filename.
=back
This method performs the following steps:
=over 4
=item 1.
Checks if the 'needle_id' parameter is present in the request. If not, it returns a 404 Not Found response.
=item 2.
Looks up the needle in the database using the 'needle_id' parameter. If the needle is not found, it returns a 404 Not Found response.
=item 3.
Retrieves the directory path associated with the needle.
=item 4.
Constructs the filename by concatenating the needle's name with the provided extension.
=item 5.
Adds the needle's directory path to the list of static paths.
=item 6.
Serves the static file with the constructed filename.
=back
Returns the result of serving the static file.
=cut
sub _needle_by_id_and_extension ($self, $extension) {
return $self->reply->not_found unless my $needle_id = $self->param('needle_id');
return $self->reply->not_found unless my $needle = $self->schema->resultset('Needles')->find($needle_id);
my $needle_dir = $needle->directory->path;
my $needle_filename = $needle->name . $extension;
push @{$self->static->paths}, $needle_dir;
return $self->_serve_static($needle_filename);
}
Updated by okurz 5 months ago
You gave a really good example of how documentation should not be done:
- _needle_by_id_and_extension is a private method so one should not put it into the outwards facing documentation
- Cleaner code is better than documented but bad code. If you can't understand the code then consider improving the code, not document it
- The lengthy list of description "what" the code is doing I also consider bad because it's too verbose and as soon as somebody changes the implementation the comments will be wrong because we all know from experience that comments are not updated when code is updated unless the comments are really near to the code.
Also I recommend to read https://www.codeproject.com/Articles/872073/Code-Comments-are-Lies and https://lassiautio.com/2019/03/19/comments-lie/ and https://medium.com/@bpnorlander/stop-writing-code-comments-28fef5272752
Given that if you do find cases where the documentation can be improved then feel welcome to open pull requests or mention how we could measure an improvement so that we can refine the ticket to become workable.