DEV Community

Harry Dennen
Harry Dennen

Posted on • Originally published at Medium on

2

On Readability

None of this is new and I don’t know that it’s possible to follow these 100%. But if these are your targets then your code will be a pleasure to work with.

The Function Does Not Rely on Hidden Cleverness

Language peculiarities around order of interpretation for type coercion are confusing. Yes it’s fun to explore them, but leveraging them in production is effectively setting a landmine for the next developer who touches that code.

Javascript favorite language comic

The Function Makes Sense in Isolation

The reasons why a function was constructed are apparent from the title and contents of the function, without the need for additional context of the caller or any internally called functions.

If a developer needs to read anything other than the function to understand what it’s doing, it’s not readable. The ultimate first prize is to convey precise meaning with the function name alone.

The Function Assumes Knowledge of the Language

Yes the semantics of Promises and methods like .reduce are cumbersome. Yes closure and context take effort to initially get your head around. Yes you still need to be comfortable with all of that.

The one caveat here is to be careful not to fall into leveraging hidden cleverness.

Consistency Trumps Comfort

So much of bug reduction boils down to eliminating surprises. If you join a front end team of ex-backend devs who are all writing functions like this:

function makeThingsHappen()
{
  // things happening
}

or they’re using / not using semicolons, or they’re using spaces / tabs, or [insert your pet peeve here], just bite the bullet and join in. Get some auto-formatting and let go of your petty preferences, they truly do not matter. Your ability to become comfortable in environments that go against your personal preferences is a professional quality — develop it.

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay