-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rethink the 80 characters line limit #833
Comments
Increasing the column limit doesn't really fix that problem. You're still wasting just as much space on the left side of the page. You're just able to make the window wider and eat space on the right side of the page that you could be using for other things. Some amount of nesting is, of course, natural in Flutter. But I don't think any page width is going to make >10 levels of indentation a good idea. That's just too much nesting for the eye to follow. Instead, I think a better solution is:
I do all of my work on a 15" laptop and very much appreciate being able to do side-by-side diffs, so going wider than 80 columns would be a significant challenge for me. |
The problem is when we are obligated to run dartfmt before each commit. this way we can't escape the laws of indentation, unless the Flutter team releases a new flutterfmt tool to help with this. Also, breaking down into smaller Widgets is just swapping one problem for another. We reset the indentation, but now we have lots of boilerplate to code. Helper methods are in general not recommended . Also, sometimes splitting the Widget tree makes it easier to read when you care about the high level, but it also can make it harder, if you are trying to follow down the rabbit hole on where's the problem, and you find yourself going back and fort in the file, looking for different Widget classes, so it can be helpful or not, depends on the context. I am not saying I am against breaking the build method, I do it all the time, it's just that sometimes it just doesn't make much sense, and if we use more specialized Widgets, like |
You can pass |
I generally use Ctrl+Alt+L in IntelliJ IDEA, can't see an option in the plugin to pass this configuration :/ |
@feinstein I think that piece of advice about helper functions is about something entirely different. Not using mere functions instead of actual widgets. This has its clear reasons but that doesn't in any way forbid you from using helper methods inside your widgets. Basically:
instead of lifting the Having said that, I wholeheartedly agree with the lifting of the 80 character limit which I have always found hilariously low in the age of 28-30-whatever monitors. And even on laptops. |
@feinstein by the way, if you go into Settings > Editor > Code style > Dart > Dartfmt, you'll see that it does pick up the width from another tab. Although I'm not sure it really does make any difference. :-) |
I know that changing my code helps, but I feel this is like Apple saying "you are holding it wrong". I just don't want to write additional code when I think my actual code is OK, just too much to the right. It's like creating a new problem for fixing an old one. |
As another data point, I did a search and found that ~35% of our organization's Dart projects (maintained by various independent teams) use a custom dartfmt line length of either 100 or 120 as opposed to the default 80. And, almost all of those repos with custom line lengths contain over_react UI code, which has similar nesting/syntax to Flutter widgets. |
PSR-12 defines the concepts of soft limit and hard limit:
I think it is quite fair and looks nice for PHP. There might be something similar for Dart as well. In my opinion, 80 and 120 would be great. |
Sure, but another way to look at that data point is that ~65% of your teams are using the 80 character line length, which implies that it's the right choice to standardize on. |
They are using 80 characters per line does not mean that they think it is better, most programmers I know do not agree that 80 is better, but use it as a guideline. Part of the projects is 80 characters per line and part 120, but if the guideline changes to 120 everyone would use the same pattern. |
No, Bob, it isn't. You can be as opinionated as you please in other corners of dartfmt, especially if, as right now, good placement of empty comments allows us to influence the formatting in many cases, but don't force line lengths on us, keep it a setting. Not everybody works in teams. Not everybody uses 14" laptop screens. Not everybody actually cares about old-fashioned ideas why the 80-limit should be better than anything larger of having no limit at all or whatever. It's really understandable that, for the sake of uniformity, you never wanted to introduce hundreds of user changeable settings. During the last year or so of working in Flutter I've grown to actually like the way dartfmt works (and in the few cases where I have differing opinion, I simple use those extra comments) but I'm sure to switch it off the minute you decide to rob the line length setting from us. I like working on a 30+" monitor and I want to use it all, not just the left quarter strip. |
There are advantages to embracing a universal line length limit in the community. It's the tabs-vs-spaces and other endless discussions happening all the time in all programming communities (e.g. Python's PEP8). This reminds me of the Go Proverb:
I don't really care if it's 80 or 100 characters, what I do not want is every package on pub.dev using different styling conventions and buggy, complex tools. |
As I said in my original post, the 80 character line was made for newspapers and magazines, so eye movement be constrained to a region, this way reading would be more comfortable and easy to matain attention on the text. But in Flutter we get lots of whitespace indentations on the left, making the text more like a zigzag pattern, not the same as a newspaper. So here's a crazy idea to explore and research: 80 character lines counted after the first non-whitespace character in that line (left most whitespaces should be ignored on the character count). This could be coupled with IDE tools that auto-scrolls the text left and right, keeping it bit centered as we scroll it up and down (but not perfectly centered, so we still get a sense of indentation as we scroll). Is this good? Will it work? Will code be easier to read? Is this ridiculous and will it fail miserably? I have no idea, but I would love to see some research done on it, that's how science evolves afterall, crazy hypothesis being tested so we can come up with new ideas and new hypothesis based of the previous ones. |
@feinstein The 80-char has nothing to do with newspapers and magazines. That's an afterthought somebody tried to make up to justify that very old rule that simply goes back to the monitors of several decades ago. |
Independently, my suggestion is based on the fact that Flutter code has lots of leading whitespaces, whereas normal texts does not, so my suggestion stands. |
It appears that Linus Torvalds agrees with us: |
There are no plans to remove the option for specifying line length when running the formatter. |
I want auto formatter when saving. |
Linux uses 8 spaces of indentation, though, which Dart does not. |
This, to me, is the most frustrating pain point of Dart. We can run The only compelling argument I've heard against finalizing this feature is "because I don't want to," which honestly, is a fairly compelling argument in open source as far as I'm concerned, but it doesn't make it any less frustrating and senseless. I understand that maintaining |
Even with 100 I can easily split the editor window vertically. 80 is so limited that it breaks even short+dumb code lines into multiple lines -> the brain has to work more cognitively to unwrap the riggidy broken lines. |
Just dug this up. I have a line length configured on my computer, and another one configured on my laptop. I have to remember, in my brain, the line length I have set, otherwise, I save files, and then it makes a git diff a total nightmare. Also, this comment:
That's nice, and would relevant if you were the only person that used Flutter to develop apps. But you're not. So it's not relevant. And even if it was too wide or whatever, you could configure it by setting it in the pubspec.yaml as required. |
I work on a laptop, 1920x1080 so nothing fancy and I can side-by-side 100 or even longer files. |
I see there are two main arguments: 80 characters is standard, > 80 characters can look nicer. I think having the option for both should make everyone happy. Since we can already override |
I don't think it's particularly useful to try and make an argument that 80 lines should always or never be used. Ultimately, I think the ask here would be to allow teams to make their own decisions via configuration. |
It's already possible to pass a flag for this configuration. The original post was about what character limit per line should be the official recommendation or default option. For example, in my team we use 1000 characters as a limit in the dart format tool (PRs aren't allowed to be merged if there's a formatting issue), which is basically just saying that we don't want to limit. Why we don't limit? Because we believe breaking code lines at each 80 characters can make code harder to read, which is the opposite of the original intention of the 80 characters limit. In my team the devs usually make cleaner line breaks than the tool with 80 characters, but I don't know if this applies to everyone. |
There is a command line flag but you cannot bubble your custom settings down to everywhere in the toolchain. In some places the 80 still pops up. Another thing is that I would like more detailed command line switch. My apps have generated code (Floor and Mockito generate code). These of course use the default 80, and once that goes through my custom setting ti unnecessarily changes those files. |
I think the main problem is rather pub.dev warning, isn't it? |
If it was just a warning... But it's a hard error. |
Let's just meet half-way and make the default 100. |
Just stop using Dart. After a week of making changes to mangled flutter code we have, I’m done, it’s utterly unreadable. 80 character limit isn’t the issue though, the issue is that bot formats your code, and all bots are tone-deaf and have zero understanding of what’s human readable or which parts of code are actually important. |
Ditching Dart would mean abandoning Flutter which would be kinda drastic. |
We're mad, but not that mad. |
Considering that I'm hardly the only one who considers Flutter to be better than any other contemporary mobile cross platform framework, by a long sea mile, this is rather unlikely... :-) In your IDE, where reading your own code counts, you can change the line length setting. The only problem is when you want to publish packages for others but, frankly, if you're at the stage when you abandon ship that easily, I don't think this is an issue yet. |
I prefer the 80 line format. Kind of way to identify for me if a widget is too nested. Some devs prefer adding a conditional statement in the widget tree which in my opinion should be avoided if possible. It makes the widget tree more readable in a sense you don't have to read a widget tree both horizontally and vertically. Should the screen/page/stateless/ful is huge. Just properly separate it in a widget class which makes sense. Don't hate please. Just stated my opinion based on experience of having a peer code review for a long time. |
@rirjkl19 I get your point about forcing to not nest code, but still 80, 100 or 120 would not make a big difference for nested code and giving more screen space for a single line does not prevent people to be good developers |
voting for controversial opinion: Make it 80 after indent.
This will work especially well with viewport wider than 80, as almost all code on visible lines will fit. (except for rare, extremely "leaning" code, which tends to not have long lines anyway) (The more code I see at the same time, the more productive I am. [1] Yes, all of this can be solved with refactoring, and arguably, in many cases, it is better to do so. But there are also many valid cases, where it's not. I don't think any absolute limit will ever be a good solution. People who feel they need +10 today, will equally need +10 then. Monitor widths are not a good reference point. Neither annoyingly limiting to 800x600, neither expecting everyone to have HD widescreens, nor expecting any point in between. It should work on all, without being annoying, using as much space as the user desires, without forcing it on others. |
As a 64 year old programmer, I just want to comment that the 80 character line limit is rooted in the days when we used punch cards to represent lines of code, and there was a lot of inertia for a few years afterward to maintain backward compatibility. Please recall that in those days, a significant amount of programming was done in assembly. So 80 characters seemed like a very comfortable amount of line width. I think there's a strong argument to be made for creating tools that enforce consistency within a project or development group. I think it's problematic to argue for "One line width to rule them all." |
I strongly disagree with some of the requests to have a line length limit that ignores indentation. Doing so would mean that lines could be arbitrarily long, and therefore there would never be an editor/terminal/window width wide enough to guarantee that all lines are fully visible without horizontal scrolling or wrapping. That seems like a compromise that would be bad for everybody. I think ideally there would be no set length limit and that editors/terminals/windows could reformat code dynamically based on their current width. But that's probably not realistic for non-IDEs. Otherwise I don't think it's possible to reach any kind of consensus on what any specific line length limit should be. I personally use 80-column terminals, so I like 80, but I also recognize that that's not everyone's cup of tea. I do think that there should be a way to specify the preferred line length per-project instead of per-user. Making |
@jamesderlin I don't know in VS Code (I use it for many things but not Flutter, it just happened that way) but in Android Studio, you can set it to your line length, I always have it at 999 what practically means no line length. As I have already mentioned above, it's not a problem in a sane IDE, you can set it to whatever you like, so there's no need to try to convince each other of the perfect line length. The problems is with places like Pub.dev where a specific setting is enforced. |
Then that should be an issue filed against the pub.dev repo, and it looks like there already is dart-lang/pub-dev#3041. |
Yeah the dart development team needs to understand that not everyone is using a tiny monitor. |
I totally agree with this, which is followed by dart-lang/pub-dev#3041. |
Just give us a config file where we can set line length per project, nothing else ... |
I totally agree with this comment We can consider setting the maximum length of each line in the lint configuration file Consider an open source project. New contributors may not necessarily read the contributing file in detail, or there may be no such file at all. If these automatic formatting settings can be determined by the lint configuration file, and vscode or plug-ins on other platforms can also Following these settings, it will become very user-friendly, and developers only need to focus on the code logic. |
I think at this point it's just that they want to show us THEY get to choose those stuff, there is zero good reason not to add this feature but they don't want to admit they are wrong so they will just prevent us from having this basic and very needed functionality |
Dart format was opinionated, always, and Munificent (Bob) was always vocal about it. It usually grows on you, the more you use it. Only that I always thought that it could be opinionated inside the constraints but the line length is such a constraint that should be removed from |
Let's try to keep the discussion constructive and to not be overly dramatic. If your claim were true there wouldn't be a way to configure line length at all. |
How about put the configuration in |
I am not sure if this is the right repository to discuss this, but I would like to propose a investigation if 80 characters per line should still be the recommendation and dartfmt default.
The Dart style guide says:
I think this is perfectly valid for regular text for newspapers and magazines, that usually come in the form of:
But recently with the soaring success of Flutter, we are finding deeply nested code, which leads to lots of space being wasted as pure indentation. This picture shows how one of my Flutter widgets has just about half its line wasted in indentation, forcing me to break lines all the time:
Bear in mind, this is just a 9 Widget deep tree:
Provider>Scaffold>SafeArea>WillPopScope>Column>Consumer>Padding>Row>Text.
And I didn't have any classes there with long names. If I did, it would have been a multi-lined mess.
IMHO, we can't use studies made for newspapers for coding styles, specially after the usage has become so different in the Flutter age.
I have seen people in the past defending 80 character lines saying it fits better all monitors, but nowadays with everyone using 24" monitors 1080+ I don't think that's longer the case.
I don't want to propose a new number, like 120 characters, but instead I would like to suggest that Google should launch a research on this, taking in consideration Flutter Apps and what line character count fits better their code.
My hope is that we don't turn out in the end with just 40 characters per line as real usable space due to indentations and enforced standards.
The text was updated successfully, but these errors were encountered: