DEV Community

Discussion on: Maximum line length in your code

Collapse
 
mcccclean profile image
Tom McLean

I stick to 80 and I'm a bit of a stickler about it - I use a lot of panes when editing, so I'll have multiple files sitting side by side; even on a widescreen monitor, sticking to 80 means I can have 3 panes across instead of just 1 or 2.

With the example you used, you can rewrite to fit in 80 chars comfortably just by ditching fat arrow syntax (which is also a handy way of announcing "this is a pure function" to your teammates).

export function setCommunity(id: string): SetCommunityAction {
    return {
        type: '@@community/SET_COMMUNITY',
        payload: { id }
    }
}

...assuming ActionCreator<X> just means "a function that returns an x"; I don't know the context of the code. In any case, my point is that the response to a line-length code smell shouldn't just be to see if you can put your line breaks in different places; it's to see if there's a better way to write that line that expresses your idea more clearly.