A second implementation is a promise that two runtimes answer the same question. Most ports break that promise in the first month, quietly, and the damage shows up as two dashboards that disagree. Porting a library is mostly the work of keeping parity, and five rules did that job for me.
Code: ReadSightRS, MIT licensed.
The canonical implementation is PHP. The Rust crate is a byte-accurate port, and the same rules applied to the Python and Node versions.
Rule 1: one implementation owns the answer
The PHP library decides what a formula means. Every other language reproduces it, including the rounding, including the edge case where a text has no sentences.
The temptation is to improve the port: use a better coefficient, fix a rounding that looks wrong. Fix it in the canonical version first, then re-derive the vectors. A port that quietly improves on the original is a fork with a compatibility problem.
Rule 2: vectors are generated, not written
The golden vectors come from the PHP library, not from the port. They cover the supported formula list per language, analyze metrics, every applicable formula with its inputs, and per-word syllable vectors, compared at a tolerance of 1e-9.
Handwritten expectations test what the author believed. Generated vectors test what the original does, which is the only thing the port must match.
Rule 3: approximations are documented at the point of use
Syllable counting by TeX patterns is exact about hyphenation points and approximate about counts. That is a property of the algorithm, not a bug, and it belongs in the readme next to the mode table.
Four Slavic languages use a heuristic counter instead. A user who reads the table knows why дыхание counts as four; a user who does not will file the bug that the maintainer has answered ten times.
Rule 4: speak the language’s idioms, keep the semantics
ReadSight::new() in Rust returns Result, score() returns Result<FormulaResult, Error>, and empty input is Error::EmptyText. Python raises an exception with the same meaning, and JavaScript throws.
Idioms change the shape of the call, never the number that comes back. A port that returns a sentinel zero instead of an error is easier to write and wrong to use in a batch.
Rule 5: the executable documentation counts as a test
The Rust examples in the readme are compiled and run by cargo test. Ninety integration tests cover parity, ported unit tests and a smoke test that builds every language and runs every supported formula.
A readme that compiles cannot drift from the API. A readme that is only prose drifts in the first rename, and the first person to notice is a user pasting a broken example.
What the third port teaches
By the third language the pattern is clear: the shared part is the data and the vectors, and every port is thin around them. Rust embeds the data in the binary, Python caches compiled patterns in a system directory, Node ships it in the package.
That is the useful outcome of the exercise. The interesting work went into one canonical implementation and one set of vectors; the rest is adaptation, and adaptation is cheap when the definition of correct is not negotiable.
Where it ends
Parity is not a feature users see. It is the reason a comparison between two documents survives a rewrite of the pipeline underneath, and it is invisible until the day it is missing.
The crate is MIT, #![forbid(unsafe_code)], and the repository publishes the vectors so a fourth port starts with a definition instead of a guess.
Related: readability library for the canonical PHP library, and readability in node for the port that started this series.