3 ms·
> My feeling though is the problem is they have a line limit. There are a few reasons why we do 80 columns: 1. Human eyes have an effective line limit. The lo
by munificent 11y ago
> My feeling though is the problem is they have a line limit.
There are a few reasons why we do 80 columns:
1. Human eyes have an effective line limit. The longer a line gets, the harder it is to scan back to the beginning of the next line. This is why paperbacks are taller than they are wide and why newspapers use several short columns instead of one wide one.
2. Being too narrow hurts readability, sure, but being too wide does as well. Also, even though many developers have giant monitors now, we also spend a lot of time on laptops, doing side-by-side code reviews, looking at code on blogs, etc. 80 columns is pretty friendly towards all of the various and sundry places where a user may be looking at some code.
3. We found it encourages better code. Dart is syntactically kind of a superset of Java, which means you can write Dart code that looks like Java. In particular, you can revisit some of the egregiously verbose naming practices that infected that community in the 90s. I see a lot of code like:
LoggedInUserPreferenceManager preferences = new LoggedInUserPreferenceManager();
A shorter column limit has worked as an effective nudge to get people to do:
var preferences = new Preferences();
> The article just pointed out a year of wasted time.
We'll get the time back. It's amortized over the amount of time saved by running it x the number of engineers using it.
> I can point to searching and replacing an identifier and then having to go manually reformat hundreds of lines of code all because of some arbitrary style guide.
The problem here is that you had to manually reformat it! Refactoring is a key goal of automated formatting. You can make a sweeping change to the length of an identifier and automatically fix the formatting every where it appears.
> I also had code generators at google that had to generate code that followed the line limit.
Code generators are another explicit use case. We have a lot of code generators now that produce completely unformatted code and the run dartfmt on it.
> I too wasted days futsing with the generator to break the lines at the correct places all because of some arbitrary line limit.
Should have used an automated formatter.
- skybrian 11y agoDid you know that Go doesn't have a line limit and gofmt doesn't wrap lines? It only fixes whitespace within a line. It's up to programmers to split lines manually. It seems to work for them, so clearly there's more than one way to do this.
- munificent 11y ago> Did you know that Go doesn't have a line limit and gofmt doesn't wrap lines? Yup. My feeling is that this keeps gofmt much simpler, but it kind of punts the problem onto users. I wanted a more complete solution, even though the result is a lot more complex.
- greggman 11y agoThe idea of an auto-formatter has come up many times on the Chrome team. It is always shot down because formatting often imparts meaning. Meaning that is unclear to an auto-formatter. Of course you're free to run an auto-formatter over your own code. Often I want to format things that are more readable for me. Example (yea, not Google style guide example. Too lazy to dig one up) uint32_t rgba8888 = ((red & 0xFF) << 24) | ((green & 0xFF) << 16) | ((blue & 0xFF) << 8) | ((alpha & 0xFF) << 0); vs uint32_t rgba8888 = ((red & 0xFF) << 24) | ((green & 0xFF) << 16) | ((blue & 0xFF) << 8) | (alpha & 0xFF); I think the first is objectively more readable than the second. An auto-formatter is unlikely to ever format that in a "readable" way. Another simple example. If I have a many argument function ctx.arc(xPosition, yPosition, radius, startAngle, endAngle, clockwise); If I break that line I'm not going to break it between xPositon and yPosition, nor and I'm going to break it between startAngle and endAngle. An auto-formatter will never know that semantically those things are more readable when they are on the same line. Similarly you claim the short length encourages shorting names but you still run into plenty of situations where the code is far far less readable because of the line limit. Example, assume 40 char limit int w = desired_width * scale_factor + padding; int h = desired_height * scale_factor + padding; glBindTexture( GL_TEXTURE_2D, someTexture); glTexImage2D( GL_TEXTURE_2D, level, format, w, h, border, format, type, data); glTexParameter( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); vs int w = desired_width * scale_factor + padding; int h = desired_height * scale_factor + padding; glBindTexture(GL_TEXTURE_2D, someTexture); glTexImage2D(GL_TEXTURE_2D, level, format, w, h, border, format, type, data); glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); Chrome in particular is full of code line wrapped into what is effectively obfuscated code. So no, I don't agree what a line limit has any point. You claim human eyes have a line limit. I don't disagree per say, but in my years before Google I never found anyone seriously abusing line length. Then again I never had to use Java but that's a separate issue. I hope Dart is not targeting Java's verboseness. I could make the same claim that unbroken lines, up to a point, are more readable, understandable and I will go on to claim that the 80 char limit at Google breaks that rule and ends up cause 20% of Google's code or more to effectively be obfusticated.