Idea

Porting a formula to another language requires rereading the operator precedence of the original language

Info

Originally written in French. Translated by AI — the meaning has been preserved, not the prose.

Main idea

A formula written in one language cannot be copied as is into another: operator precedence differs. In Turbo Pascal, and has the same precedence as *, higher than +. The expression X*X and y*y therefore reads as $((X \cdot X) \And y) \cdot y$, not $(X^2) \And (y^2)$ as a C or JavaScript programmer would read it.

Porting the formulas of a Pascal program to JavaScript requires rereading each expression according to the rules of the original language, and rewriting it with explicit parentheses.

Why it matters

The error is silent: the misread formula compiles, runs and produces a plausible image, just a different one. Only knowing the source language's precedence rules lets you spot it.

Nuances and limits

The risk is low between languages of the same family; it peaks with logical operators, whose precedence varies the most from one language to another.

Open questions

  • What other silent differences between Pascal and JavaScript — integer division, rounding, type conversion — should a port review cover?