PistonDevelopers / PistonDevelopers/piston

Removing/renaming type aliases to improve readability of documentation

Open
#1,248 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

discussion
Dominant language
Rust
Stars
4.7k
Forks
235
Avg merge
1m
Merged PRs (30d)
4

Description

Sometimes reading the piston documentation is a bit of an uphill battle, just today this happened:

I needed to see the types I needed to put into a square to make a wrapper function, so I see that graphics::rectangle::square has the signature square(x: Scalar, y: Scalar, size: Scalar) -> Rectangle.

First thought? "What on earth is a Scalar?" ... It's just an f64. Why not just write that?

Arguably "Scalar" is a less helpful type name to the programmer at first glance than the familiar "f64", especially since nothing special is done to the type.

But fair enough.

I then notice that the returned Rectangle is not a rectangle::Rectangle at all, but a types::Rectangle, which is an alias for a [f64; 4]... Why does it have the same name as an entirely different type? That's incredibly unhelpful.

Simply making the function signature square(x: f64, y: f64, size: f64) -> [f64; 4] tells me loads more about what the function is, than hiding it all behind several layers of indirection; heck (🐍), calling [f64; 4] "Rect" would've been more helpful to give a visual distinction from the other "Rectangle" type within the library.

I don't know, it's these small things that sometimes makes me pull my hair out when trying to use a library.

I feel that removing unnecessary type aliases would dramatically increase the readability of the docs, at least for things like primitive numeric types.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the definitions and usages of the Scalar and Rectangle aliases referenced by graphics::rectangle::square and types::Rectangle. Review how those aliases appear in the generated documentation, then determine which aliases should be removed or renamed and update their signatures consistently; done means the documented types are unambiguous.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
documentation
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.