←back to thread

628 points cratermoon | 6 comments | | HN request time: 0.441s | source | bottom
Show context
chrismorgan ◴[] No.44462001[source]
> Like, just to calibrate here: you know how some code editors will automatically fill in a right bracket or quote when you type a left one? You type " and the result is "|"? Yeah, that drives me up the wall. It saves no time whatsoever, and it’s wrong often enough that I waste time having to correct for it.

I have not yet figured out why anyone would choose this behaviour in a text editor. You have to press something to exit the delimited region anyway, whether that be an arrow key or the closing delimiter, so just… why did the first person even invent the idea, which just complicates things and also makes it harder to model the editor’s behaviour mentally? Were they a hunt-and-peck typist or something?

In theory, it helps keep your source valid syntax more of the time, which may help with syntax highlighting (especially of strings) and LSP/similar tooling. But it’s only more of the time: your source will still be invalid frequently, including when it gets things wrong and you have to relocate a delimiter. In practice, I don’t think it’s useful on that ground.

replies(13): >>44462030 #>>44462032 #>>44462150 #>>44462206 #>>44462213 #>>44462300 #>>44462368 #>>44462389 #>>44462450 #>>44463659 #>>44463863 #>>44464038 #>>44466698 #
1. matsemann ◴[] No.44462389[source]
> and it’s wrong often enough

How is it ever wrong, though? If I insert a (, and then a {, and the editor appends so that it's ({}), that's always ?correct. Can it ever not be.

Maybe because on a Norwegian keyboard { is a bit awkward, but I like it. Then even if we're 5 levels deep with useEffect(() => {(({[{[ I can just press ctrl+shift+enter and it just magically finishes up everything and put my caret at the correct place, instead of me trying to write ]}]})) in the correct order.

replies(5): >>44462525 #>>44462659 #>>44462725 #>>44465211 #>>44478008 #
2. rcxdude ◴[] No.44462525[source]
It certainly can, because it doesn't necessarily know where the closing brace should be, especially when inserting as opposed to writing a completely new line. I'm often deleting random crap in the editors I use with the 'feature' as I'm adding delimiters. '"' tends to be even worse, because the distinction between opening and closing is not obvious.

e.g.:

(a + b > c) -> ((a + b > c) -> (()a + b > c) -> no, I was aiming for ((a + b) > c)

(it sound like you're talking about a different feature/implementation, though, since in the annoying case there's no 'completion' shortcut, it just appears)

3. jltsiren ◴[] No.44462659[source]
Most editors are not smart enough to do it consistently right. For example, VS Code often inserts extra quotes when I try to break "long string" into "long " + something() + " string". And when I try to write a half-open interval [a, b) in a comment or within a string, the editor inserts an extra ].
4. Kon5ole ◴[] No.44462725[source]
>How is it ever wrong, though?

Whenever you edit something existing that already has the ), ] or } further down and you end up with a ()), []] or {}}. Or when you select some text that you want to replace and start with a quote only to end up with "the text you wanted to replace" instead of the expected ".

I never notice when it works but get annoyed every time it doesn't, so I feel like it never works and always sucks.

I guess it's muscle memory and some people are used to it, but it feels fundamentally wrong to me to have the editor do different basic editing things based on which character is being pressed.

5. Attrecomet ◴[] No.44465211[source]
> can just press ctrl+shift+enter and it just magically finishes up everything and put my caret at the correct place, instead of me trying to write ]}]})) in the correct order.

I think here you are talking about a different thing -- completion of already started parentheses/"/whatever with content in-between, not the pre-application of paired braces or quotation marks, as the author did, no?

6. charles_f ◴[] No.44478008[source]
I can't count how many } I've deleted across the years because of that feature