Hacker News new | past | comments | ask | show | jobs | submit login

That actually looks terrible to me, but I don't program in C#. Mostly it's because there are three blocks, but it only looks like there's one.



It gets rid of excessive nesting when you need multiple resources allocated after another (e.g. SqlConnection, SqlCommand, etc.). You can do

        using (handle a = new handle(0), b = new handle(1), c = handle(3)) {
            // use a, b, c
        }
instead, too, but that obviously only works with equal types.

I'm usually not a friend of too deep nesting (worst thing I've seen in our codebase was 65 spaces deep) and in C# you already have one level for the class, one for the namespace (possibly) and another for the method. No need to add two more if you can help it.


Right, I understand that it removes excessive nesting, but the first example just looked ... wrong to me. Your example with above looks somewhat better.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: