views:

83

answers:

3

Can the colors of the letters, i, j, k, be changed when used as an index? For example, i could be reddish, j could be blueish and k greenish. It would be nice to use for other sets as well, such as l, m, n.

I think having more distinction between i, j would help with some indexing errors from typos.

Edit

I should note that the indexing is not just for a triple loop. That's easy enough and as others pointed can be removed with linq. The application is in a scientific code where mixed derivatives are being calculated across a 3d mesh with finite differences. There the indexes mix up a lot and its not something that can easily be abstracted. Anything that can hits the performance of the code hard.

+2  A: 

I'm sure it could. Products like ReSharper and CodeRush change the color coding of various source code elements all the time. CodeRush Express is free and might give you a helping hand towards accomplishing your goal in a relatively painless manner. Download it from http://msdn.microsoft.com/en-us/vcsharp/ee663901.aspx.

Having said that... if you're running into confusion about the names might it not be more appropriate to either a) use more meaningful names or b) refactor so you aren't nested as deep in a single method? Obviously it would depend on what you're trying to accomplish with your nested loops - if it's something obvious then color coding may be an appropriate choice.

Richard J Foster
Thank you, though its not so much an issue with the loops (question updated).
ccook
+3  A: 

I realise it doesn't directly answer your question, but another (perhaps better) way to prevent such errors is to use well-named variables for loop indexes instead of the traditional i, j and k.

While most people agree well-named variables are important, there are a lot who still stick with these index variables - I'd same the same rules apply to them and they should have good names.

The tricky part, of course, is coming up with the names..

Grant Crofton
It's not a problem with loop indexes, thank you though :)
ccook
All the more reason to find a good name then! As per your edit, I'm not sure if scientific code makes that harder as it's not something I've worked with, but I think the advice still stands.
Grant Crofton
I hear your point... but by far the most pertinent name is i,j,k. It's what's used in the mathematical derivation.
ccook
You could always try phonetic names, if the colouring doesn't work out (india, juliet, kilo, etc)
Grant Crofton
I would agree for other situations, just not here. It's too sacrilegious to the mathematical notation.
ccook
+2  A: 

A tangential answer: Perhaps you need to try an alternative programming font, one which distinguishes more clearly the difference between i,j, and k?

(Oh, the irony of editing this in a monospace font and then seeing the answer posted in glorious proportional sans-serif.)

Colin Nicholls
Good point on the font
ccook
Accepted as this helps distinguish i,j,k
ccook