stdlib-js / stdlib-js/stdlib

[RFC]: Improve doctests for complex number instances in documentation examples (tracking issue)

Abierto
#8,641 11 comentarios 0 reacciones 0 asignados Ver en GitHub
Accepted difficulty: 1 Documentation Good First Issue JavaScript Modernization RFC Tracking Issue
Lenguaje dominante
JavaScript
Estrellas
6k
Forks
1.3k
Merge medio
1 d 3 h
PR fusionados (30 d)
611

Descripción

### Instructions

1. Read the issue description below.
2. Read the issue comment which follows the description.
3. Search the code base for a package having a JSDoc example which needs updating according to the description below.
4. Follow any additional guidance specified in this issue.

### Description

This RFC proposes improving [doctests](https://github.com/stdlib-js/stdlib/blob/develop/docs/doctest.md) for complex number instances in documentation examples. This is best conveyed through an example.

Consider the following JSDoc example in [`blas/ext/base/cfill`](https://github.com/stdlib-js/stdlib/blob/f223373e1c5b86f2ba763cb92472b03096485604/lib/node_modules/%40stdlib/blas/ext/base/cfill/lib/cfill.js):

```javascript
/**
* ...
*
* @example
* var Float32Array = require( '@stdlib/array/float32' );
* var Complex64Array = require( '@stdlib/array/complex64' );
* var Complex64 = require( '@stdlib/complex/float32/ctor' );
* var realf = require( '@stdlib/complex/float32/real' );
* var imagf = require( '@stdlib/complex/float32/imag' );
*
* var arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
* var x = new Complex64Array( arr );
*
* var alpha = new Complex64( 10.0, 10.0 );
*
* cfill( x.length, alpha, x, 1 );
*
* var y = x.get( 0 );
* // returns
*
* var re = realf( y );
* // returns 10.0
*
* var im = imagf( y );
* // returns 10.0
*/
```

Compare to the example after updating in commit https://github.com/stdlib-js/stdlib/commit/e8c8651693bc38d999b5f46cf31ccd370ad6cb8c

```javascript
/**
* ...
*
*
* @example
* var Float32Array = require( '@stdlib/array/float32' );
* var Complex64Array = require( '@stdlib/array/complex64' );
* var Complex64 = require( '@stdlib/complex/float32/ctor' );
*
* var arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
* var x = new Complex64Array( arr );
*
* var alpha = new Complex64( 10.0, 10.0 );
*
* cfill( x.length, alpha, x, 1 );
*
* var y = x.get( 0 );
* // returns [ 10.0, 10.0 ]
*/
```

Notice how, in the updated example, we use the [doctest](https://github.com/stdlib-js/stdlib/blob/develop/docs/doctest.md) return annotation `// returns [ 10.0, 10.0 ]`. In contrast, in the old example, we decomposed an element into real and imaginary components.

As may be observed, the updated doctest is much more compact and conveys more clearly the expected behavior.

Accordingly, this RFC seeks to leverage recent improvements in our [doctest](https://github.com/stdlib-js/stdlib/blob/develop/docs/doctest.md) framework which now supports complex number instance notation for complex number instances (e.g., `[ 1.0, 2.0 ]`), where previously it did not; hence, the more verbose decomposition logic used in the first example.

If you compare the two example code blocks above, notice the removal of `realf` and `imagf` imports and element decomposition and updating the returns annotation to `// returns [ 10.0, 10.0 ]`.

### Steps

Given the relatively widespread practice of decomposing complex instances into individual components, this RFC aims to be an open call for any contributor wanting to contribute to the project to do the following:

0. Study the changes made in commit https://github.com/stdlib-js/stdlib/commit/e8c8651693bc38d999b5f46cf31ccd370ad6cb8c, as this commit contains the sorts of changes that we are looking for.
1. Find a package containing documentation examples which performs element decomposition into real and imaginary components in order to show expected values. A possible global project search could use the regular expression `\* var [a-zA-Z0-9]* = (?:real|imag)(?:f|)\(`. From the search results, you should be able to find a package in need of updating.
2. Update the examples for that package, and **only that package**, to migrate to using complex number instance notation (e.g., `[ ... ]`, `[ ... ]`, etc). Examples may be found in the following package files (note: not all files may require updating; you should inspect each file individually):
- `README.md`
- `docs/index.d.ts`
- `docs/repl.txt`
- `examples/index.js`
- `lib/*` JSDoc examples
4. Submit a PR updating the documentation for that package (and only that package).
5. For the PR title, use the following template "docs: improve doctests for complex number instances in ``", where `` is the name of the package you updated (e.g., `blas/ext/base/cfill`).

**Please do NOT make extraneous changes to examples. We are not interested in changing examples wholesale. We are only interested in replacing decomposition logic with complex number instance notation.**

### Related Issues

None.

### Questions

No.

### Other

- If you are interested in working on this RFC, for each pull request, **please only update the examples for a single package**.
- As mentioned above, **please do NOT make extraneous changes to examples. We are not interested in changing examples wholesale. Nor are we interested in new "creative" changes. We are only interested in replacing decomposition logic with complex number instance notation.** Failure to match the behavior of the existing examples and to respect this guidance will result in your PRs being automatically closed without review.
- As this is a "Good First Issue", you are **strongly encouraged** to **avoid** using AI when authoring your contribution. One of the primary intents of Good First Issues is to help introduce you to stdlib, its development environment, and the contribution process, as documented in the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md). Most new contributors are unfamiliar with stdlib and its conventions, and thus fail to appropriately use LLMs and AI when authoring contributions, most often generating AI slop and leading to wasted time. Don't be one of those people. :) Take the time to manually author your first several PRs, and, once you are intimately familiar with project conventions, you can consider leveraging AI to augment your dev tasks.

### Checklist

- [x] I have read and understood the [Code of Conduct](https://github.com/stdlib-js/stdlib/blob/develop/CODE_OF_CONDUCT.md).
- [x] Searched for existing issues and pull requests.
- [x] The issue name begins with `RFC:`.

Guía de contribución

Abrir la guía de contribución

Línea de trabajo

Study commit e8c8651693bc38d999b5f46cf31ccd370ad6cb8c and search for decomposition patterns matching the supplied regular expression. Inspect the named README.md, docs/index.d.ts, docs/repl.txt, examples/index.js, and lib/* files for one package. Replace only real/imag decomposition in that package with complex instance return annotations, preserving existing behavior and examples.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
javascript
Área
documentation
Tipo de issue
Documentación
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
45/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.