Live data from Hacker News

A Prettier JavaScript Formatter

jlongster.com

111–120 of 159 posts

Re: A Prettier JavaScript Formatter

#111
post #108

Earlier quoted context omitted.

gofmt doesn't solve the hard problem that this blog post (and Wadler's paper) is about. From the article: "There's an extremely important piece missing from existing styling tools: the maximum line length." gofmt's decision to not bother to require a line length may work somewhat for Go (which tends to encourage short lines by virtue of lacking expressiveness), but it doesn't work for lots of other languages, includi…

The fact that gofmt doesn't enforce some arbitrary line length is a blessing. I have a modern widescreen monitor and I use a maximized window text editor. I have no problem with 200 char length lines. I'm more easily annoyed by 80 (or 60, like in this case) char limits, as if I was viewing this code on punch cards.

It can be configurable. The rust community for example sticks to 100 or 120 lines (and rustfmt lets you choose).

I have big screens but side by side diffs on unformatted code on GitHub are always wrapped. Plus I often split my screen. Not everyone uses maximized windows all the time, and in a shared codebase sometimes you want to try and cater to everyone.

Re: A Prettier JavaScript Formatter

#112
post #109

Earlier quoted context omitted.

gofmt doesn't solve the hard problem that this blog post (and Wadler's paper) is about. From the article: "There's an extremely important piece missing from existing styling tools: the maximum line length." gofmt's decision to not bother to require a line length may work somewhat for Go (which tends to encourage short lines by virtue of lacking expressiveness), but it doesn't work for lots of other languages, includi…

Why does the formatter need to solve this and not the editor? The editor has more information available to it, like the present screen space.

Theoretically, an editor could. I have yet to see one that does this well. Most do dumb wrapping, with no language sensitivity.

I think it's just a matter of programmer habit now -- folks expect their editor to mirror the code without formatting tweaks.

It gets confusing when you realize that programmers may insert their own indentation and wrapping, and sometimes you want to make this part of the actual file, and sometimes you want to remove it before serializing.

Re: A Prettier JavaScript Formatter

#113
post #108

Earlier quoted context omitted.

gofmt doesn't solve the hard problem that this blog post (and Wadler's paper) is about. From the article: "There's an extremely important piece missing from existing styling tools: the maximum line length." gofmt's decision to not bother to require a line length may work somewhat for Go (which tends to encourage short lines by virtue of lacking expressiveness), but it doesn't work for lots of other languages, includi…

The fact that gofmt doesn't enforce some arbitrary line length is a blessing. I have a modern widescreen monitor and I use a maximized window text editor. I have no problem with 200 char length lines. I'm more easily annoyed by 80 (or 60, like in this case) char limits, as if I was viewing this code on punch cards.

> The fact that gofmt doesn't enforce some arbitrary line length is a blessing.

You don't have an infinitely long screen. You have some line length limit.

Re: A Prettier JavaScript Formatter

#114
post #109

Earlier quoted context omitted.

gofmt doesn't solve the hard problem that this blog post (and Wadler's paper) is about. From the article: "There's an extremely important piece missing from existing styling tools: the maximum line length." gofmt's decision to not bother to require a line length may work somewhat for Go (which tends to encourage short lines by virtue of lacking expressiveness), but it doesn't work for lots of other languages, includi…

Why does the formatter need to solve this and not the editor? The editor has more information available to it, like the present screen space.

> Why does the formatter need to solve this and not the editor? The editor has more information available to it, like the present screen space.

Because making the line wrapping nice requires deep syntax-aware editor integration. Most languages try to be at least somewhat plain-text-editor-friendly.

Re: A Prettier JavaScript Formatter

#115
post #109

Earlier quoted context omitted.

Why does the formatter need to solve this and not the editor? The editor has more information available to it, like the present screen space.

Theoretically, an editor could. I have yet to see one that does this well. Most do dumb wrapping, with no language sensitivity. I think it's just a matter of programmer habit now -- folks expect their editor to mirror the code without formatting tweaks. It gets confusing when you realize that programmers may insert their own indentation and wrapping, and sometimes you want to make this part of the actual file, and so…

I've been pretty happy with vim and "set breakindent" where the broken line is indented to the parent one. I pretty frequently work with small views of a file.

Re: A Prettier JavaScript Formatter

#116

Earlier quoted context omitted.

It's almost crazy to think this already isn't just a thing. Why is this just coming to a head now, after all these years of carrying on over code formatting?

I'm not convinced it is just coming to a head now. I've seen automatic/forced formatting on projects at least as far back as 2000, when I entered the workforce.

The ones I've used for java have been consistently bad though. Autoformat as a commit hook leads to ugly code. Granted, I mean "bad" as in "gets ya 75% of the way".

Re: A Prettier JavaScript Formatter

#117
post #109

Earlier quoted context omitted.

Why does the formatter need to solve this and not the editor? The editor has more information available to it, like the present screen space.

> Why does the formatter need to solve this and not the editor? The editor has more information available to it, like the present screen space. Because making the line wrapping nice requires deep syntax-aware editor integration. Most languages try to be at least somewhat plain-text-editor-friendly.

> Because making the line wrapping nice requires deep syntax-aware editor integration.

Why does it need to be syntax aware?

Re: A Prettier JavaScript Formatter

#118
post #109

Earlier quoted context omitted.

gofmt doesn't solve the hard problem that this blog post (and Wadler's paper) is about. From the article: "There's an extremely important piece missing from existing styling tools: the maximum line length." gofmt's decision to not bother to require a line length may work somewhat for Go (which tends to encourage short lines by virtue of lacking expressiveness), but it doesn't work for lots of other languages, includi…

Why does the formatter need to solve this and not the editor? The editor has more information available to it, like the present screen space.

I wish more people would realise this.

Re: A Prettier JavaScript Formatter

#119
post #55

This is awesome, but one request: can you please extend it into a real (ie, AST based) diffing tool? Current diffing tools all compare the text (which is basically an input format) rather than the AST, and hence end up focusing on formatting rather than actual changes.

If you auto-format as a commit hook then all of the changes you see will be AST-based, and you can ignore the style.

Re: A Prettier JavaScript Formatter

#120
post #108

Earlier quoted context omitted.

The fact that gofmt doesn't enforce some arbitrary line length is a blessing. I have a modern widescreen monitor and I use a maximized window text editor. I have no problem with 200 char length lines. I'm more easily annoyed by 80 (or 60, like in this case) char limits, as if I was viewing this code on punch cards.

> The fact that gofmt doesn't enforce some arbitrary line length is a blessing. You don't have an infinitely long screen. You have some line length limit.

It's infinitely scrollable though. Scrolling horizontally sometimes isn't a bad fallback.
Post reply on HN