heck we have programmers at my office that has programmed for years,
when i
was hired i saw how slow there services were....
True enough. Time spent programming is no guarantee of quality. A person
can do the same thing wrong for years without ever figuring it out.
[...]
notice the same object being created each loop
instead of being created once outside the loop
the exec the methods
go through 30000 iterations and thats 30000 new instances
of the same object instead of 1.
Of course, it begs the question: what sort of design requires that you
instantiate an object just to call a single method? I can think of
exceptions to the rule, but generally speaking that's the sort of thing
that is better handled by static methods, or in some cases a singleton
class.
That said, my understanding is that instantiating objects over and over in
.NET isn't really all that expensive, relatively speaking. In that loop
you posted, even if you move the instantiation of that one object out of
the loop, there's no reason to believe that calling the methods doesn't
also instantiate new objects as well. So you save one instantiation of
what could be several or even dozens.
Also, I gather that the framework has optimized for this case, caching the
memory blocks needed for objects that are reused frequently. Of course,
that doesn't help with the actual initialization, but objects should
generally be designed so that initialization isn't expensive, and again
those methods could be instantiating plenty of new objects each time as
well.
I agree that the code could be cleaner, but there seem to be greater
things wrong with the design there than where the object gets
instantiated, and there _is_ something to be said for not worrying too
much about performance until there's a proveably slow area of code.
Pete