With the above example, you have no clue about what the magic number 16 represents. But, with a simple refactoring, extracting the conditional into a well-named variable now conveys all the meaning required to understand what is tested here.

Writing Cleaner Code (with examples)
673
8

Nicklas Millard

Angelo Hulshout ๐Ÿ‡ณ๐Ÿ‡ฑ๐Ÿ‡ฎ๐Ÿ‡น

Angelo Hulshout ๐Ÿ‡ณ๐Ÿ‡ฑ๐Ÿ‡ฎ๐Ÿ‡น

ยท

Follow

May 25, 2021

--

Putting it in a function with the name you assigned to the variable now, and simply return the result of the comparison makes more sense.

--

--

Angelo Hulshout ๐Ÿ‡ณ๐Ÿ‡ฑ๐Ÿ‡ฎ๐Ÿ‡น

Written by Angelo Hulshout ๐Ÿ‡ณ๐Ÿ‡ฑ๐Ÿ‡ฎ๐Ÿ‡น

86 Followers

CEO at Schinchoku and software architect at Delphino Consultancy B.V. โ€” writing about software, and about the Shinchoku startup.

Help

Status

Writers

Blog

Careers

Privacy

Terms

About

Text to speech

Teams