Dealing with curly brace soup
- by Cyborgx37
I've programmed in both C# and VB.NET for years, but primarily in VB. I'm making a career shift toward C# and, overall, I like C# better.
One issue I'm having, though, is curly brace soup. In VB, each structure keyword has a matching close keyword, for example:
Namespace ...
Class ...
Function ...
For ...
Using ...
If ...
...
End If
If ...
...
End If
End Using
Next
End Function
End Class
End Namespace
The same code written in C# ends up very hard to read:
namespace ... {
class ... {
function ... {
for ... {
using ... {
if ... {
...
}
if ... {
...
}
}
}
// wait... what level is this?
}
}
}
Being so used to VB, I'm wondering if there's a technique employed by c-style programmers to improve readability and to ensure that your code ends up in the correct "block". The above example is relatively easy to read, but sometimes at the end of a piece of code I'll have 8 or more levels of curly braces, requiring me to scroll up several pages to figure out which brace ends the block I'm interested in.