5 ms·
Personally, I rely a lot on autoformatters ran on save. It frees my mind completely from thinking about formatting, I can write ugly one-liners that get immedia
by williamdclt 8y ago
Personally, I rely a lot on autoformatters ran on save. It frees my mind completely from thinking about formatting, I can write ugly one-liners that get immediately beautified and I have an almost-immediate feedback for syntax errors (it doesn't autoformat => I made a syntax error somewhere)
- vjeux 8y agoThis was something I wasn't really expecting when I started working on prettier. It was a strong selling point when people adopted it within Facebook. I still can't believe that it only took a year between the first commit of prettier and 100% of Facebook massive codebase to be completely formatted using prettier. Prettier is also growing extremely quickly in open source. It's now at 3.7 million downloads a week, compared to 6 million for React.
- badfrog 8y agoI didn't get to say this before I quit working at FB, but thank you for building prettier! It really made writing and reviewing JS much less painful.
- zwily 8y agoEven if there were no other advantages to Prettier, I would use it for this. It seems barbaric to write in languages now that don’t have something similar happening on save.
- dorfsmay 8y agoSame here. This is so powerful. I absolutely love python, but this is one thing it doesn't allow. On the other when working in say Rust, I can express my thought in a line or 2 straight from brain to keyboard without having to care about any formatting, hit autoformatter and also typically get an immediate feedback about basic syntax. When writing in a language that can be auto formatted, it is a huge cognitive overload removed from my shoulders, like having a copilot.
- arusahni 8y agoHave you tried any Python autoformatters? `autopep8`, `yapf`, and `Black` come to mind.
- dorfsmay 8y agoYes. They can format correct python to pep8, but can't guess which if an else correspond to if I write it all on one or two lines.
- ambivalence 8y agoThis experience must have been with a formatter different than Black. That one has no problems with any valid syntax.
- tom_ 8y agoI think the point is that the valid python syntax is potentially a limitation on any autoformatting tool. Like, suppose you were writing in C. You might well write this: if(x);else if(y){if(z);else;} and clang-format would turn it into this: if(x) { } else if(y) { if(z) { } else { } } But the equivalent in Python has to be correctly indented to be interpreted properly, because you need to distinguish these two cases: if x: pass if x: pass elif y: elif y: if x: pass if x: pass else: pass else: pass (This is the classic shift/reduce problem: https://www.gnu.org/software/bison/manual/html_node/Shift_002fReduce.html https://www.gnu.org/software/bison/manual/html_node/Shift_00...) This is sort-of not unreasonable, because of course code has to be syntactically correct for the autoformatter to do its thing, and if you're working in Python, these are the syntax rules. So, what can you do? But suppose you'd come to find it valuable to be able to stuff all your code on one line and have the autoformatter sort it out: you might then find the Python syntax a backwards step by comparison, rather than an improvement. I think this is the claim that's being made, and no more.
- 8y ago
- kilovoltaire 8y agoAgreed, I now feel like I'm editing the AST instead of editing text, it's quite magical.
- yellowapple 8y agoThat latter point is how I do a lot of my syntax-related bug finding with Emacs: press C-x h Tab, look for where the indentation starts to look unexpectedly wonky, fix the issue that caused it, repeat.