Readit News logoReadit News
aithrowawaycomm · a year ago
One minor advantage which wasn’t so relevant in 2008: 80 character lines are much easier to read on a smartphone. This is especially true for Safari on iOS, which always seems to make bad wrapping / sizing decisions with plain text.

ETA: thinking back on it, several years ago I switched from 120 characters to 80 specifically because of this. I don’t have a car, so I read a lot of code on my phone while taking public transit.

taeric · a year ago
Took me a second to realize ETA was "edited to add." I was very confused on what an estimated time of arrival meant, here. :)

I'm surprised reading on a phone is common. Not at all something I would want to do. I'm assuming largely read only there?

Makes me curious if the CWEB idea of styling specifically for reading has extra merit in that flow?

NikolaNovak · a year ago
I've been reading books on phone since palm pilot and 160x160 screen.

I do not want to type / create on my phone though, certainly not code, or even sign up for stuff / submit / do applications on phone. Makes me a rarity though.

benced · a year ago
I've made edits to config files on the GitHub mobile app while on-call. Not something I like doing but I like having the option.
chrisweekly · a year ago
CWEB?
aithrowawaycomm · a year ago
I don’t know how “common” it is, but (like I said in my comment) the only reason I read code on my phone is that I am often on a bus or a subway. The comment about assuming I only read on my phone is bizarre: you are putting words in my mouth for reasons I do not understand. When it comes to books I like paper, and I usually read long PDFs on a tablet.
runjake · a year ago
Someone else is going to be weird and want to look this up so I'll save you the trouble.

Yes, aithrowawaycomm's claim about line lengths are supported by many, many different sources who recommend a 50 to 80 character line length.

https://duckduckgo.com/?q=reading+optimal+line+length

IMHO, 80 characters is too narrow, especially with Python, for most coding tasks so I settle more around 100 (+-20) characters. PEP-8 says up to 99 characters is okay.

https://peps.python.org/pep-0008/#maximum-line-length

o11c · a year ago
It's worth noting that most of those studies are for body text. To make that more directly applicable we should exclude indentation, but the additional punctuation (especially commas, but unfortunately no parentheses) also affects it.

Shading lines can also improve readability (this is known; the rest of this comment is speculation). It's probably not enough to simply alternating between e.g. white and off-white background, unlike for tables. More likely an alternation between 3 or 4 subtly-different colors is best; maybe these can form a pattern across additional lines (e.g. 121312321). If the difference isn't subtle enough, editing will suffer whenever you break the line count, but for reference only the human eye is pretty good at aligning subtle things. Maybe even an outright paper-texture background image? (This is more often a gimmick, but it can be useful.)

throwaway2037 · a year ago

    > especially with Python
What is special about Python in this case?

thayne · a year ago
On the other hand, horizontal scrolling on a touchscreen is more natural than with a mouse.
eviks · a year ago
It's not, with a mouse I can scroll vertically with a Shift to scroll horizontally On a phone touch screen horizontal scrolling is also less ergonomic than vertical due to less range (and less ergonomic than vertical mouse), but I can't replace it
binary132 · a year ago
Just because some people like to have a single pane of text cover their entire 16:9 display doesn’t mean I should have to. I find very vertical text much easier to follow. Wide lines are usually wide due to nesting and chaining, either of blocks or of inline expressions. Both are a thing which should not be.

Concisely and clearly define one concept or abstraction. Then, use it in the next definition. This isn’t hard! And stop with the insanity-inducing compound names. If your name needs 5 subclauses to clarify its intent, your semantics are stupid and you should be beaten with a shoe.

jltsiren · a year ago
And some people like me prefer using large fonts, because my vision is not very good. The code pane in the full-screen VSCode window I have open on a 27" display is 145x37. Full-screen mode would add one more line. And those 145-character lines are typically enough for ~110 characters of code, because the editor adds various annotations.

That gives me an effective working space of 110x37. Any concept that needs longer lines or more lines is going to be harder to follow.

sfpotter · a year ago
It's hard if you don't know how to do it... and lots of people don't know how to do it.
binary132 · a year ago
I mean, spelling the word “CAT” is hard if you don’t know how to do it, but as spelling goes, it’s pretty easy.

It’s true that some people are illiterate and never learned to spell. That doesn’t mean it’s hard, it just means they never learned how.

ryandvm · a year ago
I don't mind an 80 or 100 character limit on code, but it boggles my mind that we're still inserting line breaks in comment blocks. Like, if you can't figure out how to get your editor to line-wrap comments then you're in the wrong business.
acjohnson55 · a year ago
There's still reason to use line breaks, because many editors / viewers will wrap at the viewport width, not earlier, which is not always desirable. Different content "wants" to be different max widths.

For instance, I think prose is hard to read when you have to scan long horizontal distances from line to line.

However, code often has indentation, syntax, and chains (e.g. nested property access) that take up a lot of width before the actual information is presented, so width is more helpful.

binary132 · a year ago
Code is not only used in modern editors. Sometimes it is used in HTML, sometimes it is used in emailed patches, sometimes it is read as plaintext in some other context, it may be read or manipulated over a remote shell session in a terminal that has only rudimentary tools available during a production problem. There are many contexts where source code should be cleanly and clearly formatted and comprehensible without assistance from modern GUIs.
LargoLasskhyfv · a year ago
Here you go, munch on a punch-card.
binary132 · a year ago
Delightful!

You know, there’s a reason cars and trains are the width that they are.

duxup · a year ago
> doesn’t mean I should have to.

I don’t believe the article says you should have to.

binary132 · a year ago
What I mean is that if I’m working on a file with some other people, and I write some 80-column code, they can easily view it in their nice wide panes, but I can’t easily view their wide code in my nice tiled square or vertical panes. I often have as many as 8 (or more!) tiles in a single fullscreen window.
Minor49er · a year ago
Sticking with 80 characters has been great for my team. Not only does it encourage shorter lines, but comparing diffs on GitHub ensures that both old and new comparisons fit evenly on the page without any cutoffs or wrapping
shiroiushi · a year ago
What kind of monitors does your team use?

I view diffs side-by-side all the time with much wider lines than 80 chars, but I have 27" monitors, which are not unusual these days.

throwaway2037 · a year ago
In my experience, people who use wide monitors are more OK to longer lines. The opposite is true for tall/vertical monitor users. The next question: What is the chicken and what is the egg? Do people prefer narrower lines because they prefer tall monitors? Or vice versa?
Minor49er · a year ago
All of my main external displays are 27". The diffs fit perfectly on them with the 80 character limit
koito17 · a year ago
The penultimate paragraph of the article really shows its age.

  When there are unclear or conflicting rules ... [y]ou can end up with hilarious games like formatting tennis ...
Back then, formatters were rarely used, if at all. The major benefit of tools like gofmt, Prettier, etc. is that a major source of vacuous commits and code review has gone away.

In the case of Prettier, bikeshedding can still happen over the .prettierrc file, but it's not hard to make an argument for using the default configuration.

Formatters are something I miss whenever using languages without a widely-used formatting tool. For instance, in Common Lisp, code formatting is "whatever Emacs does when formatting the whole buffer". Depending on the exact package used (e.g. SLIME or SLY), the results of formatting the whole buffer may differ. Contrast this to languages like Go where there is one tool (gofmt) and it exposes no configuration, so there is no possibility of bikeshedding over code formatting.

j1elo · a year ago
In new projects I usually add an empty .prettierrc file with a single comment:

  // Empty file. Use default Prettier settings. No rules here.
To make it clear for other people that it was not just a mistake that the formatter was missing its configuration or that no config file existed at all. Useful to deter from adding new rules because someone is capricious about their own preferences...

koolba · a year ago
I like to put a haikus in spots like this:

    // Empty by choice
    // Use the Prettier defaults
    // No customized rules
Taking the time to write a specific one gives added weight to the decision to use the defaults as anyone adding a rule has to remove the haiku.

vhcr · a year ago
Maybe even add a CI step that closes PRs if someone modifies formatter config files.
AlienRobot · a year ago
I still play tennis with Black. But Black wins every time when I Ctrl+S. I still play tennis anyway because user-facing strings are " not '
steve_taylor · a year ago
Prettier docs recommend a line length of 80 characters because of a fundamental design flaw: Lines are greedy and cramming as much as possible into each line decreases readability as lines increase in size.
tommiegannert · a year ago
Yesterday I was running Prettier on an existing code base, and decided to go with 100. Even at 2-space indentation, 80 caused too many if-expressions to be split up. Google's JS styleguide also says 80. (I also have 450 character lines there, in a table of CSS classes for dark/light/selected/hover/disabled/focused modes. Leaving it long makes it much easier to confirm all modes set the right class.)

However, the benefit of automatic formatters is that if you really like 80 better, you can reformat before editing, and undo that before sharing your results.

delichon · a year ago
I maintain 80 characters in order to edit files side by side on a laptop screen without side scrolling. I seem to grok code better vertically too.
bearjaws · a year ago
I love how everytime this debate comes up, the 80 character gang keeps adding more stuff to put side by side.

Now we're shrinking the resolution/sizes of the devices we are using to justify it...

loloquwowndueo · a year ago
Gotta admit a three-way side by side diff/merge is glorious.
eviks · a year ago
If you soft wrap you can avoid scrolling inn this case for any line length without negatively impacting the case of a single file
funcDropShadow · a year ago
Is there any editor with an intelligent soft-wrap? I.e. it doesn't just wrap at the end the window. Line breaks should be introduced so that the tree structure of the code (think AST) becomes obvious. That improves readability a lot compared to breaking lines at a fixed column.
PeterWhittaker · a year ago
> formatting tennis

That's a paddling.

Seriously, professionals do this? If someone else wrote it and it does what it is supposed to do, it is not, NOT (no apologies for shouty emphasis), my job to change that.

(I hate tabs, but will never :retab someone else's code.)

My job is either/both to fix bugs and add new capabilities, not to be precious about, well, anything.

I would have serious reservations about any team member who wasted all our time on that.

johnisgood · a year ago
I follow the coding conventions used by the project, whether it is tabs, 4 spaces, or other preferences. For my personal projects, I use 2 spaces for indentation and maintain an 80-column width, as it fits nicely in my XTerm windows, making both code and Git commit titles and messages easy to read.
mattnewton · a year ago
I agree this is terrible primarily because it muddles up any git-blame based workflow for debugging regressions. I think an autoformatter with the config checked into git is a nice way around this.
codetrotter · a year ago
> an autoformatter with the config checked into git is a nice way around this.

Yes. At my job we mainly use defaults of rustfmt in most repos. Some repos have rustfmt.toml in them. And the neat thing is that cargo picks up this automatically so there’s no per-repo config you have to do after cloning those repos in order to follow repo-specific formatting rules.

In CI we have a step that runs

  cargo fmt --all --check
And that exits with non-zero code if any formatting is different from what rustfmt wants it to be. Which in turn means that that pipeline stage gets marked as failed.

In order then to get your changes merged, you have to follow the same formatting rules that are already in use. Which in turn is as simple as having

  cargo fmt --all
run at some point before you commit. For example invoked by your editor, or from some kind of git hook or alias, or manually.

It’s nice and easy to set up, and it means that every Rust source file within each individual repo follow the same formatting as the other Rust source files in that same repo.

I don’t particularly care about what specific formatting rules each repo owner chose. (And the vast majority of our repos just use the defaults anyway.) All I care about when I’m working on code is that there is some kind of consistent formatting across the files in the project, and that formatting changes between commits from different people are kept to a minimum so that git log and git blame gives the info that you are interested in. So for me I am very happy that they do it this way at my job.

zamadatix · a year ago
This approach comes with the benefit of automatically fixing those who simply don't realize their editor's settings disagreed with/didn't pick up on the conventions the project follows.
Wowfunhappy · a year ago
> I agree this is terrible primarily because it muddles up any git-blame based workflow for debugging regressions.

...it occurs to me, this feels like you're conforming to the tool instead of the other way around.

Is there a reason git blame doesn't have an "ignore whitespace" option? Is it harder than it seems?

necovek · a year ago
Consistency makes it easier to compare apples to apples and oranges to oranges.

Just like you don't want to allow both underscore_split, camelCase and TitleCase names in a single JSON object (or even different JSON objects returned by the same API), you might want more consistency overall to exactly avoid people's editors rewriting code someone else did (eg. you edit a module and your editor reformats the entire file).

jvanderbot · a year ago
Well I just want to fix the bug or write the feature and move on, but some want other things from their code.
lcnPylGDnU4H9OF · a year ago
Since we’re already on a Holy War About Arbitrary Things topic (and at the risk of igniting the whitespace wars anew), do you mind expanding on this?

> I hate tabs

This opinion seems common but I haven’t seen a practical argument against tabs among practical arguments (for an admittedly niche situation) in favor of tabs. This seems an appropriate place to ask about it.

funcDropShadow · a year ago
I wouldn't say, I hate tabs. But I strongly prefer not using tabs in source code. Let me explain why. There are some languages and coding styles where it doesn't really matter. E.g. when you are always indenting by multiples of some indentation length. But there also languages and coding styles where you want to align stuff.

Consider this example:

    def someFunctionName(Int firstParameter, Boolean secondParameter, String thirdParameter)
Let's say, that line is too long. We could format it like this:

    def someFunctionName(Int firstParameter, Boolean secondParameter, 
        String thirdParameter)
    
Or we could format it like this:

    def someFunctionName(Int firstParameter, Boolean secondParameter, 
                         String thirdParameter)
Or event his

    def someFunctionName(Int firstParameter, 
                         Boolean secondParameter, 
                         String thirdParameter)
In the second two variant the indentation depends on the length of someFunctionName, so it is not necessarily a multiple of four or whatever your tab width is.

There are other similar situation when aligning in multiple columns, etc.

PeterWhittaker · a year ago
I simply find spaces easier to navigate. I don't always use vim-golf-winning movements, and when I am being lazy using hl or arrow keys, I expect to move a space at a time. Tabs violate that expectation.

It's a visceral rather than a rational thing (which I suppose is implied by the word "hate" :->). I also have trailing spaces and all tabs highlighted for similar reasons.

tehjoker · a year ago
tabs are not great in Python because they can hide spaces, and that causes the code to break. in other code? i guess tabs are nicer because people can size them as they like on their devices.
throwaway2037 · a year ago
Your comment is a bit strong, but, in my experience, it is normal to have a couple of average and below devs who only ever comment about formatting in a code review.
lijok · a year ago
Very few professionals do this. Most people writing code are not professionals.
xadren · a year ago
I largely prefer an 80 column limit. On my external monitors with no file tree open, I perhaps could utilise more columns comfortably, but that really falls apart if I need to work on my laptop's screen.

The side effect of this that I don't particularly love is having to split a function's arguments on to multiple lines. Usually if I'm at that point though, I'll probably end up having to split those arguments up event at a ~100 character column limit.

To me, splitting the arguments is the preferable of the two situations. I always want to be able to see the whole line.

bigstrat2003 · a year ago
80 characters is way, way too short. I think 120 is a decent spot for today's displays, although I don't mind even longer than that either.
crazygringo · a year ago
No it's not, it's perfect.

You want to be able to do side-by-side diffs on your laptop using a normal sized (not tiny) font.

You want to be able to paste snippets into design documents and emails and blogs without accidental wrapping or truncating or scrolling.

80 is nicely legible. It works really well.

conductr · a year ago
Actually no I don’t want to be able to work like that on a laptop monitor. I’d rather optimize my full screen real estate. There in lies the conflict.
thayne · a year ago
On my laptop, with a normal font (12-14pt) I can have a side bu side diff of 100 char wide text just fine.
eikenberry · a year ago
IMO 120 is the extreme limit but a good limit. Anything higher than 120 is to long and, personally, I'd ask for that to be fixed in a code review.
malfist · a year ago
120 is way too small. IMO 180 is a good limit. We're not on 800x600 screens anymore
qingcharles · a year ago
I just bought an ultrawide, and I just checked to see how wide my lines are in my code editor. 350 characters.

When I'm coding for myself, I use all of that at times. I love that there are some things I no longer have to break onto multiple lines any longer.

Also, if you have a ton of nested loops etc, then you don't end up with that problem where you can only see the first few characters of the deepest lines.