Post by Danny Tuppenyespecially the method at the bottom (I don't think it'd look so bad with
Post by 'Bob Nystrom' via Dart MiscPost by Danny Tuppenystring.format, but it looks horrible like this).
I think it would look a little better if you weren't using ".." for the
sort() call. If you don't want it to be one line, then going out of your
way to make it one *statement* is a little odd.
I didn't go out of my way to make it one statement, it just felt more
natural (otherwise I'd have loads of variables only being used on the next
line, which seems rather noisy).
I'm a total Dart noob though, so don't for a minute think this code is
ideal. I'd be really interested to know how you'd write/format it though! A
https://gist.github.com/DanTup/2fbdde2b5c5a69520c56ba072ca28b7e
If it were my code, I'd do:
String toQueryString(Map<String, String> data) {
var items = data.keys.map((k) => "$k=${encode(data[k])}").toList();
items.sort();
return items.join("&");
}
Post by Danny TuppenyI do prefer the 80 column limit. It causes some extra wrapping, but it
Post by 'Bob Nystrom' via Dart Miscmeans I don't have to awkwardly scroll horizontally to see all of the code
like I have to do right now with your screenshot in gmail. :)
To be fair, that's two screens side-by-side! :P
Right, but that's a typical use case when you're doing code reviews,
looking at diffs, etc.
Post by Danny TuppenyI've just got an ultrawide monitor (2660x1080) and I have all this width
not being used...
Many users (including me, for what it's worth) do almost all of their work
on a laptop screen.
When I do use a big monitor, I use the extra horizontal space for other
columns, docs, other tool windows, etc.
Readability of text generally goes down when lines go above a certain
length. The wider the line, the longer it takes your eye to track back to
the beginning of the next line, and the greater chance of making mistakes
and skipping or double-reading a line. That's why newspapers use several
relatively columns of text on their big wide sheets of paper.
Post by Danny TuppenyEven with two VS Code windows open (both with the explorer view down the
side) 80 characters takes up hardly any of the screen.
I don't think constraining the width is a bad idea, it just feels like 80
is too short (and it feels like indenting with 2 spaces, which I think is
also insane, was done because of this width) :(
I don't know where the 2 space thing comes from, but it's used in languages
at Google that don't have the 80 column limit. We just followed other
Google language styles that all use 2 spaces. It seems like most of the
open source ecosystem is going in that direction too.
Post by Danny TuppenyThe formatter is designed to do a good job on real-world code. You can
Post by 'Bob Nystrom' via Dart Miscalways make non-idiomatic code that gets formatted weird because the
formatter isn't tuned for that. If you were to make this example a little
blah
.doSomething()
.doSomethingElse()
.uppercase
.sorted
.filter(() => stuff > whatever);
Then you will see it also formats it more like you prefer.
But presumably that only doesn't get unwrapped because the whole thing is
too long?
Right.
Post by Danny TuppenyIt seems weird that you could write two identical chunks like that, one 81
chars, one 79 and they would format very differently.
Well, we're talking about a tool whose job is to produce an
optically-consumed output. Spatial dimensions matter.
I presume the rules on the decisions the formatter uses aren't really
Post by Danny Tuppenydocumented other than in the source?
Alas, no, though I have an issue
<https://github.com/dart-lang/dart_style/issues/395> to do that. I did
write up how the formatter applies its rules
<http://journal.stuffwithstuff.com/2015/09/08/the-hardest-program-ive-ever-written/>,
though. It's pretty complex.
The rules themselves are simpler, but they also have a good bit of
sophistication in them. Like many user interface issues, what you
intuitively think is simple when you do it manually actually turns out to
have a large amount of subtlety that you aren't conscious of.
Cheers!
â bob
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.