Until now I've always tried to stick to 80 characters per line and it worked just fine in plain ol' JavaScript, however after adopting TypeScript it feels like it's not enough with all these type declarations, sometimes code becomes harder to read, an example:
export const setCommunity: ActionCreator<SetCommunityAction> = (
id: string
) => ({
type: '@@community/SET_COMMUNITY',
payload: {
id
}
});
Whereas if limit would be 100, this becomes more readable:
export const setCommunity: ActionCreator<SetCommunityAction> = (id: string) => ({
type: '@@community/SET_COMMUNITY',
payload: {
id
}
});
Of course this is a single example that was frustrating me.
What max line length do you use and what are the reasons behind it?
Oldest comments (51)
Why stick to an arbitrary max length at all?
Make lines as long as is natural for the code without having to horizontally scroll.
This usually comes from tools like GitHub or VSTS. These will enforce horizontal code scrolling on code comparison if lines are longer than
{x}characters.I like max lengths because I usually work in an IDE with other devs. A shared max length means we can all format our code on save, and it doesn't mess each other up
In my case it comes in handy when I have 2 files opened side-by-side. I switched to 120 from 80 and it works pretty well for me.
Now that's the principle.
I think there shouldn't be any definite edged-in-stone approach to maxlengths.
In my case, I simply turn on the text wrap in whatever IDE, and it fits what's right in the viewport.
120
Mainly I am doing Java and a little HTML and CSS.
Just use the horizontal space provided by modern widescreens of huge size :-)
We had a discussion and settled on 100.
We all use the same size main monitors and same IDE with a standardized settings file. To get max line length we took the number of characters that can fit on a line without horizontal scrolling and took a bit off for indentation.
I go with 100, but still try to fit comments into 80 because I find those are more difficult to read when they break the line or scroll.
120 that's what we use in our company, and I think it fits most of the modern screen sizes
I wouldn't say that I'm sticking to it religiously, just really wanted to know whether that was bugging just me or not and what others in community are using.
I get my favourite readability with 80 :)
80
It's a nice way to have a constraint in your code not to go deep in callbacks or nested statements, not only long variable or method names. These days with wide screen monitors my preference is to have 120 as a soft limit, nicely fits my code and surrounding tools from IDE in one screen. Also fits in GitHub pull request side by side view. It's all about readability, as long as it is not hardly enforced without a valid reason.
We find than 120 is the most readable while still short enough for all the ways our code is displayed (screen, diffs, Bitbucket, etc.).
80 chars gets hard to read when you have longer, more descriptive names like we use in our code.