Studies on optimal code width?

前端 未结 11 664
滥情空心
滥情空心 2021-01-29 18:42

If you enable the \"View Right Margin\" in your IDE of choice, it is likely that it will default to 80 characters. I tend to change it to 120 for no reason other than it was th

11条回答
  •  悲哀的现实
    2021-01-29 19:04

    I don't have studies, but I will relate my experience.

    I find that horizontal scrolling is tedious when dealing with text. I look at the environment that the code will be used in, and set width standards based on that context.

    For example, when I worked in Emacs on XWindows, it worked well to have 2 Emacs windows side-by-side at all times. That limited them to 80 characters, so that was my max line length.

    At one point I worked in Visual Studio on a 1920x1200 screen. I'd keep it maximized, with all tool windows docked down one side. There was enough space left for two editor windows side-by-side at around 100 characters.

    I also find that the longest lines come from method calls with long parameter lists. This is sometimes a code smell: perhaps the method should be refactored.

    If you & your co-programmers have high-resolution screens and sharp eyesight, by all means use a small font and long lines. Conversely, you may need short lines.

提交回复
热议问题