CodeFaster

CodeFaster

Share this post

CodeFaster
CodeFaster
Small to big, left to right

Small to big, left to right

Tyler Adams's avatar
Tyler Adams
Sep 06, 2022
∙ Paid
2

Share this post

CodeFaster
CodeFaster
Small to big, left to right
2
Share

Wrong:

foo > 0

Right:

0 < foo

Thanks for reading CodeFaster! Subscribe for free to receive new posts and support my work.

Why? Doesn’t this break the yoda rule? Yes it does, but this one’s better.

Readability

It’s important that code is readable. To humans. Humans are much better at spatial and visual reasoning than abstract reasoning. It’s why this post has a BIG header that says READABILITY. The shape and size give a hint that it’s the BIG idea.

So how can we apply this to something as abstract as value comparison? The number line:

The number line reads small to big, left to right. So, when doing a comparison, we should also have our data go small to big when reading left to right.

Therefore instead of

foo > 0

we will do

0 < foo

That way, we can easily transform code logic to a number line in our minds and see where 0 and foo are spatially relative to each other and therefore mathematically their relation.

Another example is ranges:

Wrong:

foo > 0 && foo < 100

Right:

0 < foo && foo < 100

Thanks for rea…

This post is for paid subscribers

Already a paid subscriber? Sign in
© 2025 Tyler Adams
Privacy ∙ Terms ∙ Collection notice
Start writingGet the app
Substack is the home for great culture

Share