Five Lines, One Little Paper
Most of my students rarely read someone else's code. They write code to build things: animations, games, mathematical models, visualizations. That's intentional. Creation comes first.
But one afternoon I came across this tiny JavaScript function:
function ordinal(n) {
const s = ["th", "st", "nd", "rd"];
const v = n % 100;
return n + (s[(v - 20) % 10] || s[v] || s[0]);
}
I liked it so much that I sent exactly the same message to every family WeChat group and posted it in our Slack:
这五行代码非常有趣,如果能看懂,就能写一篇漂亮的小论文,可以在 Slack 中分享。
("These five lines of code are fascinating. If you can truly understand them, you can write a beautiful little paper. Feel free to share your thoughts in Slack.")
This wasn't a homework assignment.
There was no deadline.
No expected answer.
Just an invitation to slow down.
Instead of asking, "Can you write more code?" I asked, "Can you appreciate someone else's thinking?"
That is a very different question.
Inside these five lines hide surprising ideas:
English grammar (1st, 2nd, 3rd, 11th, 12th, 13th...)
Modular arithmetic (%)
Lookup tables
Array indexing
JavaScript's || fallback mechanism
Elegant algorithm design with almost no branching
It doesn't look profound.
That's exactly why it is.
The best algorithms often disappear into their own simplicity.
Programming isn't only about expressing your own ideas.
It is also about learning to recognize elegance in someone else's.
A programmer matures twice:
the first time when they can build things;
the second time when they can read a few lines of code and see the invisible decisions behind them.
The second skill is much rarer.
A five-line function can contain mathematics, language, and software engineering all at once.
By reading slowly enough to ask not just what the code does, but why each line exists.
Because learning to recognize elegant thinking is one of the milestones from programmer to computer scientist.