How long the line of code can be to remain readable?

Example will be my solution for this step.

I did it like this:

function reverseString(str) {
  return str.split('').reverse().join('');
}

reverseString("hello");

In the above we have 3 methods in one line, I personally consider it’s readable.

What if we have like 8 methods in one line:

string.method1().method2().method3().method4().method5().method6().....

For me it’s a bit much.
Any best practices in terms of “how complex line of code should be”?

A best practice is to use your project’s auto formatting tool.

Everyone and every project has their own rules of thumb. Personally, a line starts to get long for me at 90-120 characters. And if I’m chaining more than 2 methods, I put each call on its own line.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.