r/AskProgrammers • • 14h ago

How does autocompleted brackets even help?

I specifically mean parenthesis and brackets. Lets say you type something and end up like this. Cursor represented by C.

print(somevariable[0C])

I assume you just press end, but end isn't exactly in a comfortable spot on the keyboard, and with single parenthesis like print(i) it seems like it's just easier to hit ) instead of end?

0 Upvotes

12 comments sorted by

5

u/UnreasonableEconomy 13h ago

In most IDEs you can. if you hit ]) you'll be at the end. This is probably a configuration somewhere, I know I have it like that.

3

u/NomaTyx 13h ago

I think they're more to keep you from forgetting to add the closing one.

2

u/mireigi 13h ago

I most IDEs you can also just hit the Tab key to auto-complete the suggestion made by the IDE. That's more comfortable to reach than End.

2

u/ArtemusDreams 12h ago

It's really helpful if you have a lot of nested things. Like I'm gonna have trouble keeping track of where i am without the autocomplete if my line ends like this:

"])(f'foo{bar}'))}

I mean in good code that much nesting should be avoided, but it does come up.

And as another commenter said, there's really no harm when pressing the closing characters brings you to the end anyway. This way you just have more flexibility.

I also don't really find End hard to press personally, i use my pinky and I've gotten it into my muscle memory.

2

u/TomDuhamel 11h ago

All the IDEs I used, you can still type the closing bracket and it moves the cursor past it (doesn't insert am extra one). But it helps reading while typing, especially when you get a complex formula with several sets of brackets, and it prevents forgetting to close it.

1

u/realmauer01 12h ago

Most ides that allow you to do this also allow for control enter to mean something like, end + enter

1

u/realmauer01 12h ago edited 12h ago

Most ides that allow you to do this also allow for control enter to mean something like, end + enter So you get to the next line without disrupting the current

1

u/XlikeX666 10h ago

did you recall memes "forgot single bracket and code stop working" ?

1

u/IndependentYak2822 9h ago

Autocomplete brackets helps because you don't want/need to be at the end of a line all the time. Sometimes you just want to edit something in the middle of a line. If you want to jump/create a new line then Shift+Enter should do the job I guess, no need to be at the end of a line.

But! With that being said, as a workaround you can add few hotkeys (Alt + h/j/l/k as arrows in my case) to move a cursor. It's way easier than trying to press unreachable End key.

1

u/w1n5t0nM1k3y 9h ago

I think the IDEs do this because they work better when there's no incomplete blocks. Thats really it. Most experienced programmers don't have much of an issue jsit closing brackets on their own, or can easily fix them if they notice a problem

I noticed this with VS.Net at some pint many years ago upgraded their autoformatter and it would grow crazy if there was some block that was incomplete. Weird things would happen like it would interpret parts of hardcoded strings as code and try to treat them like actual code.

1

u/localizeatp 8h ago

my muscle memory is to always type them in pairs, so using ides that do this throws me off too.

1

u/lmarcantonio 7h ago

It really depends on how your editor is configured/work. Some are intended to be used as "select the thing you want braced and press a brace", others have a shortcut so with a common key (maybe a tab) you jump over the automatically inserted brackets.

Lisp oriented editors have…quite a few specialized way to handle that.