Hacker News new | ask | show | jobs
by deepfriedrice 848 days ago
Off topic but every once and a while I'm made aware of the impact prettier has had on my typing. It's so hard to write code without a tool like prettier because formatting related keystrokes have largely been removed from my muscle memory. You basically end up writing a sort of shorthand.
4 comments

Yeah it’s true. Its not simply that you don’t have to manually format things a certain way. You simply don’t format things at all. You can avoid writing lots of spaces, newlines, semi colons, etc. it’s absolute garbage, then you save it, then it’s fine.
And autoformatters have cemented my preference for non-white spaced languages. As you say, just write whatever and let it format it. When I then switch to our python backend this strategy no longer works. Like, it can fix something, but it needs a much cleaner state to do so. For instance if my loops are indented wrong, black can't solve that as the decision it makes has a semantic meaning.
Something of a tangent: with Automatic Semicolon Insertion (ASI), JS is a white-space influenced language. Some of prettier's defaults are directly related to ASI, such as the way it often wraps things in extra ("unnecessary") parentheses, especially JSX but also anything complicated and multi-line especially after keywords like `return`. (`return` is the trickiest under ASI, so prettier's defaults seem that conservative in large part because of `return`.)

As someone who appreciates `{ "semi": false }` in my prettierrc, I take a lot of advantage of JS' ASI and find prettier's behavior interesting and conservative, but useful.

A team I'm doing some work with uses eslint and has not configured prettier, so instead of simply having everything get formatted correctly, I get red squiggly lines under blocks of code because of an omitted meaningless whitespace character.

There are a few linting rules that can help identify semantic errors or dead code, but only a small number of rules are needed to get all of the benefits.

Autoformatting (prettier, gofmt, etc.) is the way to go.

You can mellow the squiggles for stylistic errors in VS Code.

Take a look at the “eslint.rules.customizations” key in this file:

https://github.com/antfu/eslint-config/blob/main/.vscode/set...

Thank you! I had been wondering if that was possible. Do you know if it can be done only for a single project / directory?
You can set workspace settings in the top-level .vscode/settings.json file of your project: https://code.visualstudio.com/docs/getstarted/settings#_work...
many (most?) red squiggles are autofixable with eslint. I use eslint exactly like prettier, in that I never think about formatting and everything gets fixed/formatted on save.
Many are, but some of the "errors" are not helpful while code is in progress. Why do I need to see them while typing if they can be easily auto-fixed later? It's just more useless visual clutter to worry about.
I'm amazed people are using editors that require manually tweaking indentation. I mean, apart from making sure the code is in the right block.
In languages which don't use indentation semantically, I always end up catching a bug, sooner or later, by running code through a formatter. It's usually in a complex tree of nested if statements, some code I thought was part of one group gets moved to be in another group, making it obvious where the mistake was.

Python can't do that. It's one of a few things about the language which is "nice" when using it for simple tasks, but which makes more complex programming pointlessly error-prone.

Conversely, my strategy is "press shift+tab to close the block and not have to screw around with matching {} everywhere".
But that leaves you having to manually adjust entire blocks, when indentation levels change. With {}, prettier can readjust everything properly for you, even after mutilating changes such as copying an entire block from a different file into a new one, and at a different indentation level.
Python formatters do that too, they don't care about the indentation, as long as it's consistent. All I need to do is indent the block far enough to the right that it's not more left than the previous one, and that's it.

This also happens rarely enough that it's never been an issue for me.

I find selecting a block of code and hitting tab/shift+tab much simpler and faster than hunting down matching parenthesis, especially when adjusting longer sections or complex situations.

Of course this is mostly a tooling issue, since there is a shortcut for adjusting indentation but not for adjusting parenthesis. Or maybe there is and I just haven't discovered it yet.

Perhaps is because jetbrains make better structural editing than vscode, but I practically never have to type closing brackets.

Copying, moving, reordering, newlines, pretty much anything will keep correct pairing of brackets.

Sure, and I never have to type any opening indentation either, only closing.

Regardless, to me, this is such a minor issue that I don't consider it at all when choosing a language.

This + Copilot.

I code in an entirely different way now, I would of thought it impossible to change my ways (about 20 years of coding)

Yes I just started dabbling with copilot and I feel much the same as when I began really leveraging prettier.

I’m similarly surprised to see such an ingrained skill undergo such rapid change. And it’s funny because for me prettier was originally just meant to fix the chaos that is every dev having their own style/editor preferences.

have*
But I am quite happy with it I don’t have to waste my time typing. I don’t have to waste my time improving my raw typing speed.

I do solid touch typing 60WPM writing plain text. With code completion and linting it easily goes twice as fast writing code.

That's cool. I'm unironically interested, how do you manage to think at such speed?
I'm ~120WPM and a vim user, and yeah the main thing is how little time I actually spend typing. It helps me keep my focus on what I'm doing.

I think other tools (like the ones people are mentioning) do stuff like this for people: autocomplete, copilot, formatters, etc. I also use formatters and linters, and my autocomplete is "be strict about conventions, look up the actual meanings of words", which makes me touchy about conventions haha.

I type at 100WPM and that's usually fast enough for programming but not always. Sometimes you just know exactly what needs to be written, maybe because you've written similar things before.
I don’t do it simultaneously, when I do know what I want to code it just takes me less time writing it out so sooner I go back to thinking what’s next.
Programming is mostly thinking interspersed with a bit of typing. Nobody thinks as they type. The typing bit is just getting your abstract idea of what the program should do into the computer.
I think I probably suffer from the same thing. On top of that, I added a VS macro that adds missing imports, cleans up unused ones, and re-orders them in a single keystroke. I've never been lazier.