3 ms·
How do tab advocates deal with max column widths? Many projects require that lines not exceed 80 chars, but I'm not sure how'd you establish that kind of limit
by andrewfong 10y ago
How do tab advocates deal with max column widths? Many projects require that lines not exceed 80 chars, but I'm not sure how'd you establish that kind of limit with variable length tabs.
- minitech 10y agoPersonally: by not enforcing maximum widths. Having a fixed limit makes for ugly workarounds and looks horrid if you happen to be viewing at a narrower width. Just wrap code where it makes sense to do so.
- mikegerwitz 10y agoI think that depends partially on the verbosity of the programming language (e.g. type declarations, casting, templating) which eat up a lot of columns, and verbosity of coding style. In the latter case, if your variable names are `name_of_person' rather than simply `name' (which should be obvious by context), you're also going to have problems. The first one might be a legitimate issue. The second issue, I've noticed, I've never had a problem with, even in heavily indented lisp: - If your variable names are too long, they must not be obvious from context, and your function/method/block is doing too much. Refactor. - Consequently, if the line is too long, perhaps it's doing a little too much; short lines with limited logic help with code comprehension the same way short methods do. Splitting code into multiple lines generously allows you to clearly indicate how parts relate to one-another. My line width is 76 characters max to allow for 3 columns for line numbering + one space after it---if line numbering requires more columns that that, maybe your file's too big as well. Some will disagree on that last point, but I consider that in the same light as I do line length and function size. For OOP especially where there's one class per file, it's certainly a code smell if you have a long file.
- girvo 10y agoEditorConfig or various other configuration setups allow your editor/git/whatever to read a tab as if it is "n" spaces, where that is somewhat configurable. Using EditorConfig, this allows consistency across tooling, and solves this problem neatly (at least in this particular use-case, YMMV in other places where this isn't possible or desirable).
- saucetenuto 10y agoSuppose I have a configured tab width of 2 and I write a line with three tabs that's 78 characters wide. When my friend with tab-width 8 views it, he'll see a line that's 90 characters wide. What do projects with 80 character limits do in situations like that? In either case the line contains only 75 characters, of course, but that's a pretty pedantic non-answer: we care about horizontal screen space, not the number of bytes of storage you'd need.
- scrollaway 10y agoEditorConfig tells you the canonical tab size for the project, in other words "a tab counts as 4 characters to the soft wrap". If you choose to increase the tab size beyond 4 characters, you have to accept you'll get longer lines. (It's also high time we stop pretending wrap limits matter to the exact character. In most cases, they are and should be guidelines - we have evolved beyond 640x480 CRTs and 80 character terminals)
- Stratoscope 10y agoThat's a very reasonable question to ask. I suspect that it isn't much of an issue in practice for a few reasons: 1) I'd wager that most projects that have a hard 80-column limit also forbid tabs. 2) If a project does use tabs and has a hard line length limit, it can simply say that that limit is interpreted using a certain tab size (e.g. the most common tab size is probably 4 spaces). 3) In my own code, as I've mentioned probably too many times in this thread :-) I don't use column alignment, which is one of the main causes of excessive line length. Because I use indentation for multiline expressions, my lines of code tend to be a lot shorter than they would be with column-aligned expressions.