Shotnest

Shotnest · Library

Compare code text without assuming executable equality

Compare two code snippets in the Shotnest text tool and see why if (count > 0) and if (count >= 0) still share 0.778 of their tokens.

What the comparison does to code

The compare tool lowercases both inputs, applies the same character folding Shotnest uses for search (accents removed, full-width letters made half-width), collapses every run of whitespace to one space and then splits on spaces. What it reports is the share of distinct tokens the two texts have in common, plus the tokens found on only one side. Indentation, line breaks and letter case disappear before that step, which is convenient for prose and risky for code.

Nothing is executed. The page treats a pasted snippet as plain text and prints the result without turning it into markup, so the numbers describe characters, not behaviour.

Prepare the two snippets

  1. Paste each snippet exactly as captured, including its braces and operators.
  2. Read the “Exactly equal” line first; it is the only check that keeps case and spacing.
  3. Then read “Equal after normalization” and the overlap value as separate facts.
  4. Open the first-only and second-only token lists; operators and attached punctuation usually show up there.
  5. Go back to the screenshot for anything the token lists cannot show, such as indentation in a language where it matters.

Two snippets, one changed operator

First text: “if (count > 0) { return count; }” written over three lines. Second text: the same statement on one line with >= instead of >. After normalization the line breaks are gone, so the only differing tokens are > and >=. Seven of the nine distinct tokens are shared, giving 7 ÷ 9.

Exactly equal
No
Equal after normalization
No
Token overlap
0.7777777777777778
Only in first
>
Only in second
>=

A second pair shows the opposite risk: “const Total = 1;” and “const total = 1;” are reported as equal after normalization with overlap 1, although many languages treat Total and total as different names.

Mistakes with code text

Where the comparison stops

Token overlap is a text measure. It ignores order, repeated tokens and whitespace, so it cannot tell you whether the code compiles or returns the same value. In the Shotnest app, a screenshot of code goes to the Code shelf when three or more lines start like code (import, def, return and similar); that shelf is for finding it again, and running it is a job for your own environment.

Tools