Produce consistently formatted code. Consistent style improves readability because you aren't distracted by differences in style between different parts of a program. It makes it easier to contribute to others' code because their style will already be familiar to you.
End debates about style issues in code reviews. This consumes an astonishingly large quantity of very valuable engineering energy. Style debates are time-consuming, upset people, and rarely change anyone's mind. They make code reviews take longer and be more acrimonious.
Free users from having to think about and apply formatting. When writing code, you don't have to try to figure out the best way to split a line and then painstakingly add in the line breaks. When you do a global refactor that changes the length of some identifier, you don't have to go back and rewrap all of the lines. When you're in the zone, you can just pump out code and let the formatter tidy it up for you as you go.
Produce beautiful, readable output that helps users understand the code. We could solve all of the above goals with a formatter that just removed all whitespace, but that wouldn't be very human-friendly. So, finally, the formatter tries very hard to produce output that is not just consistent but readable to a human. It tries to use indentation and line breaks to highlight the structure and organization of the code.
--
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+uns...@dartlang.org.
I agree with everything you've said, Bob. But in terms of line length vs tab-and-indent length, is there a reason why you can configure one and not the other?
I would guess that it was just so dead simple to make 80 vs another integer configurable, that it was an easy concession.
But tab-vs-indent requires a little more opinions and decisions (default is 2 in some cases, 4 in others, so if you "configure" to use a 4-space indent, then is it 4 and 8? if you use tabs, is it 1 tab and 2?)
Ah, good points, Bob. It does seem a nightmare to support tabs and consistency at the same time.
Thanks for the response!
As for tabs: they make it impossible to read the code outside of your own IDE Standard editors may show 8, 4, or 2 spaces depending on configuration. For many, 8 is the default. I have this problem very often while working with somebody else's code (to make things worse, the code may include combination of spaces and tabs, so you have a complete mess on your screen)
dartfmt needs to know exactly how long a line is in actual columns so that it knows where to line-wrap, so even if it supported tabs, it would have to treat them as having a very explicit width in characters, so you get no flexibility from using tabs.
--
--
Of course you can change it in your IDE. But do you really want to manually switch this option every time you look at someone else's code? Or do you suggest the source file should have some machine-readable comment that would give it a hint what the tab size is (like "/* tabs=4 */)?
That's not entirely true - if dartfmt wrapped with the assumption that a tab is 2 chars, you still have the flexibility to render them as 4 in your editor if you wish.
I genuinely can't see any negative from using tabs (except for tools that render tabs at a size you would not like; but how is that worse than my editor, the thing where I actually write the code, not rendering at a size I would like?)
Again, I don't expect this to change (and don't want to dig up tabs vs spaces) but other than "it's too late to change", I just can't see how spaces is a better choice than tabs.
To this day, languages and projects that prefer tabs over spaces have problem when folks see their code rendered on GitHub or some other source code host that is not their preferred editor.
It is relatively easy to see how in projects that indent with both tabs + spaces, that the lines don't indent neatly all the time when the tab preferences are changed. If more than 1 person edits the code with different specifications, the code could have multiple formats.
Anyway as it's always apparent when discussing programming, some people are OK if the preference works for an individual, whereas others are ready to cast the problem as one that can affect a whole company or community. Dart is supposed to be a language for larger teams. Even if we know that many projects have just a couple of developers driving them.
That's not entirely true - if dartfmt wrapped with the assumption that a tab is 2 chars, you still have the flexibility to render them as 4 in your editor if you wish.Sure, but then you'll be annoyed when dartfmt wraps your lines "prematurely" because you see them as farther to the right than it does. In fact, setting a tab stop higher than two means you can no longer rely on all the code in your window fitting in 80 columns.
I genuinely can't see any negative from using tabs (except for tools that render tabs at a size you would not like; but how is that worse than my editor, the thing where I actually write the code, not rendering at a size I would like?)The reason we use monospace fonts for code is because it makes it easier to line things up horizontally and ensure code fits within various horizontal dimensions.Tab is like a super-non-monospace character that is not only not as wide as every other character, but its width isn't even stable across users and tools. That's not a good recipe for consistent typography.
Again, I don't expect this to change (and don't want to dig up tabs vs spaces) but other than "it's too late to change", I just can't see how spaces is a better choice than tabs.Tabs add a lot of complexity. Every tool, web site, code review system, editor, etc. needs to handle them, have a UI to let users configure their width, persist that setting somewhere, etc.
In return for that, you get per-user variance on indentation. That assumes that user's ability to read code with certain indentation varies so much that it justifies that complexity.
--
If I prefer my indent at 4 characters, I should be allowed to have it.
Again, I don't expect this to change (and don't want to dig up tabs vs spaces) but other than "it's too late to change", I just can't see how spaces is a better choice than tabs.Tabs add a lot of complexity. Every tool, web site, code review system, editor, etc. needs to handle them, have a UI to let users configure their width, persist that setting somewhere, etc.Not true. They only need to add options if you want them to be customisable.
Of course you can change it in your IDE. But do you really want to manually switch this option every time you look at someone else's code? Or do you suggest the source file should have some machine-readable comment that would give it a hint what the tab size is (like "/* tabs=4 */)?I don't understand what you mean. No, you'd never changed it, nor would you need a hint. You set your editor to how *you* want it - eg. Google would set it to 2, and I would set it to 4. All code I open would be indenting by 4 characters for me, and all code Google open would be 2. Everyone is happy; nobody needs to mess with anything.This assumes you never open any Google code and we never open any code of yours, right?
On Fri, Aug 26, 2016 at 11:11 AM, Danny Tuppeny <da...@tuppeny.com> wrote:If I prefer my indent at 4 characters, I should be allowed to have it.Yes, but your preference has an implementation and complexity cost. Effort spent supporting customizable tab stops is time not spend on other useful features you might like. There is a real opportunity cost to letting users have their personal preference.
Not true. They only need to add options if you want them to be customisable.Yes, but just now, you said they should be customizable. If you're fine with "non-customizable tabs", their ASCII representation is 32. :)
Every code I've seen, if contains tabs, contains spaces as well (maybe it's only me?). Fixed editor setting won't help with that. Also, you have to be able to open in many tools (IDE, git, code review tool, or somebody just sends a snippet of code). Makes life absolutely miserable.
Here's the broken promise I'm talking about when you introduce tabs to dartfmt.
On Fri, 26 Aug 2016 at 19:40 'Filip Hracek' via Dart Misc <mi...@dartlang.org> wrote:Here's the broken promise I'm talking about when you introduce tabs to dartfmt.Actually, I disagree.Firstly, dartfmt doesn't promise less than 80 characters, you can already break that.Secondly, if you choose to set your tab to be large and you try to render on a short screen, things aren't going to fit. This is totally acceptable and as a user you get to choose which you want; larger tabs or fitting (mostly) into 80 char.I would take that 4-char indenting in a heartbeat. I am not coding in an 80-character wide terminal. If you are, then go with 2 characters, that's fine. With tabs, you have choice!(I'd also argue that code could be refactored; 8 nested levels of indenting in a single method seems somewhat unreadable regardless of indenting size).
I really don't understand these arguments... "You can't have tabs because if you set tabs to 4 characters then (this thing I don't like) won't look right". With tabs, I get to choose. You can still have your code was you want. People are making (invalid) assumptions about how others want their code. This only way this impacts those wanting 2-space indenting is that other tools will display things "wrong"; and that is no different to how things are to us wanting 4-char indenting see things in all tools.
Look in a better world people would understand that tabs are for indentation and spaces are for alignment. In a perfect world http://nickgravgaard.com/elastic-tabstops/ would be the norm.Having coded on many different codebases both internal and external you really need to just take the stance "when in Rome". Dart's format wants spaces so use spaces. Golang wants tabs. Python wants spaces. C/C++ can have any number of different formats. One code base I'm working on does 2 spaces another does 4 spaces. Who cares?The tabs vs spaces war is stupid. Silicon Valley even made a point of making fun of its absurdity https://youtu.be/SsoOG6ZeyUI.
--
So far I haven't used dartfmt, but if possible I will choose more than 80 chars on own projects
I understand the idea of the same input giving the same output; but its applied really inconsistently - for example, if you have blank lines in methods, they are preserved. So why not preserve newlines before method calls?
I understand the idea of the same input giving the same output; but its applied really inconsistently - for example, if you have blank lines in methods, they are preserved. So why not preserve newlines before method calls?There are a couple of places where one (and only one) discretionary blank line will be preserved. Basically between member declarations and statements. But those are not ideal when it comes to consistent automated formatted. Ideally, we would be able to automatically choose where to insert those blank lines too. Probably before lines that start with a line comment, and after statements and declarations that have {} bodies. I've taken some steps in that direction—it will always insert a blank line after function, class, and brace-bodied member declarations. But there's an art to automating the formatting while not being too disruptive to existing code. :-/
> But there's an art to automating the formatting while not being too disruptive to existing code. :-/You can treat special comment like //foff to copy the following lines, until blank line, as is. That's the whole art :)
Unless I'm remembering incorrectly, aren't these both left as-is?
So, what is the reason not to preserve them for chain method calls like in my earlier example?
What happens then is after a couple of minor nervous breakdowns and a bottle of Advil, you start writing good code, even without advice from jslint. You develop *perfect* style.Isn't it a goal of any aspiring writer. @Bob?
--
--
400,000 GitHub repositories, 1 billion files, 14 terabytes of code: Spaces or Tabs?
https://medium.com/@hoffa/400-000-github-repositories-1-billion-files-14-terabytes-of-code-spaces-or-tabs-7cfe0b5dd7fd
I guess being able to parse files slightly faster by having fewer space characters also helped them, evenif on that case they were just used to tabs when coming from C.
The Go code is not too nested and with their type inference and not having "generics" it keeps their codesparse. So even if they interpret their tabstops with the 8 spaces it would still fit on 80 columns, I'dassume.
var a = []
.filter((c) => true)
.map((c) => c)
.sort((c1, c2) => c1.name.compareTo(c2.name));
var a = [].filter((c) => true).map((c) => c).sort((c1, c2) => c1.name.compareTo(c2.name));
var a = [] //
.filter((c) => true)
.map((c) => c)
.sort((c1, c2) => c1.name.compareTo(c2.name));
var a = [] //
.filter((c) => true)
.map((c) => c)
.sort((c1, c2) => c1.name.compareTo(c2.name));
lol, interesting idea! :D
--
> lol, interesting idea! :D
Just don't tell Bob, he will be upset :(
> lol, interesting idea! :D
Just don't tell Bob, he will be upset :(
I don't think he gets upset easy.