News for hackers. Stuff that matters.
Re:Software Engineering at Google (2020) [pdf] by google234123 on Wednesday May 04, 2022 @01:48AM (#31257129)
Is the first chapter explaining why all lines must be less than 80 characters in width and all parameters and conditional statements must be automatically formatted in the most compact way possible - damn readability.
Re:Software Engineering at Google (2020) [pdf] by iliketrains on Wednesday May 04, 2022 @02:16AM (#31257283)
Having worked at Google for many years, 80 char line limit was easily the biggest frustration with coding. Because of that, I was forced to write less readable code, shorten variable and function names, omit some comments, fight with formatter and linter, spend extra time aligning things, etc.

For example, Python requires extra effort to brake lines, often adding extra parentheses or doing other unnecessary tricks. Lambda does not fit on the rest of the line? Too bad, define an extra function, because liner won't let you submit a lambda that spans more than one line...

Now, I am so happy with 120 char limit while still being able to fit two columns on one screen.

Re:Software Engineering at Google (2020) [pdf] by bjackman on Wednesday May 04, 2022 @04:42AM (#31258110)
FWIW, a counterpoint: I work in C++ (80) and Go (no line length limit) at Google and I barely even think about it. I just write code however feels natural and then run 'hg fix' before sending for review.

I would definitely not impose 80 if it were my choice but it really doesn't bother me when clang-format is set up as nicely as it is.

Probably Python should switch to the Go model, since auto-splitting python lines sounds tricky.

Re:Software Engineering at Google (2020) [pdf] by bpicolo on Wednesday May 04, 2022 @06:35AM (#31258648)
Black’s model for Python is great. It has a default limit of 88 but will go over that up to 10% if the formatting makes more sense that way.
Re:Software Engineering at Google (2020) [pdf] by eadmund on Wednesday May 04, 2022 @08:26AM (#31259490)
> Python requires extra effort to brake lines, often adding extra parentheses or doing other unnecessary tricks.

There are much more compact languages than Python.

> Now, I am so happy with 120 char limit while still being able to fit two columns on one screen.

The standard width of a terminal is 80 characters; if you are writing 120-character-wide code then your lines will read very poorly on a terminal, or a window sized to a terminal.

Note too that to be readable text should not be too wide, which is why newspaper columns are narrower, and why websites normally try to have a fairly narrow text box. It turns out that 80 characters wide is a pretty good readability standard.

Re:Software Engineering at Google (2020) [pdf] by sly010 on Wednesday May 04, 2022 @09:09AM (#31259870)
You are repeating an argument you read somewhere, not actually something you believe. No-one sizes their terminals to 80chars. Heck, I don't even remember the last time I came across one, maybe other than some BIOS over RS232 (i.e. NOT coding). For the 0% of you who code on a dot matrix printer, please enable line wrapping in your editor and let the rest of the world move on.

I am not saying lines should be arbitrary long, but a 100-120 _soft_ limit would really not hurt anyone and would help code readability a LOT.

p.s. even dot matrix printers support a 100 character mode.

EDIT: long lines only reduce readability for prose. Code is inherently easier to parse for the eye because it has a shape. Unless of course if you f--k up that shape with arbitrary line breaks.

Re:Software Engineering at Google (2020) [pdf] by eadmund on Wednesday May 04, 2022 @09:30AM (#31260103)
> You are repeating an argument you read somewhere, not actually something you believe.

I think I am a better judge of my beliefs than you are.

> No-one sizes their terminals to 80chars.

Mine open at 24×80, although to be honest I normally tile them instead. And I much prefer code formatted to be 80 chars wide, with functions that fit within a page or two of text.

Re:Software Engineering at Google (2020) [pdf] by sly010 on Wednesday May 04, 2022 @10:06AM (#31260618)
> And I much prefer code formatted to be 80 chars wide, with functions that fit within a page or two of text.

Wouldn't you agree that largely depends on the code in question? Of course I also "prefer" shorter lines in general, but that relationship is somewhat linear: 81 is not infinitely worse than 80. If the function in question would be more readable with just 1-2 lines that happens to be 83 chars, wouldn't you opt for that over placing some arbitrary closing bracket on the next line? Whether a code is more readable (for a human) should really not be decided by an arbitrary technical limit from 50 years ago. We have code reviews for that.

btw, as far as I know the linux kernel has a _recommended_ 100 char maximum now.

Re:Software Engineering at Google (2020) [pdf] by skirmish on Wednesday May 04, 2022 @01:27PM (#31263399)
And then you get Go readability reviewers enforcing a single letter (!) variable names so that everything fits in 80 columns. Do you prefer that?
Re:Software Engineering at Google (2020) [pdf] by foota on Wednesday May 04, 2022 @02:19AM (#31257297)
Line splitting in python is miserable, all the other languages are much easier for it.
Re:Software Engineering at Google (2020) [pdf] by bob1029 on Wednesday May 04, 2022 @05:17AM (#31258281)
What is with these draconian rules of having any limit at all? There are tons of edge cases where allowing a 100k line of text would totally make sense to most developers.

Are the tools at Google and elsewhere unable to diff code if a line exceeds some arbitrary width?

Re:Software Engineering at Google (2020) [pdf] by compiler-guy on Wednesday May 04, 2022 @07:05AM (#31258863)
The tools at Google are perfectly capable of diffing lines of arbitrary width.

Those in charge of the C++ style guide choose not to allow them without strong justification. In practice, you just convince your reviewer and move on. Most reviewers are reasonable, but edge cases a where it is needed are rare.

I don’t especially like it, but in terms of annoying style issues, it is very far down the list, especially when the tooling handles it all for you via auto formatting and whatnot.

Re:Software Engineering at Google (2020) [pdf] by saalweachter on Wednesday May 04, 2022 @06:16AM (#31258557)
You can commit lines > 80 characters in all languages.

You just have to convince your reviewer it makes sense in that particular case. The more obvious it is, the easier it will be.

Re:Software Engineering at Google (2020) [pdf] by nextlevelwizard on Wednesday May 04, 2022 @05:35AM (#31258365)
>There are tons of edge cases where allowing a 100k line of text would totally make sense

Can you give one?

Re:Software Engineering at Google (2020) [pdf] by bob1029 on Wednesday May 04, 2022 @05:38AM (#31258381)
Sure. Unit test where you have hundreds of signature specimens which need to be evaluated against graphics processing code. Maintaining a separate list of binary files for each resource was a mess for us. Inline base64 string in each unit test method containing the exact specimen was way more convenient. These lines are long but cause no trouble for IDE responsiveness or our github tooling.
Re:Software Engineering at Google (2020) [pdf] by the-lazy-guy on Wednesday May 04, 2022 @05:49AM (#31258427)
I think maintaining a directory of binary files and using it at runtime is a lot better in the long run. Either through a separate build step which embeds them into the test binary. Or via proper env setup where tests actually know how to find the data in the file system.

At the very least you can inspect your test data easily without having to extract it from base64-encoded strings.

Current approach may be working for your team, but I can totally see why a company which has a dedicated team working on build and testing infra, prefers a slightly more complex approach. It requires one-off investment in tooling which can be payed off very soon given enough people using it.

Re:Software Engineering at Google (2020) [pdf] by nextlevelwizard on Wednesday May 04, 2022 @01:44PM (#31263587)
Why does it need to be in the same test file at all? That sounds like a test resource that should be in some kind of test material/resources folder where it can be read from.

Of course you can embed binary files as base64, but have you thought if you should

Re:Software Engineering at Google (2020) [pdf] by Tepix on Wednesday May 04, 2022 @05:37AM (#31258376)
An art project!
Re:Software Engineering at Google (2020) [pdf] by nextlevelwizard on Wednesday May 04, 2022 @01:45PM (#31263594)
Yeah if you embed a random 100000 character art project as one liner in your code you have bigger problems than 100000 character line in your code.
Re:Software Engineering at Google (2020) [pdf] by BeetleB on Wednesday May 04, 2022 @01:02PM (#31263086)
I dunno - I strive for 80 characters and do Python development these days, and it isn't hard at all - with good editor support. Adding an extra parenthesis shouldn't hurt that much. I choose reasonable variable names, and almost never shorten them to get a line to fit in 80 characters.

We don't have an 80 character rule, but none of the other developers has come to me saying my code is hard to read.

The lambda problem is a language problem. If Python allowed multi-statement lambdas, you wouldn't have this frustration. When I used to do C++, most of my lambdas were multi-line - my coworkers found it easier to read.

Re:Software Engineering at Google (2020) [pdf] by nanoservices on Wednesday May 04, 2022 @10:01AM (#31260546)
> Having worked at Google for many years

Perfect person to ask this. What is behind the need to constantly abandon products/services in favor of new offerings that have a fraction of the functionality?

Re:Software Engineering at Google (2020) [pdf] by Jensson on Wednesday May 04, 2022 @10:20AM (#31260815)
Because Google earns more money by making those engineers optimize ads rather than maintaining systems with a fraction of the ROI.

The upper leaders even talked about that. How Google was looking for "the next big thing", and every time it turned out to just be be more ads since nothing else they tried even came close to being as profitable.

Re:Software Engineering at Google (2020) [pdf] by maskedinvader on Wednesday May 04, 2022 @02:02AM (#31257197)
do we really have to limit 80 chars now? don't we all have bigger monitors and wider screens to accommodate 120 perhaps?
Re:Software Engineering at Google (2020) [pdf] by omegalulw on Wednesday May 04, 2022 @02:18AM (#31257291)
Other than the reasons already posted, I find it much easier to read code with 80 char line limits vs longer. For me it's like the benefit of reading an article in columnar format - going down vertically just feels more comfortable.
Re:Software Engineering at Google (2020) [pdf] by helge9210 on Wednesday May 04, 2022 @02:05AM (#31257212)
With 80 chars you could fit three windows with code side by side on standard screen or four on ultra wide.
Re:Software Engineering at Google (2020) [pdf] by nicogg88 on Wednesday May 04, 2022 @06:09AM (#31258514)
When you take into account IDE stuff like file tree on the left, plugins on the right, or the split view when looking at a file diff, more than 80 char is too much even on a large monitor in my opinion.
Re:Software Engineering at Google (2020) [pdf] by corford on Wednesday May 04, 2022 @05:17AM (#31258277)
Even Linus seems comfortable with 100 these days: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/lin...

On my team we've settled for either 100 or 120 depending on language.

Re:Software Engineering at Google (2020) [pdf] by BeetleB on Wednesday May 04, 2022 @01:04PM (#31263109)
I almost always have multiple files open side by side. Lines longer than 100 characters start wrapping which really hurts readability.
Re:Software Engineering at Google (2020) [pdf] by LudwigNagasena on Wednesday May 04, 2022 @02:06AM (#31257219)
Don’t we all have IDEs that enumerate lines and allow wrapping?
Re:Software Engineering at Google (2020) [pdf] by okamiueru on Wednesday May 04, 2022 @02:50AM (#31257483)
Not sure what you mean. Soft wrapping?
Re:Software Engineering at Google (2020) [pdf] by dmitriid on Wednesday May 04, 2022 @02:04AM (#31257208)
On a wider screen you will probably have several code windows/panes side by side. So, back to 80 characters :)
Re:Software Engineering at Google (2020) [pdf] by nickjj on Wednesday May 04, 2022 @08:08AM (#31259354)
Yep.

If you run 2560x1440 at its native resolution you can fit (4) side by side code windows at 80 characters with a very readable font size. Having 120 character lines only lets you have 2 (3 will cut off the last one by a decent amount).

Being able to comfortably open 4 files side by side is like having access to a completely new world compared to 2. You can often fit the entire context of what you're working on in one visible space.

I use 80 characters for mainly this reason and it's also no extra time spent when using languages like Python because Black will auto-format it for you, it comes down to running 1 command and letting the machine do all of the work.

Re:Software Engineering at Google (2020) [pdf] by ignoramous on Wednesday May 04, 2022 @02:19AM (#31257296)
While it might be true that 120 chars are ideal for screens [0], the consensus is an optimal line length is roughly 50 to 75 chars. [1]

[0] https://www.viget.com/articles/the-line-length-misconception...

[1] http://webtypography.net/2.1.2

Re:Software Engineering at Google (2020) [pdf] by kitsune_ on Wednesday May 04, 2022 @03:11AM (#31257628)
Yeah but line formatting usually includes white space indentation in the calculation of the line length, I don't know whether you can 1:1 translate findings from normal text paragraphs like that. With linted code the actual relevant length might only be 20 characters, maybe we need some smarter linters.
Re:Software Engineering at Google (2020) [pdf] by kozd on Wednesday May 04, 2022 @02:22AM (#31257323)
That seems to apply for blocks of text. I don't know that the same would hold true for code.
Re:Software Engineering at Google (2020) [pdf] by shakezula on Wednesday May 04, 2022 @02:34AM (#31257407)
What is code if not blocks of text
Re:Software Engineering at Google (2020) [pdf] by YokoZar on Wednesday May 04, 2022 @06:50AM (#31258752)
Sentences feel different from lines of code. "One statement doing one thing per line of code" seems a reasonable idea but "one sentence per line of text" seems a bit absurd.
Re:Software Engineering at Google (2020) [pdf] by tpush on Wednesday May 04, 2022 @02:46AM (#31257467)
A tree of nodes.
Re:Software Engineering at Google (2020) [pdf] by shakezula on Wednesday May 04, 2022 @08:57PM (#31268039)
And we model sentences the same way
Re:Software Engineering at Google (2020) [pdf] by cjg on Wednesday May 04, 2022 @06:43AM (#31258700)
Often significantly more indented.
Re:Software Engineering at Google (2020) [pdf] by shric on Wednesday May 04, 2022 @09:31AM (#31260115)
The nice thing about books about how Google does X (SRE, SWE, etc.) is you can adopt the good/relevant parts however you see fit and ignore the stuff that either only applies to Google scale or makes no sense.
Re:Software Engineering at Google (2020) [pdf] by spockz on Wednesday May 04, 2022 @02:38AM (#31257426)
I think we need some contextual line width limits. When splitting a function/method definition over multiple lines, I like to align the parameters. Now if there is a short line limit this will force us to left align the parameters instead. This has the consequences that there is less visual, spatial, distinction between method definition and their code, resulting in a big hodgepodge of characters.

If we have contextual limits, we can make method headers arbitrarily long while keeping the body within a tight limit. Or allow a longer line when defining a lambda in python as another comment laments.

Re:Software Engineering at Google (2020) [pdf] by 4ad on Wednesday May 04, 2022 @07:07AM (#31258875)
> When splitting a function/method definition over multiple lines, I like to align the parameters.

Please don't do this. It's horrible for us who use proportional fonts.

In fact I would go as far as arguing that "artificial" line breaks are always bad. They aren't really more readable, quite the opposite usually, and most importantly they break diff.

I like short lines, and it's a good ideal to strive for. 98.5% of my code fits in 80 columns, but if I need a longer line, don't artificially make it worse in the pursue of some arbitrary rule.

Re:Software Engineering at Google (2020) [pdf] by Rebelgecko on Wednesday May 04, 2022 @02:48AM (#31257475)
The width limit is per language- some are longer than 80. And some languages, believe it or not, don't even have readability
Re:Software Engineering at Google (2020) [pdf] by google234123 on Wednesday May 04, 2022 @02:52AM (#31257494)
Sorry, i didn’t mean to use that word to mean that. Was just talking about how it’s easier to read parameters and long conditional statements that are split over separate lines.
Re:Software Engineering at Google (2020) [pdf] by jppittma on Wednesday May 04, 2022 @06:07AM (#31258510)
No languages have readability on GoB. You don’t know what you’ve got until it’s gone.
Re:Software Engineering at Google (2020) [pdf] by unicornmama on Wednesday May 04, 2022 @03:54AM (#31257847)
This style was written for C++ developers who work author on terminals. It shouldn’t be taken seriously outside that context.
Re:Software Engineering at Google (2020) [pdf] by whatever1 on Wednesday May 04, 2022 @02:03AM (#31257205)
Why is this a thing in languages that are not Fortran 77?

Why not a 1000 character long line?

If I want the editor to overflow it below or show me a scrollbar should be my choice.

Re:Software Engineering at Google (2020) [pdf] by compiler-guy on Wednesday May 04, 2022 @07:11AM (#31258908)
In a personal project that makes a lot of sense (and in a personal project you have your choice), but once you are in a corporate or open source project of more than just a couple of people, code is read far more often than it is written, and by many more people than the original author.

In those circumstances, it makes sense to optimize for readability to everyone rather than the author’s personal preferences. One can easily argue that Google’s style isn’t optimal, but it’s harder to argue that a personal preferences free for all is optimal.

Re:Software Engineering at Google (2020) [pdf] by whatever1 on Wednesday May 04, 2022 @10:37AM (#31261068)
The fact is that the limit of 80 characters length is arbitrary. No evidence that code of 80 characters length is more readable than code of 83 characters length.

The other fact is that few devs craft their code to fit 80 characters. Instead they write code and let formatters do their thing. But automated formaters are doing a horrible job, aka if I write a line that is 81 characters long, they will massacre it to a set of unreadable lines with no proper aligning.

So now we are at the mercy of automated formatters that try to enforce an arbitrary constraint that is irrelevant with today's code editing/reviewing technologies.

Re:Software Engineering at Google (2020) [pdf] by dudeman13 on Wednesday May 04, 2022 @02:53AM (#31257506)
>Why not a 1000 character long line?

I work in a codebase where a previous dude constantly did this. I do not find those lines amusing.

Whenever I'm un-fucking his stuff one of the first things to do is expand his infinite lines into usually 5-50 lines because visualizing and reasoning about 50 lines of code crammed into one requires someone who is totally a way, way better programmer than me.

I don't need to git blame to know when the code was written by that guy.

Re:Software Engineering at Google (2020) [pdf] by nine_k on Wednesday May 04, 2022 @02:37AM (#31257421)
Diffing an excessively long line is uncomfortable in most tools. A crash dump mentioning the 1000-character line leaves you thinking where in that line the error has happened.

The actual limit should be the complexity of one lihe, something like the number of AST nodes in it. But our tools which go back all the way to mechanical teletypes and punched cards are firmly line-oriented. This allows them to be language-agnostic.

Re:Software Engineering at Google (2020) [pdf] by thfuran on Wednesday May 04, 2022 @08:03AM (#31259308)
I think it's reasonable to have restrictions on both. Regardless of complexity, long lines make it hard to view side by side diffs on your screen.