44 ms·
$20k bounty was claimed
- laurels-marts 3y agonoob question but how does one actually use prettier? i find that the formatting just make the code less readable. is the goal to train yourself to be able to read prettier-formatted code as well as you could read your own hand-formatted code? when i'm in the thick of it working on a piece of code, writing some logic and have everything laid out the way that makes sense to me and then i hit cmd + s and BOOM all the lines get shifted and wrapped and i'm ripped out of my flow i wondering what the heck it is i'm now staring at. sometimes i disable prettier on save and just run it on a pre-commit hook because at that point who cares that the code is unreadable to me.
- razodactyl 3y agoCongratulations to the winning team.
- fastball 3y agoAs an aside, the winning project (Biome) is a fork (renaming?) of the Rome project, which was started by Sebastian McKenzie (creator of Babel) a few years ago. Forked because sebmck seems to have gone AWOL over the last year or so and contributors were unable to update many of the project's resources as only he had access. Hope he is doing ok though and glad the Biome project seems to be going strong regardless.
- tmm84 3y agoThis is something that really got me thinking about how to make my own prettier from scratch because I thought it was interesting. Needless to say, having looked at the “tests” for prettier I was kind of lost because I was trying to reverse engineer from the tests. What I saw was the format tests are auto generated and have if statements in them. If you’re a unit test stickler then seeing an if statement in a test should be a smell. The hardest part was trying to get the why behind each test. No explanation is in the test but I’ll bet it’s in the docs, source code or whatever cloud chat community. Also, I had to check the winning implementation just for sanity’s sake. It is older than a week or two. Still, my hats off to them for being able to meet the compatibility mark and get the cash.
- arachp_braijik 3y ago[flagged]
- arachp_braijik 3y ago[flagged]
- arachp_braijik 3y ago[flagged]
- arachp_braijik 3y ago[flagged]
- namanyayg 3y agoWhile porting to Rust has been a trend, as Prettier runs on every save, the speed boosts will be significant. I'll be trying out Biome soon. Congrats to the Biome project!
- foreigner 3y agoI recommend using the lint-staged tool so Prettier only runs on every save on changed files. It makes a huge difference on large projects.
- conaclos 3y agoBiome is also working on a feature that only formats changed files. See the associated PR [0] for more details. [0] https://github.com/biomejs/biome/pull/753 https://github.com/biomejs/biome/pull/753
- _fat_santa 3y agoTangental but for anyone using lint staged + typescript, I recommend tsc-files[1]. [1]: https://github.com/gustavopch/tsc-files https://github.com/gustavopch/tsc-files
- uoaei 3y agoThis effort reflects the excitement in the Python community around `ruff`. Excited to see efficiency and speed gains with a wide impact.
- spankalee 3y agoI have never noticed any lag from Prettier running on single files. The perf starts to matter with whole-repo format passes. For interactive use we really should be using long-running, warmed up, processes too, where the start time of Node is irrelevant. Ideally type-checking, linting, highlighting and formatting would run in one language service doing incremental parsing and updates to a shared AST on every keystroke.
- strager 3y ago
- syrusakbary 3y agoI'm incredibly excited for this. The Biome team has been remarkably fast on achieving 95% compatibility with Prettier [1]. This will help to bring maximum speed to formatting Javascript thanks to Rust, following the ruff (Python formatter) trend. Just as a note, as it was not mentioned in the article, Wasmer [2] also participated with a $2,500 bounty to compile Biome to WASIX [3], and it has been awesome to see how their team has been working to achieve this as well... hopefully we'll get Biome running in Wasmer soon! Also congrats to the Algora team, as they have been doing very good work with their landing and trying to help on the challenge moving forward [4]. Keep up the great work!! [1] https://github.com/biomejs/biome/issues/720 https://github.com/biomejs/biome/issues/720 [2] https://wasmer.io/ https://wasmer.io/ [3] https://wasix.org/ https://wasix.org/ [4] https://console.algora.io/challenges/prettier https://console.algora.io/challenges/prettier
- triyambakam 3y agoDo you know the reason for enabling compilation to WASIX?
- syrusakbary 3y agoWASIX will enable to run biome fully sandboxed at close to native speeds. Imagine you can safely assume that the formatter program will only have access to the directory you provide, and not anything outside of it (not even the network!). In summary, Wasmer + WASIX is like Docker, but much more lightweight :)
- slimsag 3y agoThe parent poster (syrusakbary) is the CEO of Wasmer and trying to push WASIX, a quasi-proprietary 'open standard' while it seems the rest of the WASM ecosystem is in fact moving to WASI preview 2 [0] [0] https://news.ycombinator.com/item?id=37545670 https://news.ycombinator.com/item?id=37545670
- intelVISA 3y agoExtend, Embezzle, Escape
- ehutch79 3y agoI'm looking through the docs, specifically the formatter stuff ( https://biomejs.dev/formatter https://biomejs.dev/formatter ), and it feels like all the examples are backwards? Am I missing stuff?
- ufo 3y agoThose diffs are rare corner cases where the input is invalid Javascript. Prettier's parser is permissive and emits beautifully indented nonsense (which is arguably a bug in prettier). For example, in the original program there is a "private public" but the prettier output in red only says "private". Biome decided that in these cases it should not touch the indentation at all. The output is indented exactly the same as the input. The concern is that if you reindent something that you don't understand, it might break it. https://github.com/biomejs/biome/issues/739 https://github.com/biomejs/biome/issues/739
- conaclos 3y agoWhat do you mean by "backwards"?
- surye 3y agoThe "diff" appears to be backwards (it's subtracting what prettier would emit, and adding back the original).
- explaininjs 3y agoThe diff is between the test cases’s expected output (red) and the utility’s current output (green).
- ematipico 3y agoThe red represents what would Prettier emits, and the green represents what Biom e emits. If you think that's unclear, feel free to send a PR to help us make it clearer.
- 3y ago
- jrockway 3y agoThat's interesting. I've been using "deno fmt" as of late and it's been fine for me. https://docs.deno.com/runtime/manual/tools/formatter https://docs.deno.com/runtime/manual/tools/formatter
- conaclos 3y agoIf you switch from Prettier to deno-fmt you will notice many changes to perform on your code base. Biome tries to minimize these changes.
- tills13 3y agoFWIW it doesn't matter which formatter you choose, so long as everyone working on the project is required to use it.
- culi 3y agoIn the same way it doesn't matter which side of the road you drive on. What matters is that everyone else is also driving on that side
- jkrubin 3y ago100% I also personally believe you should pick a formatter and NOT configure it. I don’t care anymore about style. Just want formatting to be consistent.
- jrockway 3y agoYeah, that's my take as well. The less there is to configure, the better. Something I like about Go is that I don't need any project-specific settings, because there are none. (Not strictly true, as some people use gofumpt instead of gofmt. I think this is a bad idea, even though I agree with all of gofumpt's formatting changes. What matters is will everyone use it on every commit? Not if gopls doesn't do it for you.) At my last job, we had a lot of fun with Prettier. We basically made our Typescript codebase look as much like Go as possible. I am not sure this is a particularly valuable endeavor, but it was fun. So if people are willing to spend $20,000 on making that faster, whatever. They can have that fun, I guess.
- andrewstuart 3y agoThe post says the reason they did this was to motivate themselves to make the javascript version better? Strange.
- sophacles 3y agoCompetition is good for the consumer (i.e. the users). For example: when clang and LLVM came along, gcc got significantly better.
- dewey 3y ago> One question you are probably wondering is why would the Prettier team fund another project!? In practice, Prettier has been the dominant code formatter for JavaScript and as a result of a lack of competition, there has been little incentive to push on performance and fix various edge cases. I was indeed wondering that but the answer doesn't really answer the question for me. Why not set a bounty to improve Prettier instead of building a competing project just to increase the motivation to improve Prettier? Or is the end goal to shut down the Prettier project and encourage people to switch to the Rust based one? Seems like an unnecessary fragmentation of an already confusing landscape. Maybe I'm misunderstanding something though.
- evan_ 3y agoHow much would you pay to have your project on the front page of Hacker News for most of the day? More or less than $20,000?
- nijave 3y agoI think there's some merit in creating a fresh solution with little or no bias from the original. Trying to adapt an existing codebase is limited by the existing applications architecture and how much you can change without breaking everything
- gmgmgmgmgm 3y agoYes, I'm sure rust is amazing but, Just a guess that the number of programmers that can contribute to a rust project is probably 3-4 orders of magnitude less than the number of programmers that can contribute to a JavaScript project. Well, maybe if you subtract all the "competent enough to a submit a coherent pull request" programmers the number is only 2-3 orders of magnitude? Basically I'd assume, if a project targeted at JS, switched to rust, the number of useful pull requests would be 50-100x less. I wonder if anyone has any data on that (and similar projects re-written in C++ or Go etc...).
- rattray 3y agoSpeaking as a contributor to Prettier, it is _not_ an easy codebase for someone who knows JS to just jump into and contribute. Furthermore, projects like Ruff show you can have a lot of contributors for projects like this. Maybe because there are lots of devs who use TS or Python in their day job, but want excuses to use Rust on the side.
- nicoburns 3y agoSpeed is always welcome, but I just wish prettier was a little less opinionated. Specifically around line length, it will just not leave my formatting alone. I find prettier formatted code much less readable than unformatted code, and this isn't a problem I have with other code formatters like rustfmt.
- beirut_bootleg 3y agoThere's a more insidious side effect to prettier related to the line length thing which I'm not sure other commenters touched upon, and the reason I avoid opinionated formatters. Prettier will affect your diff in ways you didn't intend to. Remove a member from a destructuring assignment that brings it below the line length limit, and suddenly your diff is +1/-5 instead of 0/-1, making it slightly more difficult for your reviewer to see what the exact difference is between those 5 lines removed and 1 line added - it's not immediately clear which member was removed. You try to rewrite a previous commit to fix a typo using Git's interactive rebase, and now the next commits won't replay on top if it because Prettier decided to reformat an entire code block. Another fun thing to try with prettier: add a precommit hook that runs prettier, and then try to stage partial file changes. No thanks.
- plugin-baby 3y agoReformatting in precommit is destructive.
- meowtimemania 3y agoDo you have any examples where prettier code is much less readable? I haven't really ran into that issue and have been very happy with prettier.
- deleted 3y ago[deleted]
- harimau777 3y agoPrettier often makes code written using sequences of .chaining much more difficult to read by forcing it all to the same line. For the same reason, it often makes code written using composition more difficult to read since it won't let you decide when to put a sub-call on its own indented line for clarity.
- anshulbhide 3y agoWould be cool to use a Replit Bounty next time!
- candiddevmike 3y agoI'm still salty that all my eslint plugins decided to remove perfectly fine linters in lieu of Prettier. I find Prettier to be way too heavy handed and hard to reason about, and yet another tool that I never asked for...
- xdennis 3y ago> I find Prettier to be way too heavy handed But that's the purpose of such tools: to stop endless debates about style.
- fenomas 3y agoSure, but the issue with prettier is that it goes beyond style and also mangles semantic details. That's their explicit design choice - they feel that conforming formatting in all cases is more important than preserving semantic information about code, and that devs should add "// prettier-ignore" comments to every line of code with semantic details that prettier would throw away.
- pcthrowaway 3y agoI mean.. sure https://xkcd.com/927/ https://xkcd.com/927/
- constantly 3y agoIt's not a new standard so this comic really doesn't apply here. It's just being opinionated, for once, about what to use. I welcome it strongly, as I do tools like Black for Python, which do similar things. Just set that up in CI for anything and all my code looks the same, removing some overhead of readability.
- mm263 3y agoIt isn't really applicable here since Prettier was de-facto standard at pretty much every place I've worked at - start-ups to FAANG
- deleted 3y ago[deleted]
- smnscu 3y agoI feel like people complaining about Prettier being "heavily opinionated" are missing the point. Perhaps I'm biased by my decade of using Go, but not having to worry about superfluous stylistic choices is a welcome reduction in cognitive load. (Up to a point I guess, e.g. I'd never put up with K&R-style newline opening brackets).
- pigeonhole123 3y agoPrettier is very opinionated about line length which gofmt isn't. That's the only complaint I have and it's bad enough I just refuse to use it. Add one character to a line and enjoy a ten-line diff. Edit: See a contrived example of something gofmt doesn't touch (the behavior I want): https://go.dev/play/p/cKMKnFwT8tq https://go.dev/play/p/cKMKnFwT8tq
- 1letterunixname 3y agoLine length with modern toolchains is too often stylistic bikeshedding with awkward limits stuck in 1975 cargo culted from the VT52. My external monitor can legibly display 637 x 81 while my laptop does 217 x 63. The largest barely legible terminals with tiny fonts are 3x the size. Around 100 is a sane minimum while 160 is a sensible upper limit. There's no specific limit other than to prevent poor coding technique, illegible code, or inclusions of generated or minified atrocities.
- deleted 3y ago[deleted]
- preommr 3y agoThen just change it in the prettier config. 80 characters is a really good default. I have an extra wide monitor, and with 2 side panels open in my IDE, that's the perfect length.
- pigeonhole123 3y agoIt will then force longer lines, which is even worse.
- nulld3v 3y agoAre there benchmarks for Biome anywhere? How much better does it perform than prettier exactly?
- nulld3v 3y agoFound some here: https://github.com/biomejs/biome/blob/main/benchmark/README.md https://github.com/biomejs/biome/blob/main/benchmark/README.... They claim 25x but the numbers are old so I'm not sure if I believe them now that a bunch of new functionality has been added. Either way, if it's anywhere within that ballpark it's still a huge achievement.
- conaclos 3y agoThis heavily depends on your workstation. Biome scales very well. With 16 threads on a i7-120P, I got the following figures: Webpack repository: Biome ran 2.19 ± 0.11 times faster than dprint 4.18 ± 0.14 times faster than Biome (1 thread) 32.12 ± 1.18 times faster than Prettier 32.45 ± 2.56 times faster than Parallel-Prettier I am not sure why Parallel-Prettier is slower than Prettier for the webpack repository. Prettier repository: Biome ran 1.89 ± 0.21 times faster than dprint 3.47 ± 0.34 times faster than Biome (1 thread) 36.70 ± 3.41 times faster than Parallel-Prettier 46.66 ± 4.32 times faster than Prettier
- gostsamo 3y agoMany people comment the reasons without acknowledging that part as well: > By matching all the tests, the Biome project also found a lot of bugs and questionable decisions in Prettier that we will be able to improve upon. For me, this means that they have another implementation for sanity checking their own.
- jdorfman 3y agoThank you for posting this. Sourcegraph is now a sponsor on Open Collective.
- thenbe 3y agoWhile it's always great to see performance gains, my largest pain point with prettier was never performance. Instead my only gripe with prettier is the "line wrapping noise" it creates, illustrated here by Anthony Fu: https://antfu.me/posts/why-not-prettier#the-line-wrapping-noise https://antfu.me/posts/why-not-prettier#the-line-wrapping-no... Would it be realistic to expect a solution for this issue now that "prettier needs to step up it's game"?
- dsherret 3y agoYou can already mostly do this with dprint's TypeScript plugin if you tweak the config (and I'm open to adding more config to support this scenario in case something is missing). For example, the TypeScript team uses a line limit of 1000: https://github.com/microsoft/TypeScript/blob/1797837351782e7f7ea9b23a1fceb027094b38db/.dprint.jsonc#L3 https://github.com/microsoft/TypeScript/blob/1797837351782e7...
- deleted 3y ago[deleted]
- jakub_g 3y agoThis is indeed the biggest annoyance of mine. I quite often end up rewriting code or changing variable names to counterbalance prettier making code ugly/unreadable.
- deleted 3y ago[deleted]
- tills13 3y agoeh -- this is a one-time occurrence with prettier. Subsequent changes are guaranteed to be changes-only since formatting is consistent between authors.
- c-hendricks 3y agoIt happens often in JSX, you add one prop, which makes the line longer than the line width, which turns it into a multi line change. It's annoying, but not a reason to throw the baby out with the bathwater.
- deleted 3y ago[deleted]
- meindnoch 3y ago"This means that we can now focus on the next important aspect: Performance. Prettier has never been fast per se, but fast enough for most use cases. This has always felt unsatisfying so we wanted to do something about it. What better way than a friendly competition. On November 9th, we put up a $10k bounty for any project written in Rust that would pass 95% of Prettier test suite." I don't see how better performance follows from the fact that something is written in Rust. One could have simply transpiled the existing codebase into Rust, and collect the reward.
- bufferoverflow 3y agoWhen it comes to string manipulation, Rust is much faster than JS https://benchmarksgame-team.pages.debian.net/benchmarksgame/performance/fasta.html https://benchmarksgame-team.pages.debian.net/benchmarksgame/... https://benchmarksgame-team.pages.debian.net/benchmarksgame/performance/knucleotide.html https://benchmarksgame-team.pages.debian.net/benchmarksgame/...
- tills13 3y ago> One could have simply transpiled the existing codebase into Rust, and collect the reward Why didn't you, then?
- meindnoch 3y agoBecause this is the first time I've heard about this contest. But I'll do it for you, if you put up the 20k USD. Will you?
- strager 3y agoHere is the answer I got from vjeux: > There's a lot of fast web tooling being written in rust those days. https://twitter.com/Vjeux/status/1722769322299609565 https://twitter.com/Vjeux/status/1722769322299609565 I don't buy it. I think vjeux is riding the hype.
- KTibow 3y agoTo be fair compiled languages are just faster than interpreted (in most cases, and as others have pointed out especially with strings)
- refulgentis 3y ago"[to] get Biome running in Wasmer", it seems
- thowaway91234 3y agoSo this isn't replacing the main implementation? They just funded a new project written in Rust that is compatible?
- codeptualize 3y agoAwesome! Lets gooo! Can't say prettier performance ever bothered me, but if it can run faster and leaner I'm all for it! Increase my battery life :D In general it's really exciting to see the advancements in JS tooling, the quick successions of tooling in JS might be controversial, but I love it. Each step was a significant improvement over what was there before, and the current Rust rewrite wave has already given us great tools that I use daily. I also like that there is some money being thrown at the problems!
- 11235813213455 3y agoI dislike prettier and wonder why it's so popular because - I sometimes prefer lines to exceed maxLength (ex: template string, which prettier would horribly break on vars) - allow `1 + 2 * 3` or `a || b && c` to be parenthesis-less because everyone know the precendence here
- digging 3y ago> I sometimes prefer lines to exceed maxLength (ex: template string, which prettier would horribly break on vars) Prettier doesn't break a long template literal though...? > allow `1 + 2 * 3` or `a || b && c` to be parenthesis-less because everyone know the precendence here "Everyone knows" is usually an unwise assumption. And adding parentheses does make it easier to read even for people who know their order of operations.
- sarahdellysse 3y agoNot OP, but prettier doesn't break template literals, but it will break non-literal sections of template strings. For example, if we wrote this: const foo = `aaaaaaaaaaaaaaa${bbbbbbbbbbbbb}ccccccccccccccc${ddddddddddd}`; prettier would fix it to const foo = `aaaaaaaaaaaaaaa${ bbbbbbbbbbbbb }ccccccccccccccc${ ddddddddddd }`; (or something similar) and it would be fully equivalent. I don't like it doing that either tbh but hey prettier is good enough in most cases its worth putting up with it
- bakkoting 3y agoI have a PR fixing that specific issue: https://github.com/prettier/prettier/pull/15209 https://github.com/prettier/prettier/pull/15209 Just needs another maintainer's stamp.
- shrimpx 3y ago> You may not be aware but thanks to all those donations, we've been able to pay two people $1.5k/month for the past two years to keep shipping. Fisker Cheung and Sosuke Suzuki have done an incredible job! It's incredible how little money some people get paid to build foundational pieces in a multi-trillion dollar industry.
- uxp8u61q 3y agoI don't want to disparage prettier, but to call it a foundational piece...
- fallat 3y agoI agree. Foundational isn't the right word here. I would though accept "impactful". A lot of people care about code formatting "taken care of".
- wentin 3y agoMaybe essential is a better word.
- austin-cheney 3y agoThat is still far too much an exaggeration. This is an opinionated beautifier. Its a vanity item with some downstream utility benefits.
- cdmckay 3y agoA formatter is pretty essential when working in a team. It saves tons of time wasted on code formatting in code reviews.
- 0x0000000 3y ago> A formatter is pretty essential when working in a team. I worked on a team without a formatter for more than 5 years. I'm certain many people have done the same. "Essential" is overselling.
- assimpleaspossi 3y agoTheir next bounty should be for fixing their insistence on putting a closing slash on HTML tags that have never, ever required them in any HTML specification.
- neontomo 3y agoI couldn't find the answer - does Biome work with a prettierrc.json file so that it can be implemented in an organisation that uses Prettier? In this case it would only be for speed reasons, not the formatting.
- bntyhntr 3y agoI would love to hear about any of this. I couldn't find a clear migration path with some quick googling, but I managed to eventually track down the rules I need to get mostly compatible with my org's prettier formatting. Notably, stuff I needed was in the `javascript.formatter` section of config. But even after matching everything, Biome was wrapping lines differently. Not sure but I don't actually run the front-end show so I stopped poking at that point.
- bovermyer 3y agoSo, how does Biome compare to Dprint?
- rattray 3y agoClaims to be faster (when using multiple cores) but beyond that, I'm also curious.
- afjeafaj848 3y agoMaybe I missed it but I don't get how this improves the JS implementation Are they planning to run Rust in the browser? Or make some sort of node module that calls down into rust?
- adam_arthur 3y agoRust can run in the browser via compiling down to, and running as, WebAssembly. So I don't see why not. Prettier is run mostly on the serverside though, not the browser. I assume supporting both is still desirable though
- WorldMaker 3y agoThere are node modules already that call into WASM-wrapped rust. (One of the most common source map generation packages does exactly that and it is very heavily installed by a lot of frameworks and packagers today.) I don't think prettier is intending to do that in this case, they seem to want to continue to compete as a pure JS implementation but having a "worst case, we WASM wrap biome as the future of prettier" possibility opens up future opportunities and pushes "internal" competition.
- wg0 3y ago> Consider donating if you or your company are using Prettier and it has been helpful to you. Wondering what company would NOT be using prettier. Not many. Some arguing that Prettier isn't foundational piece of software, I'd consider automated consistent readability enhancements as foundational though.
- francislavoie 3y agoIMO it should be called uglier. The default line wrapping logic (which cannot be disabled at all, by design) is awful. It unwraps short lines that I want wrapped, and it wraps long lines that I want unwrapped. It's banned from all my projects.
- hendry 3y agoAnyone know the minimal package.json or Github template to get this going in a new repository please?
- globular-toast 3y agoWhy did it have to be Rust? Couldn't have just been "faster"? Is the Rust one actually fast? Does memory safety and leaks etc even matter for a program like Prettier?
- WorldMaker 3y agoThere's a lot of vocal people especially here on HN that think that Rust is the fastest, safest language currently around, so this was maybe in part a "put your money where your mouth is" challenge.
- kamikaz1k 3y agoDoes any body have a collection of all the profiling Fabio Spampinato did?
- fabiospampinato 3y agoI haven't really kept track of everything. It may be worth making a blog post with the main findings though.
- vinniepukh 3y agoI want to use Biome, but until it either has plugins or implements the tailwindcss class sorting itself, I will not be able to adopt it. This is a common sentiment in the fullstack community right now.
- deleted 3y ago[deleted]
- mvdtnz 3y agoSo now there are two distinct, somewhat compatible but surely diverging implementations of the same thing. Yup, sounds like the JS ecosystem.
- 65892 3y ago[flagged]