Live data from Hacker News

Prettier 1.0

jlongster.com

31–40 of 78 posts

Re: Prettier 1.0

#31
post #24

I was waiting the --no-semi option to start using Prettier. Thanks to the team!

The option seems to put semicolons at the front of your code instead of at the end. Am I wrong? Why is this attractive?

They specifically demonstrated a case where that's necessary [1], it doesn't always do that.

[1] https://github.com/feross/standard/blob/master/RULES.md#semi...

Re: Prettier 1.0

#32
post #24

I was waiting the --no-semi option to start using Prettier. Thanks to the team!

The option seems to put semicolons at the front of your code instead of at the end. Am I wrong? Why is this attractive?

[deleted]

Re: Prettier 1.0

#34

I feel like you have to give Go credit for exposing this type of productivity hack. Once you gofmt/goimports on save you will never go back. Edit: If I had to program in JS I would definitely use this coming from Go.

gofmt helped drive the demand and popularity for prettier, but people have been trying to build something like it for JS since before Go existed [0].

Prettier has succeeded largely due to a better algorithm, which actually came from the haskell community, via Wadler's paper A Prettier Printer [1] (with an implementation available at [2]).

[0] js-beautify had its first commit in 2007: https://github.com/beautify-web/js-beautify/commit/e1ddc28b2...

[1] https://homepages.inf.ed.ac.uk/wadler/papers/prettier/pretti... [PDF]

[2] https://hackage.haskell.org/package/wl-pprint

Re: Prettier 1.0

#35
post #13

I can't overstate how freeing coding with prettier has been -- often I'd find myself quickly grokking something and once I finally got it to "work," make sure it was all styled properly. Since using prettier, these things are one-and-the-same, which is a tremendous gain.

Something that's kind of tricky for me and my team is that we disagree on things like indentation and spacing in/around brackets and parens. The disagreement isn't just a "I think it should be done this way..." but "I actually understand code better when it's written this way..." If we were to implement prettier, and chose to use 2-space indents, for a simple example, how would a 4-space developer fare when they pull…

Your comment made me wonder, could tools like prettier be the first step towards developer-customized code styles?

See it as views. Code could be stored in a minified (spaces and new lines are not necessarily saved), and then every developer in the team can view the code in any style he chooses. His code would then be committed using the underlying "minified" format, so that the next developer can pick up that code and view it in his own code style.

Does that even make sense? What could be the gotchas of such a thing?

Re: Prettier 1.0

#37
The amazing thing, for me, is:

1. Announced 2 months ago

2. Already adopted by, it seems, every major JS project. (https://twitter.com/jlongster/status/852532847252566017)

3. 7000 stars, 100,000 npm downloads/mo

Now some people will say it is a better mousetrap, but even now I can't tell you what the difference is between it and all the other linters. I can tell you that, based on the popularity, I would just default to this one and assume all this famous projects and people have worked it out.

How did it get it so popular? What made people want to try it out? Just word of mouth?

Re: Prettier 1.0

#38
I'll never understand code formatters. For me the idea of my code passing through a formatter, is like if accidentally I lost part of it: there is a lot of care in the way you write your code, even in the part that the compiler does not care about: spaces. Spaces are the rhythm of the code... not sure why one would write code without rhythm and later add a synthetic one.

Re: Prettier 1.0

#39
People here seem to approve it, but I feel unsure. Example with the matrix shows pretty well, why exceptions are always possible, no matter how detailed your styleguide is. And using comments to hold your auto-formatter back always baffles me. It seems so misaligned with the original purpose of writing the code (which comments are a part of).

It might be useful to re-format a completely messed up piece of code coming from the external world, but on the team I always prefer styleguides in the mood of "recommended, never enforced", which "prettier" is exact opposite of. That is, try to write like everyone else on the team does, but avoid re-formatting the code written by someone else, if there's no real need to do so. Obvious, strictly formal things like spaces instead of tabs, spaces outside of brackets (not inside of them), etc — this is one thing. But aligning pieces code to match some meta-pattern, or using longer/shorter lines than usual for some specific, "artistic" purpose — come on, this is not such a big deal. Consistency is overrated.

Re: Prettier 1.0

#40

The amazing thing, for me, is: 1. Announced 2 months ago 2. Already adopted by, it seems, every major JS project. ( https://twitter.com/jlongster/status/852532847252566017 ) 3. 7000 stars, 100,000 npm downloads/mo Now some people will say it is a better mousetrap, but even now I can't tell you what the difference is between it and all the other linters. I can tell you that, based on the popularity, I would just defau…

Most notable feature of prettier being able to format based on the wrap length. I don't know about others, but I definitely switched to it just for that feature.
Post reply on HN