scverse / scverse/rustar-aligner
Code organization and style
@flying-sheep is already working on this.
Since Jun 25, 2026.
- Dominant language
- Rust
- Stars
- 75
- Forks
- 7
- Avg merge
- 8m
- Merged PRs (30d)
- 1
Description
Great job @Psy-Fer!
Here’s my review of the code base and what I think we could do:
-
Code reuse prevents drift/partial fixes and improves maintainability: some
ifexpressions have almost the same code on both sides, some blocks are near-verbatim duplicates. We can use loops or helper functions to centralize some of that code. E.g. I added this: https://github.com/scverse/rustar-aligner/blob/199290d83904940a7316be7468b858bc8d39bd48/src/align/transcript.rs#L61-L65 and used it in a little helper I added for a pattern I saw infinalize_transcript: https://github.com/scverse/rustar-aligner/blob/199290d83904940a7316be7468b858bc8d39bd48/src/align/stitch.rs#L1756-L1764 -
Clear use of numeric types prevents overflow bugs like https://github.com/scverse/rustar-aligner/blob/199290d83904940a7316be7468b858bc8d39bd48/docs-old/dev/BUGFIX_2026-02-09.md#L21-L26
We currently use
u32,i32,u64,i64, andusizewith no clear guidence of why we use what where. Would be amazing if we could eventually enable all the clippy lints for unsafe casts after cleaning all that up, e.g. changingif some_i32 > 0 { thing = some_i32 as u32 }tothing = u32::try_from(some_i32)...or so -
Rust has a lot of ways to abstract things (e.g. the extension traits from the first point), and I thing we should use them, e.g. code like this encapsulating a single task should be part of a function or trait instead of just appearing in the business logic: https://github.com/scverse/rustar-aligner/blob/199290d83904940a7316be7468b858bc8d39bd48/src/align/read_align.rs#L353-L366
Maybe using
itertoolscould help in some cases? IDK if e.g. using its hash-baseduniqhere would be more efficient or less than our very ad-hoc lookingsort-then-dedup. -
I personally really like splitting up huge multi-step functions like the above-mentioned
finalize_transcriptinto individual steps that are clear in what they receive and what they emit. Every function that has// 1. do first step: …could instead call another function for this step. custom structs can help holding common context for this.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.