Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I very often find myself in situations where I should have opened a parentheses, but forgot and end up furiously tapping the left arrow key to get to the spot I should have put it, and doing the same to get back to where I was - that, or removing one hand from the keyboard to do it with the mouse. Either way, it's a stupid mistake on my part and a poor use of time going back to fix it.

For example, if typing something like

var x = 100 - var1 + var2;

I might get to the end of the statement and realize I wanted to subtract the sum of var1 and var2 from 100 and not add var2 to the difference of 100 and var1.

I can't really expect an IDE to prevent my mistakes, but I was thinking there could be a simple enough feature that would save time when they're made. Specifically, some kind of function that, after a closing parenthesis is added where there isn't an opening one, would start ghosting in an opening parenthesis at different statements and allow the user to switch between them.

For example:

Say you have the following statement:

var x = oldY * oldX + newY / newX - left - right;

If you put a closing parenthesis after right and pressed the shortcut, the IDE would do:

var x = oldY * oldX + newY / newX - ( left - right);

press left, and then:

var x = oldY * oldX + newY / ( newX - left - right);

...then:

var x = oldY * oldX + ( newY / newX - left - right);

Anyway... Does this feature exist? If not, should it exist? What do senior programmers do when this happens?

share|improve this question
2  
You can always do CTRL+ <- key to get there and just press extra key (. –  Dipan Mehta Mar 14 '12 at 5:45
    
I don't know very clearly what you mean, or what language you are working in, because that matters too, however I've seen that feature in 2 IDEs: Codeblocks (C++) which automatically opens another parenthesis (and square ones) as well as Eclipse (Multiple language support). I don't sopose they're much trouble, they're just annoying. –  Bugster Mar 14 '12 at 6:35
    
Dipan Metha is correct. It takes the same number of key strokes to do Ctrl + <- and insert it as it does to hit your key command and press left until it's correctly placed. At best you might save one keystroke. –  Kris Harper Mar 15 '12 at 0:21

2 Answers 2

up vote 1 down vote accepted

Senior programmers use the Next/Previous word, start of line end of line hot keys to navigate the code - if you ever get a chance, watch a vi expert in action. These things 'just happen' - you don't think "left, left, left, left, Brace, right right right", you think "brace over there" and your fingers do it for you.

Senior devs also don't worry too much about the time taken to type. We are not the Typing Pool - paid for word/minute. We add a parenthesis (or any artifact that makes the code readable, let alone correct) when needed, as we know the time to write it is trivial compared the time it will be read thousands of times.

Further senior developers would not write

var x = oldY * oldX + ( newY / newX - left - right);

As it's very odd code that does not 'look' right, meaning even more time will be spent reading it and trying to second guess what the original write wanted it to do (Any developer should be able to work out what it does).

share|improve this answer

Does this feature exist?

No, IDE should not (and can not) automatically fix your code, because it has no way to know whether the formula you use has this or that arithmetic operation.

What do senior programmers do when this happens?

Serious programmers (not only senior) write proper unit tests, where such mistakes are easily detected.

share|improve this answer
    
No, I don't mean broken code, I mean while you're typing you realize you needed a parenthesis earlier in the statement. –  mowwwalker Mar 14 '12 at 21:13
    
@user828584 For example, in KDE you'll notice if a parenthesis is not closed, but as I said no IDE knows where is a proper place for parenthesis in a statement. –  BЈовић Mar 15 '12 at 5:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.